Setting initial game state
Use matching for game state procedures
This commit is contained in:
parent
514c7db401
commit
27b6a4d840
1 changed files with 16 additions and 16 deletions
32
game.scm
32
game.scm
|
@ -106,7 +106,7 @@
|
|||
(define audio:bg-music (load-music "cirkoban"))
|
||||
|
||||
;; Game state
|
||||
(define *state* '())
|
||||
(define *state* '(initial))
|
||||
|
||||
(define (push-game-state! state)
|
||||
(set! *state* (cons state *state*)))
|
||||
|
@ -114,14 +114,12 @@
|
|||
(when (pair? *state*)
|
||||
(set! *state* (cdr *state*))))
|
||||
(define (replace-game-state! state)
|
||||
(if (pair? *state*)
|
||||
(set! *state* (cons state (cdr *state*)))
|
||||
(set! *state* (list state))))
|
||||
|
||||
(match *state*
|
||||
((_ . rest)
|
||||
(set! *state* (cons state rest)))))
|
||||
(define (current-game-state)
|
||||
(when (pair? *state*)
|
||||
(car *state*)))
|
||||
|
||||
(match *state*
|
||||
((state . _) state)))
|
||||
|
||||
(define *actormap* (make-whactormap))
|
||||
(define (call-with-goblins thunk)
|
||||
|
@ -401,7 +399,7 @@
|
|||
(define (reset-game!)
|
||||
(run-script
|
||||
(lambda ()
|
||||
(set! *state* '(interstitial))
|
||||
(replace-game-state! 'interstitial)
|
||||
(yield
|
||||
(lambda (k)
|
||||
(show-effect! (make-fade-out+in-effect 2.0 k))))
|
||||
|
@ -1049,9 +1047,10 @@
|
|||
('undo
|
||||
(rollback-snapshot!)
|
||||
(with-goblins (update-objects!)))
|
||||
;; REMOVE BEFORE RELEASE!!!!
|
||||
;; REMOVE BEFORE RELEASE!!!!
|
||||
;; ('confirm (next-level!))
|
||||
('menu (show-menu!))))
|
||||
('menu (show-menu!))
|
||||
(_ #f)))
|
||||
('menu
|
||||
(match input
|
||||
('up (menu-up!))
|
||||
|
@ -1061,11 +1060,12 @@
|
|||
(_ #f)))
|
||||
;; Pressing any bound input resets the game.
|
||||
;; If traveling to the credits via the menu, go back to '*level-last*'
|
||||
('credits (cond
|
||||
(*level-last*
|
||||
(load-level! *level-last*)
|
||||
(set! *level-last* #f))
|
||||
(else (reset-game!))))))
|
||||
('credits
|
||||
(cond
|
||||
(*level-last*
|
||||
(load-level! *level-last*)
|
||||
(set! *level-last* #f))
|
||||
(else (reset-game!))))))
|
||||
|
||||
;; Canvas and event loop setup
|
||||
(define canvas (get-element-by-id "canvas"))
|
||||
|
|
Loading…
Add table
Reference in a new issue