Changing the way game state is handled

This commit is contained in:
Amy Grinn 2024-12-20 09:09:12 -05:00
parent 3f463a9a61
commit b248ea72ad
No known key found for this signature in database
GPG key ID: 6B558BED1DCF3192

View file

@ -106,15 +106,21 @@
(define audio:bg-music (load-music "cirkoban")) (define audio:bg-music (load-music "cirkoban"))
;; Game state ;; Game state
(define *state* (list #f)) (define *state* '())
(define (push-game-state! state) (define (push-game-state! state)
(set! *state* (cons state *state*))) (set! *state* (cons state *state*)))
(define (pop-game-state!) (define (pop-game-state!)
(set! *state* (cdr *state*))) (when (pair? *state*)
(set! *state* (cdr *state*))))
(define (current-game-state) (car *state*)) (define (replace-game-state! state)
(if (pair? *state*)
(set! *state* (cons state (cdr *state*)))
(set! *state* (list state))))
(define (current-game-state)
(when (pair? *state*)
(car *state*)))
(define *actormap* (make-whactormap)) (define *actormap* (make-whactormap))
@ -214,7 +220,7 @@
(memq idx *gems*)) (memq idx *gems*))
(define (set-level! idx) (define (set-level! idx)
(push-game-state! 'play) (replace-game-state! 'play)
(set! *actormap* (make-whactormap)) (set! *actormap* (make-whactormap))
(clear-snapshots!) (clear-snapshots!)
(with-goblins (with-goblins
@ -222,7 +228,7 @@
(update-objects!))) (update-objects!)))
(define (load-credits!) (define (load-credits!)
(push-game-state! 'win) (replace-game-state! 'win)
(set! *actormap* (make-whactormap)) (set! *actormap* (make-whactormap))
(set-vec2-y! *credits-scroll* 0.0) (set-vec2-y! *credits-scroll* 0.0)
(clear-snapshots!) (clear-snapshots!)
@ -239,7 +245,7 @@
(begin (begin
(run-script (run-script
(lambda () (lambda ()
(push-game-state! 'interstitial) (replace-game-state! 'interstitial)
(yield (yield
(lambda (k) (lambda (k)
(show-effect! (make-fade-out+in-effect 1.0 k)))) (show-effect! (make-fade-out+in-effect 1.0 k))))
@ -249,7 +255,7 @@
(begin (begin
(run-script (run-script
(lambda () (lambda ()
(push-game-state! 'interstitial) (replace-game-state! 'interstitial)
(yield (yield
(lambda (k) (lambda (k)
(show-effect! (make-fade-out+in-effect 2.0 k)))) (show-effect! (make-fade-out+in-effect 2.0 k))))
@ -403,7 +409,7 @@
(define (reset-game!) (define (reset-game!)
(run-script (run-script
(lambda () (lambda ()
(push-game-state! 'interstitial) (set! *state* '(interstitial))
(yield (yield
(lambda (k) (lambda (k)
(show-effect! (make-fade-out+in-effect 2.0 k)))) (show-effect! (make-fade-out+in-effect 2.0 k))))