Fix bug where gem could be marked as collected even if move was undone.

This commit is contained in:
David Thompson 2024-05-24 13:23:36 -04:00
parent 3503aeb00b
commit 502b8262e5
2 changed files with 15 additions and 5 deletions

View file

@ -396,6 +396,7 @@
(('wire-state grid-info from from-x from-y) #f)
(('update-wire-state grid-info neighbor-grid) #f)
(('alive?) (not ($ picked-up?)))
(('previously-collected?) previously-collected?)
(('describe)
(if previously-collected?
`(ghost-gem ,position)
@ -758,6 +759,7 @@
(define player (spawn ^cell))
(define objects (spawn ^cell '()))
(define event-log (spawn ^event-log))
(define gem-collected? (spawn ^cell))
;; Spatial partition
(define (for-each-coord proc)
@ -874,8 +876,14 @@
(cons obj (lp rest))
(match ($ obj 'position)
(#(x y z)
;; Remove from spatial partition.
(let ((cell (grid-ref grid x y)))
($ cell (delq obj ($ cell))))
;; If this is a gem, then set a flag that the
;; player has collected it.
(when (and (eq? ($ obj 'type) 'gem)
(not ($ obj 'previously-collected?)))
($ gem-collected? #t))
(lp rest)))))))))
(define (tick-object obj)
(let ((prev-pos ($ obj 'position)))
@ -914,4 +922,5 @@
(let ((cell (grid-ref grid x y)))
($ cell (cons obj ($ cell)))))))
(('flush-events)
($ event-log 'flush))))
($ event-log 'flush))
(('gem-collected?) ($ gem-collected?))))