Setting initial game state

Use matching for game state procedures
This commit is contained in:
Amy Grinn 2024-12-31 13:14:17 -05:00
parent 514c7db401
commit 27b6a4d840
No known key found for this signature in database
GPG key ID: 6B558BED1DCF3192

View file

@ -106,7 +106,7 @@
(define audio:bg-music (load-music "cirkoban")) (define audio:bg-music (load-music "cirkoban"))
;; Game state ;; Game state
(define *state* '()) (define *state* '(initial))
(define (push-game-state! state) (define (push-game-state! state)
(set! *state* (cons state *state*))) (set! *state* (cons state *state*)))
@ -114,14 +114,12 @@
(when (pair? *state*) (when (pair? *state*)
(set! *state* (cdr *state*)))) (set! *state* (cdr *state*))))
(define (replace-game-state! state) (define (replace-game-state! state)
(if (pair? *state*) (match *state*
(set! *state* (cons state (cdr *state*))) ((_ . rest)
(set! *state* (list state)))) (set! *state* (cons state rest)))))
(define (current-game-state) (define (current-game-state)
(when (pair? *state*) (match *state*
(car *state*))) ((state . _) state)))
(define *actormap* (make-whactormap)) (define *actormap* (make-whactormap))
(define (call-with-goblins thunk) (define (call-with-goblins thunk)
@ -401,7 +399,7 @@
(define (reset-game!) (define (reset-game!)
(run-script (run-script
(lambda () (lambda ()
(set! *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))))
@ -1051,7 +1049,8 @@
(with-goblins (update-objects!))) (with-goblins (update-objects!)))
;; REMOVE BEFORE RELEASE!!!! ;; REMOVE BEFORE RELEASE!!!!
;; ('confirm (next-level!)) ;; ('confirm (next-level!))
('menu (show-menu!)))) ('menu (show-menu!))
(_ #f)))
('menu ('menu
(match input (match input
('up (menu-up!)) ('up (menu-up!))
@ -1061,7 +1060,8 @@
(_ #f))) (_ #f)))
;; Pressing any bound input resets the game. ;; Pressing any bound input resets the game.
;; If traveling to the credits via the menu, go back to '*level-last*' ;; If traveling to the credits via the menu, go back to '*level-last*'
('credits (cond ('credits
(cond
(*level-last* (*level-last*
(load-level! *level-last*) (load-level! *level-last*)
(set! *level-last* #f)) (set! *level-last* #f))