From 3267fc1ace530a37fecd05d0838809c6f0af22a7 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Thu, 6 Feb 2014 21:18:32 -0500 Subject: Add new coroutine macro. * 2d/coroutine.scm (call-with-coroutine): New name for coroutine. (coroutine): New macro. (colambda, codefine, codefine*): Use call-with-coroutine. * examples/coroutine.scm: Use coroutine macro. * README.org: Update coroutine and agenda examples. --- examples/coroutine.scm | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'examples') diff --git a/examples/coroutine.scm b/examples/coroutine.scm index a479a66..45e8b39 100644 --- a/examples/coroutine.scm +++ b/examples/coroutine.scm @@ -15,17 +15,15 @@ ;; Simple script that moves the sprite to a random location every ;; second. -(codefine (script) - (set-sprite-position! - sprite - (vector2 (random window-width) - (random window-height))) - (wait game-agenda 15) - (set-sprite-rotation! sprite (random 360)) - (wait game-agenda 15) - (script)) - -(schedule game-agenda script) +(coroutine + (while #t + (set-sprite-position! + sprite + (vector2 (random window-width) + (random window-height))) + (wait game-agenda 15) + (set-sprite-rotation! sprite (random 360)) + (wait game-agenda 15))) (add-hook! draw-hook (lambda (dt alpha) (draw-sprite sprite))) -- cgit v1.2.3