summaryrefslogtreecommitdiff
path: root/examples/coroutine.scm
blob: bdfc97353db64a8376d35c26079414927eadaa2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(use-modules (2d agenda)
             (2d coroutine)
             (2d game)
             (2d game-loop)
             (2d scene)
             (2d sprite)
             (2d stage)
             (2d vector2))

(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)))))

(define coroutine-scene
  (make-scene
   "Coroutine"
   #:init (lambda ()
            (load-sprite "images/ghost.png"
                         #:position (vector2 320 240)))
   #:enter enter
   #:draw draw-sprite))

(define coroutine-demo
  (make-game
   #:title "Coroutines"
   #:first-scene coroutine-scene))

(run-game coroutine-demo)