summaryrefslogtreecommitdiff
path: root/examples/coroutine.scm
blob: 58b3a1beab615601d7725122f1272e47a343166a (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
(use-modules (2d agenda)
             (2d coroutine)
             (2d game)
             (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)