Remove objects from grid when they die.

This commit is contained in:
David Thompson 2024-05-24 13:00:14 -04:00
parent feb5b8f3d6
commit e580454a97

View file

@ -382,6 +382,7 @@
(('describe) `(bomb ,position ,($ exploding?))) (('describe) `(bomb ,position ,($ exploding?)))
(('collide other offset grid-info) #f))) (('collide other offset grid-info) #f)))
;; TODO: Combine with ghost gem.
(define (^gem bcom x y) (define (^gem bcom x y)
(define position (vector x y 1)) (define position (vector x y 1))
(define picked-up? (spawn ^cell)) (define picked-up? (spawn ^cell))
@ -394,7 +395,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)
(('update-wire-state grid-info neighbor-grid) #f) (('update-wire-state grid-info neighbor-grid) #f)
(('alive?) (pk 'gem-alive? (not ($ picked-up?)))) (('alive?) (not ($ picked-up?)))
(('describe) `(gem ,position)) (('describe) `(gem ,position))
(('collide other offset grid-info) (('collide other offset grid-info)
(when (eq? ($ other 'type) 'player) (when (eq? ($ other 'type) 'player)
@ -883,7 +884,11 @@
;; Cull dead objects. ;; Cull dead objects.
(if ($ obj 'alive?) (if ($ obj 'alive?)
(cons obj (lp rest)) (cons obj (lp rest))
(lp rest))))))) (match ($ obj 'position)
(#(x y z)
(let ((cell (grid-ref grid x y)))
($ cell (delq obj ($ cell))))
(lp rest)))))))))
(define (tick-object obj) (define (tick-object obj)
(let ((prev-pos ($ obj 'position))) (let ((prev-pos ($ obj 'position)))
($ obj 'tick grid-info) ($ obj 'tick grid-info)