diff options
author | David Thompson <dthompson2@worcester.edu> | 2013-07-29 23:41:37 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2013-07-29 23:41:37 -0400 |
commit | 14bcea6691922e3eae1852c4c5396c587c2a4321 (patch) | |
tree | bac5bf5c1259c77fb15a498b24d112b04a25babe /examples | |
parent | c601666776babd4e0cb2571dadceaacc1bb4b3b2 (diff) |
Add action example.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/action.scm | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/examples/action.scm b/examples/action.scm new file mode 100644 index 0000000..acc1434 --- /dev/null +++ b/examples/action.scm @@ -0,0 +1,57 @@ +(use-modules (2d sprite) + (2d game-loop) + (2d window) + (2d helpers) + (2d agenda) + (2d coroutine) + (2d actions) + (2d vector)) + +(init-2d) + +(define window-width 800) +(define window-height 600) +(define sprite #f) + +(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))) + +;; Open the window. +(open-window window-width window-height) + +;; Load a sprite and center it on the screen. +(set! sprite + (load-sprite "images/sprite.png" + #:position (vector (/ window-width 2) + (/ window-height 2)))) + +;; Simple script that moves the sprite to a random location every +;; second. +(agenda-schedule + (colambda () + (lerp (lambda (i) + (set-sprite-position! sprite (vector i (/ window-height 2)))) + 0 + 800 + 120))) + +(agenda-schedule + (colambda () + (lerp (lambda (angle) + (set-sprite-rotation! sprite angle)) + 0 + 1080 + 120))) + + +(run-game-loop) |