X Tutup
Skip to content

Commit fc55fb9

Browse files
committed
platform collides with barrier
1 parent 825a157 commit fc55fb9

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

levels.moon

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,16 @@ Levels = {
3232
-- 1
3333
-- 2
3434
-- 3
35-
class Barrier
35+
class Barrier extends Box
3636
watch_class @
3737

3838
w: 300
3939
h: 150
4040

4141
row_dist: 130
42+
has_collided: false
4243

4344
new: (@row) =>
44-
@position!
45-
46-
position: =>
4745
h = g.getHeight!
4846
@y = h * ((Ground.width * 0.6) + (1 - Ground.width))
4947

@@ -55,12 +53,11 @@ class Barrier
5553
@y += @row_dist
5654
@h = @@h + 50
5755

58-
draw_origin: =>
59-
@x - @w / 2, @y - @h
56+
@y -= @h
6057

6158
draw_shadow: =>
6259
g.push!
63-
g.translate @draw_origin!
60+
g.translate @x, @y
6461

6562
sw = 40
6663
sh = 30
@@ -76,7 +73,7 @@ class Barrier
7673

7774
g.push!
7875

79-
g.translate @draw_origin!
76+
g.translate @x, @y
8077

8178
g.setColor 50,50,50
8279
g.rectangle "fill", ox, oy, @w, @h
@@ -86,6 +83,9 @@ class Barrier
8683

8784
g.pop!
8885

86+
g.setColor 255,255,255, 128
87+
@outline!
88+
8989
update: (dt, world) =>
9090
b = world.box
9191
grow = 1.5 + @row/4
@@ -96,7 +96,9 @@ class Barrier
9696
left = cx - hw * grow
9797
right = cx + hw * grow
9898
@progress = world\block_progress!
99-
@x = (1 - @progress) * (right - left) + left
99+
100+
x = (1 - @progress) * (right - left) + left
101+
@x = x - @w / 2
100102

101103
class World
102104
watch_class @
@@ -174,6 +176,8 @@ class World
174176

175177
setup_block: (bid) =>
176178
@active_block = @level[bid]
179+
for i=1,3
180+
@barriers[i].has_collided = false
177181

178182
update: (dt) =>
179183
@traversed += dt * @speed
@@ -206,4 +210,11 @@ class World
206210
for thing in *@collide\get_touching @player.box
207211
@player\take_hit thing, @
208212

213+
-- barriers colliding
214+
row = @platform\row!
215+
if @active_block[row]
216+
b = @barriers[row]
217+
if not b.has_collided and b\touches_box @platform.hitbox
218+
@platform\take_hit b, @
219+
b.has_collided = true
209220

main.moon

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ class Platform
7878
@ox, @oy = g.getWidth! / 2, g.getHeight! * (2/3)
7979
@elapsed = 0
8080

81+
@hitbox = Box 0,0,450,120
82+
8183
@box = Box -@width/2, -@height/2, @width, @height
8284
@inner_box = Box -@inner_width/2, -@inner_height/2, @inner_width, @inner_height
8385
@recalc!
@@ -132,6 +134,9 @@ class Platform
132134
fn! if fn
133135
@draw_wheels!
134136

137+
g.setColor 255,200, 100
138+
@hitbox\outline!
139+
135140
draw_body: =>
136141
@transformed (elapsed) ->
137142
g.setColor 200,200,200
@@ -198,9 +203,21 @@ class Platform
198203
update: (dt, world) =>
199204
@elapsed += dt
200205

206+
@hitbox\move_center @ox, @oy
207+
201208
for w in *@wheels
202209
w\update dt
203210

211+
take_hit: (barrier, world) =>
212+
s = Sequence ->
213+
with world.particles
214+
for i = 1,8
215+
\add Explosion world, @hitbox\random_point!
216+
wait rand 0.05, 0.1
217+
218+
s.draw = -> -- lol
219+
world.particles\add s
220+
204221
class Wheel
205222
segments: 6
206223
speed: 6

player.moon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class Player extends Entity
4545

4646
mover = make_mover "w", "s", "a", "d"
4747

48+
life: 100
49+
4850
w: 15
4951
h: 50
5052

0 commit comments

Comments
 (0)
X Tutup