Make bombs movable, update bomb rendering

This commit is contained in:
Juliana Sims 2024-05-24 15:23:34 -04:00
parent 27bc4ea783
commit a102a9fb06
No known key found for this signature in database
GPG key ID: 2A00BD4B0090029E
2 changed files with 61 additions and 37 deletions

View file

@ -103,22 +103,18 @@
(define (^brick bcom x y)
(define position (vector x y 1))
(define alive? (spawn ^cell #t))
(define exploding? (spawn ^cell))
(match-lambda*
(('type) 'brick)
(('position) position)
(('tick grid-info) #f)
(('post-tick grid-info)
(when ($ exploding?)
($ alive? #f)))
(('post-tick grid-info) #f)
(('enter obj grid-info) #f)
(('exit obj grid-info) #f)
(('wire-state grid-info from from-x from-y) #f)
(('update-wire-state grid-info neighbor-grid) #f)
(('alive?) ($ alive?))
(('explode)
($ exploding? #t))
(('describe) `(brick ,position ,($ exploding?)))
(('explode) ($ alive? #f))
(('describe) `(brick ,position))
(('collide other offset grid-info) #f)))
;; TODO: Maybe make separate actors for conductive vs. inert blocks.
@ -345,41 +341,67 @@
(('collide other offset grid-info) #f)))
(define (^bomb bcom x y)
(define position (vector x y 2))
(define position (spawn ^cell (vector x y 1)))
(define alive? (spawn ^cell #t))
(define lit? (spawn ^cell))
(define exploding? (spawn ^cell))
(define countdown (spawn ^cell -1))
(define pushed? (spawn ^cell))
(match-lambda*
(('type) 'bomb)
(('position) position)
(('position) ($ position))
(('tick grid-info)
(cond
(($ exploding?)
($ pushed? #f)
(when (> ($ countdown) 0)
($ countdown (- ($ countdown) 1)))
(when (= ($ countdown) 0)
($ alive? #f)
(do ((ix (- x 1) (+ ix 1)))
((> ix (+ x 1)))
(do ((iy (- y 1) (+ iy 1)))
((> iy (+ y 1)))
(unless (and (= ix x) (= iy y))
(let ((obj (match ($ grid-info 'occupants ix iy)
(() #f)
((obj . rest) obj))))
(when (and obj (eq? ($ obj 'type) 'brick))
($ obj 'explode)))))))
(($ lit?)
($ exploding? #t))
(else #f)))
(match ($ position)
(#(x y z)
(do ((ix (- x 1) (+ ix 1)))
((> ix (+ x 1)))
(do ((iy (- y 1) (+ iy 1)))
((> iy (+ y 1)))
(unless (and (= ix x) (= iy y))
(let ((obj (match ($ grid-info 'occupants ix iy)
(() #f)
((obj . rest) obj))))
(when obj
(match ($ obj 'type)
('brick
($ obj 'explode))
('player
($ obj 'explode)
($ grid-info 'append-event `(player-death ,ix ,iy)))
(_ #f)))))))
($ grid-info 'append-event `(explosion ,x ,y))))))
(('post-tick grid-info) #f)
(('enter obj grid-info) #f)
(('exit obj grid-info) #f)
(('wire-state grid-info from from-x from-y) #f)
(('update-wire-state grid-info neighbor-grid)
(when (and (not ($ lit?))
(when (and (< ($ countdown) 0)
(grid-electrified? neighbor-grid))
($ lit? #t)))
($ countdown 2)))
(('alive?) ($ alive?))
(('describe) `(bomb ,position ,($ exploding?)))
(('collide other offset grid-info) #f)))
(('describe) `(bomb ,($ position) ,($ countdown)))
(('collide other offset grid-info)
(when (eq? ($ other 'type) 'player)
(match ($ position)
(#(x y z)
(match offset
(#(dx dy)
(match ($ grid-info 'dimensions)
(#(w h)
(let ((x (modulo (+ x dx) w))
(y (modulo (+ y dy) h)))
(let ((occupant-types
(map (lambda (obj) ($ obj 'type))
($ grid-info 'occupants x y))))
(match occupant-types
((or () ('switch))
($ pushed? #t)
($ position (vector x y z)))
(_ #f))))))))))))
(('pushed?) ($ pushed?))))
;; A gem that has already been collected previously will still appear
;; in the level but it will be drawn differently.
@ -719,6 +741,7 @@
(('exit obj grid-info) #f)
(('wire-state grid-info from from-x from-y) #f)
(('alive?) ($ alive?))
(('explode) ($ alive? #f))
(('describe) `(player ,($ position), ($ alive?)))
(('collide other offset grid-info)
(match ($ position)
@ -730,7 +753,7 @@
(match ($ other 'type)
('exit
($ grid-info 'append-event `(exit ,x ,y)))
('block
((or 'block 'bomb)
(if ($ other 'pushed?)
($ grid-info 'append-event `(push ,x ,y))
(begin