diff options
author | David Thompson <dthompson2@worcester.edu> | 2014-01-10 07:45:41 -0500 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2014-01-10 07:45:41 -0500 |
commit | 5523027f6369e9ec3f990144e8ef2cd4f243476e (patch) | |
tree | df91f447da824dd5e15f0d86aae9e5ec3d4f0409 /examples/coroutine.scm | |
parent | 6bdd1e305834dcc9be22d9a54d84f025a24d4825 (diff) |
Update some of the example programs to use the new API.
* 2d/examples/common.scm: New file.
* 2d/examples/coroutine.scm: Updated.
* 2d/examples/font.scm: Updated.
* 2d/examples/simple.scm: Updated.
* 2d/examples/tilemap.scm: Updated.
Diffstat (limited to 'examples/coroutine.scm')
-rw-r--r-- | examples/coroutine.scm | 50 |
1 files changed, 23 insertions, 27 deletions
diff --git a/examples/coroutine.scm b/examples/coroutine.scm index 58b3a1b..cd01381 100644 --- a/examples/coroutine.scm +++ b/examples/coroutine.scm @@ -1,35 +1,31 @@ (use-modules (2d agenda) (2d coroutine) (2d game) - (2d scene) (2d sprite) - (2d stage) - (2d vector2)) + (2d vector2) + (2d window)) -(define (enter sprite) - ;; Simple script that moves the sprite to a random location every - ;; second. - (agenda-schedule - (colambda () - (while #t - (set-sprite-position! - sprite - (vector2 (random (vx (game-resolution coroutine-demo))) - (random (vy (game-resolution coroutine-demo))))) - (wait 60))))) +(load "common.scm") -(define coroutine-scene - (make-scene - "Coroutine" - #:init (lambda () - (load-sprite "images/ghost.png" - #:position (vector2 320 240))) - #:enter enter - #:draw draw-sprite)) +(define window-width 640) +(define window-height 480) -(define coroutine-demo - (make-game - #:title "Coroutines" - #:first-scene coroutine-scene)) +(define sprite (load-sprite "images/p1_front.png" + #:position (vector2 320 240))) -(run-game coroutine-demo) +;; Simple script that moves the sprite to a random location every +;; second. +(schedule-interval + (lambda () + (set-sprite-position! + sprite + (vector2 (random window-width) + (random window-height)))) + 60) + +(add-hook! draw-hook (lambda (dt alpha) (draw-sprite sprite))) + +(with-window (make-window #:title "Coroutines" + #:resolution (vector2 window-width + window-height)) + (run-game-loop)) |