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

@ -196,6 +196,10 @@
(define (next-level!) (define (next-level!)
(let ((idx (+ *level-idx* 1))) (let ((idx (+ *level-idx* 1)))
(pk 'next-level idx) (pk 'next-level idx)
;; TODO: Maybe show a little achievement popup when all gems
;; are collected?
(when (with-goblins ($ (level-actor *level*) 'gem-collected?))
(set! *gems* (cons *level-idx* *gems*)))
(set! *level-idx* idx) (set! *level-idx* idx)
(if (< idx (vector-length levels)) (if (< idx (vector-length levels))
(begin (begin
@ -272,10 +276,7 @@
(('player-death x y) (('player-death x y)
(play-sound-effect audio:die)) (play-sound-effect audio:die))
(('pickup x y) (('pickup x y)
(play-sound-effect audio:pickup) (play-sound-effect audio:pickup))
;; TODO: Maybe show a little achievement popup when all gems
;; are collected?
(set! *gems* (cons *level-idx* *gems*)))
(('emit x y) (('emit x y)
(play-sound-effect audio:emit)) (play-sound-effect audio:emit))
(('emitter-on x y) (('emitter-on x y)

View file

@ -396,6 +396,7 @@
(('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?) (not ($ picked-up?))) (('alive?) (not ($ picked-up?)))
(('previously-collected?) previously-collected?)
(('describe) (('describe)
(if previously-collected? (if previously-collected?
`(ghost-gem ,position) `(ghost-gem ,position)
@ -758,6 +759,7 @@
(define player (spawn ^cell)) (define player (spawn ^cell))
(define objects (spawn ^cell '())) (define objects (spawn ^cell '()))
(define event-log (spawn ^event-log)) (define event-log (spawn ^event-log))
(define gem-collected? (spawn ^cell))
;; Spatial partition ;; Spatial partition
(define (for-each-coord proc) (define (for-each-coord proc)
@ -874,8 +876,14 @@
(cons obj (lp rest)) (cons obj (lp rest))
(match ($ obj 'position) (match ($ obj 'position)
(#(x y z) (#(x y z)
;; Remove from spatial partition.
(let ((cell (grid-ref grid x y))) (let ((cell (grid-ref grid x y)))
($ cell (delq obj ($ cell)))) ($ 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))))))))) (lp rest)))))))))
(define (tick-object obj) (define (tick-object obj)
(let ((prev-pos ($ obj 'position))) (let ((prev-pos ($ obj 'position)))
@ -914,4 +922,5 @@
(let ((cell (grid-ref grid x y))) (let ((cell (grid-ref grid x y)))
($ cell (cons obj ($ cell))))))) ($ cell (cons obj ($ cell)))))))
(('flush-events) (('flush-events)
($ event-log 'flush)))) ($ event-log 'flush))
(('gem-collected?) ($ gem-collected?))))