summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDavid Thompson <dthompson@member.fsf.org>2013-09-06 00:06:06 -0400
committerDavid Thompson <dthompson@member.fsf.org>2013-09-06 00:09:29 -0400
commita7ac1834bc375279f7ab0d6b7b72b852f7f991ed (patch)
treef49b45e17364d09c22530752c5af27d0bba17c89 /examples
parent9d96c5301ae3cf7406811879774db3708eabcb89 (diff)
Add example that shows off multiple scenes.
Diffstat (limited to 'examples')
-rw-r--r--examples/scenes.scm55
1 files changed, 55 insertions, 0 deletions
diff --git a/examples/scenes.scm b/examples/scenes.scm
new file mode 100644
index 0000000..a5d65e7
--- /dev/null
+++ b/examples/scenes.scm
@@ -0,0 +1,55 @@
+(use-modules (2d sprite)
+ (2d game)
+ (2d vector2))
+
+;;;
+;;; Scene 1
+;;;
+
+(define (make-sprite-1)
+ (load-sprite "images/sprite.png"
+ #:position (vector2 320 240)))
+
+(define (scene-1-key-press sprite key mod unicode)
+ (when (eq? key 'return)
+ (replace-scene (scene-2))))
+
+(define-scene scene-1
+ #:title "Scene 1"
+ #:draw (lambda (sprite) (draw-sprite sprite))
+ #:events (append
+ (default-scene-events)
+ `((start . ,(lambda (state) (display "Start Scene 1\n")))
+ (stop . ,(lambda (state) (display "Stop Scene 1\n")))
+ (key-down . ,(lambda (state key mod unicode)
+ (scene-1-key-press state key mod unicode)))))
+ #:state (make-sprite-1))
+
+;;;
+;;; Scene 2
+;;;
+
+(define (make-sprite-2)
+ (load-sprite "images/stars.png"
+ #:position (vector2 320 240)))
+
+(define (scene-2-key-press sprite key mod unicode)
+ (when (eq? key 'return)
+ (replace-scene (scene-1))))
+
+(define-scene scene-2
+ #:title "Scene 2"
+ #:draw (lambda (sprite) (draw-sprite sprite))
+ #:events (append
+ (default-scene-events)
+ `((start . ,(lambda (state) (display "Start Scene 2\n")))
+ (stop . ,(lambda (state) (display "Stop Scene 2\n")))
+ (key-down . ,(lambda (state key mod unicode)
+ (scene-2-key-press state key mod unicode)))))
+ #:state (make-sprite-2))
+
+(define-game scenes
+ #:title "Scenes"
+ #:first-scene scene-1)
+
+(run-game scenes)