summaryrefslogtreecommitdiff
path: root/2d/game.scm
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2013-10-23 22:51:10 -0400
committerDavid Thompson <dthompson2@worcester.edu>2013-10-23 22:51:10 -0400
commit861151d185eefa79c05684fd268d7af09a8195cd (patch)
tree677ebfbd73a1c5e903ec9dedb77819ae2a9cb5b7 /2d/game.scm
parent93633116cc3f3ffc01cb62cddf1222c50c816b4c (diff)
Use the new scene/stage API.
Diffstat (limited to '2d/game.scm')
-rw-r--r--2d/game.scm95
1 files changed, 19 insertions, 76 deletions
diff --git a/2d/game.scm b/2d/game.scm
index 4c58521..4c91b1b 100644
--- a/2d/game.scm
+++ b/2d/game.scm
@@ -22,92 +22,35 @@
;;; Code:
(define-module (2d game)
- #:use-module (2d private game)
- #:use-module (2d game-loop)
+ #:use-module (srfi srfi-9)
#:use-module (2d helpers)
#:use-module (2d observer)
- #:use-module (2d vector2))
-
-;;;
-;;; Scenes
-;;;
-
-;; When no event callbacks are specified for a scene, these
-;; (hopefully) convenient defaults will be used.
-(define %default-scene-events
- `((quit . ,(lambda (state) (quit-game)))
- (key-down . ,(lambda (state key mode unicode)
- (when (any-equal? key 'escape 'q)
- (quit-game))))))
-
-(define (default-scene-events)
- (copy-tree %default-scene-events))
-
-(define* (make-scene #:optional #:key
- (title "A Guile-2D Scene")
- (events (default-scene-events))
- (update (lambda (s) #f))
- (draw (lambda (s) #f))
- (state #f))
- "Return a new scene. TITLE is a human readable name for the
-scene. EVENTS is an alist of event handlers. UPDATE is a procedure
-that updates the scene. DRAW is a procedure that renders the
-scene. STATE is an object that encapsulates the scene state."
- (%make-scene title (alist->observer events) update draw state))
-
-(define-syntax-rule (define-scene name kwargs ...)
- "Syntactic sugar over define and make-scene. Return a procedure that
-creates a new scene."
- (define (name) (make-scene kwargs ...)))
-
-(re-export <scene>
- scene?
- scene-title
- scene-observer
- scene-update-proc
- scene-draw-proc
- scene-state
- scene-trigger
- update-scene
- draw-scene
- push-scene
- replace-scene
- pop-scene)
-
-(export make-scene
- define-scene
- default-scene-events)
+ #:use-module (2d vector2)
+ #:export (<game>
+ make-game
+ game?
+ game-title
+ game-resolution
+ game-fullscreen?
+ game-first-scene))
;;;
;;; Games
;;;
+(define-record-type <game>
+ (%make-game title resolution fullscreen? first-scene)
+ game?
+ (title game-title)
+ (resolution game-resolution)
+ (fullscreen? game-fullscreen?)
+ (first-scene game-first-scene))
+
(define* (make-game #:optional #:key
(title "A Guile-2D Game")
(resolution (vector2 640 480))
- (fullscreen #f)
+ (fullscreen? #f)
(first-scene #f))
"Return a new game. All game properties have some reasonable default
value."
- (%make-game title resolution fullscreen first-scene))
-
-(define-syntax-rule (define-game name kwargs ...)
- "Syntactic sugar over define and make-game."
- (define name (make-game kwargs ...)))
-
-(re-export <game>
- game?
- game-title
- game-resolution
- game-fullscreen?
- game-first-scene
- run-game
- quit-game
- pause-game
- resume-game
- game-running?
- game-paused?
- current-fps)
-
-(export make-game
- define-game)
+ (%make-game title resolution fullscreen? first-scene))