From 80731c6fb16136aca817b388636636635106c928 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Wed, 4 Sep 2013 23:00:01 -0400 Subject: Update the rest of the examples to use the new declarative game stuff. --- examples/animation.scm | 45 ++++++++++++++++----------------------------- 1 file changed, 16 insertions(+), 29 deletions(-) (limited to 'examples/animation.scm') diff --git a/examples/animation.scm b/examples/animation.scm index 0e58b8e..c165568 100644 --- a/examples/animation.scm +++ b/examples/animation.scm @@ -1,33 +1,13 @@ (use-modules (2d animation) - (2d game-loop) - (2d helpers) + (2d game) (2d sprite) (2d tileset) (2d vector2) (2d window)) -(define window-width 800) -(define window-height 600) - -;; Open the window. -(open-window window-width window-height) - -(define (key-down key mod unicode) - (cond ((any-equal? key 'escape 'q) - (close-window) - (quit)))) - -;; Draw our sprite -(define (render) - (draw-sprite sprite)) - -;; Register callbacks. -(add-hook! on-render-hook (lambda () (render))) -(add-hook! on-key-down-hook (lambda (key mod unicode) (key-down key mod unicode))) - -;; Load a texture, split it into 64x64 tiles, and build an animated -;; sprite out of it. -(define animation +(define (demo-animation) + "Load a texture, split it into 64x64 tiles, and build an animated +sprite out of it." (let* ((tiles (load-tileset "images/princess.png" 64 64)) (frames (vector (tileset-ref tiles 19) (tileset-ref tiles 20) @@ -39,10 +19,17 @@ (tileset-ref tiles 26)))) (make-animation frames 6 #t))) -(define sprite - (make-sprite animation - #:position (vector2 (/ window-width 2) - (/ window-height 2)))) +(define (demo-sprite) + (make-sprite (demo-animation) + #:position (vector2 320 240))) + +(define-scene demo + #:title "Demo" + #:draw (lambda (sprite) (draw-sprite sprite)) + #:state (demo-sprite)) +(define-game animation + #:title "Animation" + #:first-scene demo) -(run-game-loop) +(run-game animation) -- cgit v1.2.3