summaryrefslogtreecommitdiff
path: root/2d
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2014-01-07 21:56:28 -0500
committerDavid Thompson <dthompson2@worcester.edu>2014-01-07 21:56:28 -0500
commit994e6805f2082b07a3415c0b10df6474c5c6a57f (patch)
treeda2f023410046a149b7c2a33623f00ad961b333b /2d
parent4e307506829a3f710f40a58f4fe07b758e3636cc (diff)
Make game loop status parameter.
* 2d/game.scm (%state): Replace with game-loop-status. (game-loop-status): New parameter. (run-game-loop): Set status to running. (game-running?, game-paused?, pause-game, resume-game, quit-game): Use parameter.
Diffstat (limited to '2d')
-rw-r--r--2d/game.scm18
1 files changed, 9 insertions, 9 deletions
diff --git a/2d/game.scm b/2d/game.scm
index da4e0b8..cd73f8f 100644
--- a/2d/game.scm
+++ b/2d/game.scm
@@ -54,15 +54,15 @@
;; * stopped
;; * running
;; * paused
-(define %state 'stopped)
+(define game-loop-status (make-parameter 'stopped))
(define ticks-per-second 60)
(define tick-interval (make-parameter 0))
(define draw-hook (make-hook))
(define (run-game-loop)
"Start the game loop."
- (parameterize ((tick-interval (floor (/ 1000 ticks-per-second))))
- (set! %state 'running)
+ (parameterize ((game-loop-status 'running)
+ (tick-interval (floor (/ 1000 ticks-per-second))))
(resume-game)
(spawn-server)
(game-loop (SDL:get-ticks) 0)))
@@ -125,24 +125,24 @@ time in milliseconds that has passed since the last game update."
;;;
(define (game-running?)
- (or (eq? %state 'running)
- (eq? %state 'paused)))
+ (or (eq? (game-loop-status) 'running)
+ (eq? (game-loop-status) 'paused)))
(define (game-paused?)
- (eq? %state 'paused))
+ (eq? (game-loop-status) 'paused))
(define (pause-game)
"Pauses the game loop. Useful when developing."
- (set! %state 'paused))
+ (game-loop-status 'paused))
(define (resume-game)
"Resumes the game loop."
(when (game-paused?)
- (set! %state 'running)))
+ (game-loop-status 'running)))
(define (quit-game)
"Finish the current frame and terminate the game loop."
- (set! %state 'stopped))
+ (game-loop-status 'stopped))
;;;
;;; Event Handling