summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDavid Thompson <dthompson@member.fsf.org>2013-09-02 09:08:20 -0400
committerDavid Thompson <dthompson@member.fsf.org>2013-09-06 00:09:29 -0400
commit7f6d69e986ae9d77b6e7f8e5572f1bdc210a0ad7 (patch)
treed9242ceadb8e9d2279482b4f5f424456c9edd972 /examples
parentb23e7776be3b410c0771715f5624aa6b7190bda4 (diff)
Add a *running* flag to the game loop.
Diffstat (limited to 'examples')
-rw-r--r--examples/simple.scm30
1 files changed, 10 insertions, 20 deletions
diff --git a/examples/simple.scm b/examples/simple.scm
index 6a4e928..c33b7a2 100644
--- a/examples/simple.scm
+++ b/examples/simple.scm
@@ -1,38 +1,28 @@
(use-modules (2d sprite)
+ (2d game)
(2d game-loop)
- (2d window)
(2d helpers)
(2d vector2))
-(define window-width 800)
-(define window-height 600)
-
-;; Open the window.
-(open-window window-width window-height)
-
(define sprite
- (load-sprite "images/sprite.png"
- #:position (vector2 (/ window-width 2)
- (/ window-height 2))))
-
-(define (quit-demo)
- (close-window)
- (quit))
+ (delay (load-sprite "images/sprite.png"
+ #:position (vector2 320 240))))
(define (key-down key mod unicode)
(cond ((any-equal? key 'escape 'q)
- (quit-demo))))
+ (quit-game-loop!))))
;; Draw our sprite
(define (render)
- (draw-sprite sprite))
+ (draw-sprite (force sprite)))
;; Register callbacks.
(add-hook! on-quit-hook (lambda () (quit-demo)))
(add-hook! on-render-hook (lambda () (render)))
-(add-hook! on-key-down-hook (lambda (key mod unicode) (key-down key mod unicode)))
+(add-hook! on-key-down-hook (lambda (key mod unicode)
+ (key-down key mod unicode)))
+(define-game simple
+ #:title "Simple Demo")
-;; Start the game loop.
-;; The render callback will be called through this procedure.
-(run-game-loop)
+(run-game simple)