diff options
author | David Thompson <dthompson@member.fsf.org> | 2013-09-04 23:00:01 -0400 |
---|---|---|
committer | David Thompson <dthompson@member.fsf.org> | 2013-09-06 00:09:29 -0400 |
commit | 80731c6fb16136aca817b388636636635106c928 (patch) | |
tree | 0369389907e852da5df5703f09cfb94d183a25b3 /examples/action.scm | |
parent | 96dc9f16e85de2132fc2c640dcefe3d560f23ae7 (diff) |
Update the rest of the examples to use the new declarative game stuff.
Diffstat (limited to 'examples/action.scm')
-rw-r--r-- | examples/action.scm | 75 |
1 files changed, 34 insertions, 41 deletions
diff --git a/examples/action.scm b/examples/action.scm index dab15c1..c0d96b5 100644 --- a/examples/action.scm +++ b/examples/action.scm @@ -1,46 +1,39 @@ -(use-modules (2d sprite) - (2d game-loop) - (2d window) - (2d helpers) +(use-modules (2d actions) (2d agenda) (2d coroutine) - (2d actions) + (2d game) + (2d sprite) (2d vector2)) -(define window-width 800) -(define window-height 600) - -;; Open the window. -(open-window window-width window-height) - -;; Load a sprite and center it on the screen. -(define sprite +(define (demo-sprite) (load-sprite "images/sprite.png" - #:position (vector2 (/ window-width 2) - (/ window-height 2)))) - -(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))) - -(schedule-action - (action-parallel - ;; Move horizontally across the screen in 60 frames. - (lerp (lambda (x) - (set-sprite-position! sprite (vector2 x (/ window-height 2)))) - 0 800 60) - ;; Rotate 1080 degrees in 120 frames. - (lerp (lambda (angle) - (set-sprite-rotation! sprite angle)) - 0 1080 60))) - -(run-game-loop) + #:position (vector2 320 240))) + +(define (start sprite) + (let ((size (game-resolution actions))) + (schedule-action + (action-parallel + ;; Move horizontally across the screen in 60 frames. + (lerp (lambda (x) + (set-sprite-position! + sprite + (vector2 x (/ (vy size) 2)))) + 0 (vx size) 120) + ;; Rotate 1080 degrees in 120 frames. + (lerp (lambda (angle) + (set-sprite-rotation! sprite angle)) + 0 360 120))))) + +(define-scene demo + #:title "Demo" + #:draw (lambda (sprite) (draw-sprite sprite)) + #:events (append + (default-scene-events) + `((start . ,(lambda (sprite) (start sprite))))) + #:state (demo-sprite)) + +(define-game actions + #:title "actions" + #:first-scene demo) + +(run-game actions) |