summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2013-10-23 23:09:31 -0400
committerDavid Thompson <dthompson2@worcester.edu>2013-10-23 23:09:31 -0400
commit2bcb34a9d4e03fa162c74ea9bf3844e8ac23c199 (patch)
treece2ab8729f61d1f2461568193a4bcaec125bca10 /examples
parentadebc9363aa3b57ed05400a0d1a01ead3ac98b4a (diff)
Update coroutine demo.
Diffstat (limited to 'examples')
-rw-r--r--examples/coroutine.scm32
1 files changed, 17 insertions, 15 deletions
diff --git a/examples/coroutine.scm b/examples/coroutine.scm
index 3eac850..2f9b0ae 100644
--- a/examples/coroutine.scm
+++ b/examples/coroutine.scm
@@ -1,35 +1,37 @@
(use-modules (2d agenda)
(2d coroutine)
(2d game)
+ (2d game-loop)
+ (2d scene)
(2d sprite)
+ (2d stage)
(2d vector2))
(define (demo-sprite)
(load-sprite "images/ghost.png"
#:position (vector2 320 240)))
-(define (start sprite)
+(define (init)
;; Simple script that moves the sprite to a random location every
;; second.
+ (stage-define sprite (demo-sprite))
(agenda-schedule
(colambda ()
(while #t
(set-sprite-position!
- sprite
- (vector2 (random (vx (game-resolution coroutines)))
- (random (vy (game-resolution coroutines)))))
+ (stage-ref sprite)
+ (vector2 (random (vx (game-resolution coroutine-demo)))
+ (random (vy (game-resolution coroutine-demo)))))
(wait 60)))))
-(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 demo-scene
+ (make-scene
+ #:init init
+ #:draw (lambda () (draw-sprite (stage-ref sprite)))))
-(define-game coroutines
- #:title "Coroutines"
- #:first-scene demo)
+(define coroutine-demo
+ (make-game
+ #:title "Coroutines"
+ #:first-scene demo-scene))
-(run-game coroutines)
+(run-game coroutine-demo)