|
| 1 | +module SpringCollab2020MoveBlockCustomSpeed |
| 2 | + |
| 3 | +using ..Ahorn, Maple |
| 4 | + |
| 5 | +@mapdef Entity "SpringCollab2020/MoveBlockCustomSpeed" MoveBlockCustomSpeed(x::Integer, y::Integer, width::Integer=Maple.defaultBlockWidth, height::Integer=Maple.defaultBlockHeight, |
| 6 | + direction::String="Up", canSteer::Bool=false, moveSpeed::Number=60) |
| 7 | + |
| 8 | +const placements = Ahorn.PlacementDict() |
| 9 | + |
| 10 | +buttonColor = (71, 64, 112, 255) ./ 255 |
| 11 | + |
| 12 | +directions = Maple.move_block_directions |
| 13 | +for direction in directions, steerable in false:true |
| 14 | + key = "Move Block ($(uppercasefirst(direction)), Custom Speed$(steerable ? ", Steerable" : "")) (Spring Collab 2020)" |
| 15 | + placements[key] = Ahorn.EntityPlacement( |
| 16 | + MoveBlockCustomSpeed, |
| 17 | + "rectangle", |
| 18 | + Dict{String, Any}( |
| 19 | + "canSteer" => steerable, |
| 20 | + "direction" => direction |
| 21 | + ) |
| 22 | + ) |
| 23 | +end |
| 24 | + |
| 25 | +Ahorn.editingOptions(entity::MoveBlockCustomSpeed) = Dict{String, Any}( |
| 26 | + "direction" => Maple.move_block_directions |
| 27 | +) |
| 28 | +Ahorn.minimumSize(entity::MoveBlockCustomSpeed) = 16, 16 |
| 29 | +Ahorn.resizable(entity::MoveBlockCustomSpeed) = true, true |
| 30 | + |
| 31 | +Ahorn.selection(entity::MoveBlockCustomSpeed) = Ahorn.getEntityRectangle(entity) |
| 32 | + |
| 33 | +midColor = (4, 3, 23) ./ 255 |
| 34 | +highlightColor = (59, 50, 101) ./ 255 |
| 35 | + |
| 36 | +arrows = Dict{String, String}( |
| 37 | + "up" => "objects/moveBlock/arrow02", |
| 38 | + "left" => "objects/moveBlock/arrow04", |
| 39 | + "right" => "objects/moveBlock/arrow00", |
| 40 | + "down" => "objects/moveBlock/arrow06", |
| 41 | +) |
| 42 | + |
| 43 | +button = "objects/moveBlock/button" |
| 44 | + |
| 45 | +function Ahorn.render(ctx::Ahorn.Cairo.CairoContext, entity::MoveBlockCustomSpeed, room::Maple.Room) |
| 46 | + x = Int(get(entity.data, "x", 0)) |
| 47 | + y = Int(get(entity.data, "y", 0)) |
| 48 | + |
| 49 | + |
| 50 | + width = Int(get(entity.data, "width", 32)) |
| 51 | + height = Int(get(entity.data, "height", 32)) |
| 52 | + |
| 53 | + tilesWidth = div(width, 8) |
| 54 | + tilesHeight = div(height, 8) |
| 55 | + |
| 56 | + canSteer = get(entity.data, "canSteer", false) |
| 57 | + direction = lowercase(get(entity.data, "direction", "up")) |
| 58 | + arrowSprite = Ahorn.getSprite(arrows[lowercase(direction)], "Gameplay") |
| 59 | + |
| 60 | + frame = "objects/moveBlock/base" |
| 61 | + if canSteer |
| 62 | + if direction == "up" || direction == "down" |
| 63 | + frame = "objects/moveBlock/base_v" |
| 64 | + |
| 65 | + else |
| 66 | + frame = "objects/moveBlock/base_h" |
| 67 | + end |
| 68 | + end |
| 69 | + |
| 70 | + Ahorn.drawRectangle(ctx, 2, 2, width - 4, height - 4, highlightColor, highlightColor) |
| 71 | + Ahorn.drawRectangle(ctx, 8, 8, width - 16, height - 16, midColor) |
| 72 | + |
| 73 | + for i in 2:tilesWidth - 1 |
| 74 | + Ahorn.drawImage(ctx, frame, (i - 1) * 8, 0, 8, 0, 8, 8) |
| 75 | + Ahorn.drawImage(ctx, frame, (i - 1) * 8, height - 8, 8, 16, 8, 8) |
| 76 | + |
| 77 | + if canSteer && (direction != "up" && direction != "down") |
| 78 | + Ahorn.drawImage(ctx, button, (i - 1) * 8, -2, 6, 0, 8, 6, tint=buttonColor) |
| 79 | + end |
| 80 | + end |
| 81 | + |
| 82 | + for i in 2:tilesHeight - 1 |
| 83 | + Ahorn.drawImage(ctx, frame, 0, (i - 1) * 8, 0, 8, 8, 8) |
| 84 | + Ahorn.drawImage(ctx, frame, width - 8, (i - 1) * 8, 16, 8, 8, 8) |
| 85 | + |
| 86 | + if canSteer && (direction == "up" || direction == "down") |
| 87 | + Ahorn.Cairo.save(ctx) |
| 88 | + |
| 89 | + Ahorn.rotate(ctx, -pi / 2) |
| 90 | + Ahorn.drawImage(ctx, button, i * 8 - height - 8, -2, 6, 0, 8, 6, tint=buttonColor) |
| 91 | + Ahorn.scale(ctx, 1, -1) |
| 92 | + Ahorn.drawImage(ctx, button, i * 8 - height - 8, -2 - width, 6, 0, 8, 6, tint=buttonColor) |
| 93 | + |
| 94 | + Ahorn.Cairo.restore(ctx) |
| 95 | + end |
| 96 | + end |
| 97 | + |
| 98 | + Ahorn.drawImage(ctx, frame, 0, 0, 0, 0, 8, 8) |
| 99 | + Ahorn.drawImage(ctx, frame, width - 8, 0, 16, 0, 8, 8) |
| 100 | + Ahorn.drawImage(ctx, frame, 0, height - 8, 0, 16, 8, 8) |
| 101 | + Ahorn.drawImage(ctx, frame, width - 8, height - 8, 16, 16, 8, 8) |
| 102 | + |
| 103 | + if canSteer && (direction != "up" && direction != "down") |
| 104 | + Ahorn.Cairo.save(ctx) |
| 105 | + |
| 106 | + Ahorn.drawImage(ctx, button, 2, -2, 0, 0, 6, 6, tint=buttonColor) |
| 107 | + Ahorn.scale(ctx, -1, 1) |
| 108 | + Ahorn.drawImage(ctx, button, 2 - width, -2, 0, 0, 6, 6, tint=buttonColor) |
| 109 | + |
| 110 | + Ahorn.Cairo.restore(ctx) |
| 111 | + end |
| 112 | + |
| 113 | + if canSteer && (direction == "up" || direction == "down") |
| 114 | + Ahorn.Cairo.save(ctx) |
| 115 | + |
| 116 | + Ahorn.rotate(ctx, -pi / 2) |
| 117 | + Ahorn.drawImage(ctx, button, -height + 2, -2, 0, 0, 8, 6, tint=buttonColor) |
| 118 | + Ahorn.drawImage(ctx, button, -10, -2, 14, 0, 8, 6, tint=buttonColor) |
| 119 | + Ahorn.scale(ctx, 1, -1) |
| 120 | + Ahorn.drawImage(ctx, button, -height + 2, -2 -width, 0, 0, 8, 6, tint=buttonColor) |
| 121 | + Ahorn.drawImage(ctx, button, -10, -2 -width, 14, 0, 8, 6, tint=buttonColor) |
| 122 | + |
| 123 | + Ahorn.Cairo.restore(ctx) |
| 124 | + end |
| 125 | + |
| 126 | + Ahorn.drawRectangle(ctx, div(width - arrowSprite.width, 2) + 1, div(height - arrowSprite.height, 2) + 1, 8, 8, highlightColor, highlightColor) |
| 127 | + Ahorn.drawImage(ctx, arrowSprite, div(width - arrowSprite.width, 2), div(height - arrowSprite.height, 2)) |
| 128 | +end |
| 129 | + |
| 130 | +end |
0 commit comments