Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Canyon
- using ..Ahorn, Maple
- @mapdef Entity "canyon/spinorb" SpinOrb(x::Integer, y::Integer)
- @mapdef Entity "canyon/pushblock" PushBlock(x::Integer, y::Integer)
- @mapdef Entity "canyon/toggleblock" ToggleBlock(x1::Integer, y1::Integer, x2::Integer=x1+16, y2::Integer=y1, width::Integer=16, height::Integer=16)
- const placements = Ahorn.PlacementDict(
- "Spin Orb (Canyon)" => Ahorn.EntityPlacement(
- SpinOrb,
- "point"
- ),
- "Push Block (Canyon)" => Ahorn.EntityPlacement(
- PushBlock,
- "point",
- Dict{String, Any}(
- "stickyTop" => false,
- "stickyBottom" => false,
- "stickyLeft" => false,
- "stickyRight" => false
- )
- ),
- "Toggle Block (Canyon)" => Ahorn.EntityPlacement(
- ToggleBlock,
- "rectangle",
- Dict{String, Any}()
- )
- )
- Ahorn.nodeLimits(entity::ToggleBlock) = 1, -1
- Ahorn.minimumSize(entity::ToggleBlock) = 16, 16
- Ahorn.resizable(entity::ToggleBlock) = true, true
- function Ahorn.selection(entity::ToggleBlock)
- nodes = get(entity.data, "nodes", ())
- x, y = Ahorn.position(entity)
- width = Int(get(entity.data, "width", 32))
- height = Int(get(entity.data, "height", 32))
- res = Ahorn.Rectangle[Ahorn.Rectangle(x, y, width, height)]
- for node in nodes
- nx, ny = Int.(node)
- push!(res, Ahorn.Rectangle(nx, ny, width, height))
- end
- return res
- end
- frame = "objects/swapblock/blockRed"
- midResource = "objects/swapblock/midBlockRed00"
- function renderSingleToggleBlock(ctx::Ahorn.Cairo.CairoContext, x::Number, y::Number, width::Number, height::Number)
- midSprite = Ahorn.getSprite(midResource, "Gameplay")
- tilesWidth = div(width, 8)
- tilesHeight = div(height, 8)
- for i in 2:tilesWidth - 1
- Ahorn.drawImage(ctx, frame, x + (i - 1) * 8, y, 8, 0, 8, 8)
- Ahorn.drawImage(ctx, frame, x + (i - 1) * 8, y + height - 8, 8, 16, 8, 8)
- end
- for i in 2:tilesHeight - 1
- Ahorn.drawImage(ctx, frame, x, y + (i - 1) * 8, 0, 8, 8, 8)
- Ahorn.drawImage(ctx, frame, x + width - 8, y + (i - 1) * 8, 16, 8, 8, 8)
- end
- for i in 2:tilesWidth - 1, j in 2:tilesHeight - 1
- Ahorn.drawImage(ctx, frame, x + (i - 1) * 8, y + (j - 1) * 8, 8, 8, 8, 8)
- end
- Ahorn.drawImage(ctx, frame, x, y, 0, 0, 8, 8)
- Ahorn.drawImage(ctx, frame, x + width - 8, y, 16, 0, 8, 8)
- Ahorn.drawImage(ctx, frame, x, y + height - 8, 0, 16, 8, 8)
- Ahorn.drawImage(ctx, frame, x + width - 8, y + height - 8, 16, 16, 8, 8)
- Ahorn.drawImage(ctx, midSprite, x + div(width - midSprite.width, 2), y + div(height - midSprite.height, 2))
- end
- function renderToggleBlock(ctx::Ahorn.Cairo.CairoContext, width::Number, height::Number)
- midSprite = Ahorn.getSprite(midResource, "Gameplay")
- nodes = get(entity.data, "nodes", ())
- tilesWidth = div(width, 8)
- tilesHeight = div(height, 8)
- for node in nodes
- nx, ny = Int.(node)
- for i in 2:tilesWidth - 1
- Ahorn.drawImage(ctx, frame, nx + (i - 1) * 8, ny, 8, 0, 8, 8)
- Ahorn.drawImage(ctx, frame, nx + (i - 1) * 8, ny + height - 8, 8, 16, 8, 8)
- end
- for i in 2:tilesHeight - 1
- Ahorn.drawImage(ctx, frame, nx, ny + (i - 1) * 8, 0, 8, 8, 8)
- Ahorn.drawImage(ctx, frame, nx + width - 8, ny + (i - 1) * 8, 16, 8, 8, 8)
- end
- for i in 2:tilesWidth - 1, j in 2:tilesHeight - 1
- Ahorn.drawImage(ctx, frame, nx + (i - 1) * 8, ny + (j - 1) * 8, 8, 8, 8, 8)
- end
- Ahorn.drawImage(ctx, frame, nx, ny, 0, 0, 8, 8)
- Ahorn.drawImage(ctx, frame, nx + width - 8, ny, 16, 0, 8, 8)
- Ahorn.drawImage(ctx, frame, nx, ny + height - 8, 0, 16, 8, 8)
- Ahorn.drawImage(ctx, frame, nx + width - 8, ny + height - 8, 16, 16, 8, 8)
- Ahorn.drawImage(ctx, midSprite, nx + div(width - midSprite.width, 2), ny + div(height - midSprite.height, 2))
- end
- end
- function Ahorn.renderSelectedAbs(ctx::Ahorn.Cairo.CairoContext, entity::ToggleBlock, room::Maple.Room)
- sprite = get(entity.data, "sprite", "block")
- width = Int(get(entity.data, "width", 32))
- height = Int(get(entity.data, "height", 32))
- px, py = Ahorn.position(entity)
- for node in get(entity.data, "nodes", ())
- nx, ny = Int.(node)
- theta = atan(py - ny, px - nx)
- Ahorn.drawArrow(ctx, px, py, nx + cos(theta) * 8, ny + sin(theta) * 8, Ahorn.colors.selection_selected_fc, headLength=6)
- px, py = nx, ny
- end
- renderToggleBlock(ctx, width, height)
- end
- function Ahorn.renderAbs(ctx::Ahorn.Cairo.CairoContext, entity::ToggleBlock, room::Maple.Room)
- sprite = get(entity.data, "sprite", "block")
- startX, startY = Int(entity.data["x"]), Int(entity.data["y"])
- width = Int(get(entity.data, "width", 32))
- height = Int(get(entity.data, "height", 32))
- renderSingleToggleBlock(ctx, startX, startY, width, height)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement