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

@ -296,6 +296,8 @@
(play-sound-effect audio:electric-switch-off)) (play-sound-effect audio:electric-switch-off))
(('receive-electron x y) (('receive-electron x y)
(play-sound-effect audio:warp 0.25)) (play-sound-effect audio:warp 0.25))
(('explosion x y)
(pk 'BOOM!))
(_ (values))) (_ (values)))
(lp rest)))) (lp rest))))
(update-objects!) (update-objects!)
@ -366,8 +368,7 @@
(_ (draw-tile context tileset 3 x y))) (_ (draw-tile context tileset 3 x y)))
(draw-wire-state pos type))) (draw-wire-state pos type)))
(define (draw-brick pos exploding?) (define (draw-brick pos)
;; TODO use exploding for different sprite?
(draw-tile context tileset 22 (vec2-x pos) (vec2-y pos))) (draw-tile context tileset 22 (vec2-x pos) (vec2-y pos)))
(define (draw-clock-emitter pos) (define (draw-clock-emitter pos)
@ -379,8 +380,8 @@
(define (draw-floor-switch pos on?) (define (draw-floor-switch pos on?)
(draw-tile context tileset (if on? 25 24) (vec2-x pos) (vec2-y pos))) (draw-tile context tileset (if on? 25 24) (vec2-x pos) (vec2-y pos)))
(define (draw-bomb pos exploding?) (define (draw-bomb pos countdown)
(draw-tile context tileset (if exploding? 51 50) (vec2-x pos) (vec2-y pos))) (draw-tile context tileset (+ 51 countdown) (vec2-x pos) (vec2-y pos)))
(define (draw-gem pos) (define (draw-gem pos)
(draw-tile context tileset 28 (vec2-x pos) (vec2-y pos))) (draw-tile context tileset 28 (vec2-x pos) (vec2-y pos)))
@ -418,11 +419,11 @@
(('exit pos) #t) ; drawn via background (('exit pos) #t) ; drawn via background
(('wall pos type) (draw-wall pos type)) (('wall pos type) (draw-wall pos type))
(('block pos type) (draw-block pos type)) (('block pos type) (draw-block pos type))
(('brick pos exploding?) (draw-brick pos exploding?)) (('brick pos) (draw-brick pos))
(('clock-emitter pos) (draw-clock-emitter pos)) (('clock-emitter pos) (draw-clock-emitter pos))
(('switched-emitter pos on?) (draw-switched-emitter pos on?)) (('switched-emitter pos on?) (draw-switched-emitter pos on?))
(('floor-switch pos on?) (draw-floor-switch pos on?)) (('floor-switch pos on?) (draw-floor-switch pos on?))
(('bomb pos exploding?) (draw-bomb pos exploding?)) (('bomb pos countdown) (draw-bomb pos countdown))
(('gem pos) (draw-gem pos)) (('gem pos) (draw-gem pos))
(('ghost-gem pos) (draw-ghost-gem pos)) (('ghost-gem pos) (draw-ghost-gem pos))
(('gate pos open?) (draw-gate pos open?)) (('gate pos open?) (draw-gate pos open?))

View file

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