diff options
author | David Thompson <dthompson2@worcester.edu> | 2013-07-15 23:31:21 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2013-07-15 23:31:21 -0400 |
commit | 6b34b517b2207288155c1d74b25acffc34395eb6 (patch) | |
tree | d7dfe84cebc3d1d2b1803e6aadfeaf75d25a9712 /examples | |
parent | 8f1455e85be0907ce8fb45c63aab586208c59196 (diff) |
Add coroutine example.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/coroutine.scm | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/examples/coroutine.scm b/examples/coroutine.scm new file mode 100644 index 0000000..6e743d1 --- /dev/null +++ b/examples/coroutine.scm @@ -0,0 +1,46 @@ +(use-modules (figl gl) + (srfi srfi-1) + (srfi srfi-9) + (srfi srfi-42) + (ice-9 format) + (2d sprite) + (2d game-loop) + (2d window) + (2d vector) + (2d input) + (2d helpers) + (2d coroutine)) + +(define window-width 800) +(define window-height 600) +(define sprite #f) + +(define (key-down key mod unicode) + (cond ((any-equal? key (keycode escape) (keycode q)) + (close-window) + (quit)))) + +;; Draw our sprite +(define (render) + (draw-sprite sprite)) + +;; Register callbacks. +(set-render-callback (lambda () (render))) +(set-key-down-callback (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. +(coroutine + (while #t + (set-sprite-position! sprite (vector (random window-width) + (random window-height))) + (wait 60))) + +(run-game-loop) |