Skip to content

Commit 31c2501

Browse files
authored
Upside down jumpthrus (#54)
Upside down jumpthrus
2 parents 09bef0c + 9650464 commit 31c2501

File tree

3 files changed

+402
-0
lines changed

3 files changed

+402
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
module SpringCollab2020UpsideDownJumpThru
2+
3+
using ..Ahorn, Maple
4+
5+
@mapdef Entity "SpringCollab2020/UpsideDownJumpThru" UpsideDownJumpThru(x::Integer, y::Integer, width::Integer=Maple.defaultBlockWidth, texture::String="wood")
6+
7+
textures = ["wood", "dream", "temple", "templeB", "cliffside", "reflection", "core", "moon"]
8+
const placements = Ahorn.PlacementDict(
9+
"Upside Down Jump Through ($(uppercasefirst(texture))) (Spring Collab 2020)" => Ahorn.EntityPlacement(
10+
UpsideDownJumpThru,
11+
"rectangle",
12+
Dict{String, Any}(
13+
"texture" => texture
14+
)
15+
) for texture in textures
16+
)
17+
18+
quads = Tuple{Integer, Integer, Integer, Integer}[
19+
(0, 0, 8, 7) (8, 0, 8, 7) (16, 0, 8, 7);
20+
(0, 8, 8, 5) (8, 8, 8, 5) (16, 8, 8, 5)
21+
]
22+
23+
Ahorn.editingOptions(entity::UpsideDownJumpThru) = Dict{String, Any}(
24+
"texture" => textures
25+
)
26+
27+
Ahorn.minimumSize(entity::UpsideDownJumpThru) = 8, 0
28+
Ahorn.resizable(entity::UpsideDownJumpThru) = true, false
29+
30+
function Ahorn.selection(entity::UpsideDownJumpThru)
31+
x, y = Ahorn.position(entity)
32+
width = Int(get(entity.data, "width", 8))
33+
34+
return Ahorn.Rectangle(x, y, width, 8)
35+
end
36+
37+
function Ahorn.render(ctx::Ahorn.Cairo.CairoContext, entity::UpsideDownJumpThru, room::Maple.Room)
38+
texture = get(entity.data, "texture", "wood")
39+
texture = texture == "default" ? "wood" : texture
40+
41+
# Values need to be system specific integer
42+
x = Int(get(entity.data, "x", 0))
43+
y = Int(get(entity.data, "y", 0))
44+
45+
width = Int(get(entity.data, "width", 8))
46+
47+
startX = div(x, 8) + 1
48+
stopX = startX + div(width, 8) - 1
49+
startY = div(y, 8) + 1
50+
51+
Ahorn.Cairo.save(ctx)
52+
53+
Ahorn.scale(ctx, 1, -1)
54+
55+
len = stopX - startX
56+
for i in 0:len
57+
connected = false
58+
qx = 2
59+
if i == 0
60+
connected = get(room.fgTiles.data, (startY, startX - 1), false) != '0'
61+
qx = 1
62+
63+
elseif i == len
64+
connected = get(room.fgTiles.data, (startY, stopX + 1), false) != '0'
65+
qx = 3
66+
end
67+
68+
quad = quads[2 - connected, qx]
69+
Ahorn.drawImage(ctx, "objects/jumpthru/$(texture)", 8 * i, -8, quad...)
70+
end
71+
72+
Ahorn.Cairo.restore(ctx)
73+
end
74+
75+
end

0 commit comments

Comments
 (0)