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"))
|
(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))))
|
||||||
|
@ -1049,9 +1047,10 @@
|
||||||
('undo
|
('undo
|
||||||
(rollback-snapshot!)
|
(rollback-snapshot!)
|
||||||
(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,11 +1060,12 @@
|
||||||
(_ #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
|
||||||
(*level-last*
|
(cond
|
||||||
(load-level! *level-last*)
|
(*level-last*
|
||||||
(set! *level-last* #f))
|
(load-level! *level-last*)
|
||||||
(else (reset-game!))))))
|
(set! *level-last* #f))
|
||||||
|
(else (reset-game!))))))
|
||||||
|
|
||||||
;; Canvas and event loop setup
|
;; Canvas and event loop setup
|
||||||
(define canvas (get-element-by-id "canvas"))
|
(define canvas (get-element-by-id "canvas"))
|
||||||
|
|
Loading…
Add table
Reference in a new issue