|
| 1 | +module SpringCollab2020AttachedIceWall |
| 2 | + |
| 3 | +using ..Ahorn, Maple |
| 4 | + |
| 5 | +@mapdef Entity "SpringCollab2020/AttachedIceWall" AttachedIceWall(x::Integer, y::Integer, height::Integer=8, left::Bool=false) |
| 6 | + |
| 7 | +const placements = Ahorn.PlacementDict( |
| 8 | + "Attached Ice Wall (Right) (Spring Collab 2020)" => Ahorn.EntityPlacement( |
| 9 | + AttachedIceWall, |
| 10 | + "rectangle", |
| 11 | + Dict{String, Any}( |
| 12 | + "left" => true |
| 13 | + ) |
| 14 | + ), |
| 15 | + "Attached Ice Wall (Left) (Spring Collab 2020)" => Ahorn.EntityPlacement( |
| 16 | + AttachedIceWall, |
| 17 | + "rectangle", |
| 18 | + Dict{String, Any}( |
| 19 | + "left" => false |
| 20 | + ) |
| 21 | + ) |
| 22 | +) |
| 23 | + |
| 24 | +Ahorn.minimumSize(entity::AttachedIceWall) = 0, 8 |
| 25 | +Ahorn.resizable(entity::AttachedIceWall) = false, true |
| 26 | + |
| 27 | +function Ahorn.selection(entity::AttachedIceWall) |
| 28 | + x, y = Ahorn.position(entity) |
| 29 | + height = Int(get(entity.data, "height", 8)) |
| 30 | + |
| 31 | + return Ahorn.Rectangle(x, y, 8, height) |
| 32 | +end |
| 33 | + |
| 34 | +function Ahorn.render(ctx::Ahorn.Cairo.CairoContext, entity::AttachedIceWall, room::Maple.Room) |
| 35 | + left = get(entity.data, "left", false) |
| 36 | + |
| 37 | + # Values need to be system specific integer |
| 38 | + x = Int(get(entity.data, "x", 0)) |
| 39 | + y = Int(get(entity.data, "y", 0)) |
| 40 | + |
| 41 | + height = Int(get(entity.data, "height", 8)) |
| 42 | + tileHeight = div(height, 8) |
| 43 | + |
| 44 | + if left |
| 45 | + for i in 2:tileHeight - 1 |
| 46 | + Ahorn.drawImage(ctx, "objects/wallBooster/iceMid00", 0, (i - 1) * 8) |
| 47 | + end |
| 48 | + |
| 49 | + Ahorn.drawImage(ctx, "objects/wallBooster/iceTop00", 0, 0) |
| 50 | + Ahorn.drawImage(ctx, "objects/wallBooster/iceBottom00", 0, (tileHeight - 1) * 8) |
| 51 | + |
| 52 | + else |
| 53 | + Ahorn.Cairo.save(ctx) |
| 54 | + Ahorn.scale(ctx, -1, 1) |
| 55 | + |
| 56 | + for i in 2:tileHeight - 1 |
| 57 | + Ahorn.drawImage(ctx, "objects/wallBooster/iceMid00", -8, (i - 1) * 8) |
| 58 | + end |
| 59 | + |
| 60 | + Ahorn.drawImage(ctx, "objects/wallBooster/iceTop00", -8, 0) |
| 61 | + Ahorn.drawImage(ctx, "objects/wallBooster/iceBottom00", -8, (tileHeight - 1) * 8) |
| 62 | + |
| 63 | + Ahorn.restore(ctx) |
| 64 | + end |
| 65 | +end |
| 66 | + |
| 67 | +# Offset X position so it flips in place |
| 68 | +function Ahorn.flipped(entity::AttachedIceWall, horizontal::Bool) |
| 69 | + if horizontal |
| 70 | + entity.left = !entity.left |
| 71 | + entity.x += entity.left ? 8 : -8 |
| 72 | + |
| 73 | + return entity |
| 74 | + end |
| 75 | +end |
| 76 | + |
| 77 | +end |
0 commit comments