summaryrefslogtreecommitdiff
path: root/examples/coroutine.scm
diff options
context:
space:
mode:
Diffstat (limited to 'examples/coroutine.scm')
-rw-r--r--examples/coroutine.scm22
1 files changed, 14 insertions, 8 deletions
diff --git a/examples/coroutine.scm b/examples/coroutine.scm
index 7b4a1e6..741b357 100644
--- a/examples/coroutine.scm
+++ b/examples/coroutine.scm
@@ -15,10 +15,12 @@
;;; along with this program. If not, see
;;; <http://www.gnu.org/licenses/>.
-(use-modules (2d agenda)
+(use-modules (srfi srfi-26)
+ (2d agenda)
(2d coroutine)
(2d game)
(2d sprite)
+ (2d texture)
(2d vector2)
(2d window))
@@ -27,19 +29,23 @@
(define window-width 640)
(define window-height 480)
-(define sprite (load-sprite "images/p1_front.png"
- #:position (vector2 320 240)))
+(define texture (load-texture "images/p1_front.png"))
+
+(define sprite
+ (make-sprite texture
+ #:position (vector 320 240)))
+
+(define (random-vector2)
+ (vector2 (random window-width)
+ (random window-height)))
;; Simple script that moves the sprite to a random location every
;; second.
(coroutine
(while #t
- (set-sprite-position!
- sprite
- (vector2 (random window-width)
- (random window-height)))
+ (set! sprite (set-sprite-position sprite (random-vector2)))
(wait 15)
- (set-sprite-rotation! sprite (random 360))
+ (set! sprite (set-sprite-rotation sprite (random 360)))
(wait 15)))
(add-hook! draw-hook (lambda (dt alpha) (draw-sprite sprite)))