summaryrefslogtreecommitdiff
path: root/examples/action.scm
blob: 2886c0a444ffeb7716d92b812f61e8756f5d6ecf (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
37
38
39
40
41
42
(use-modules (2d actions)
             (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 (init)
  (let ((size (game-resolution actions-demo))
        (sprite (demo-sprite)))
    (stage-define sprite sprite)
    (schedule-action
     (action-parallel
      ;; Move horizontally across the screen in 60 frames.
      (lerp (lambda (x)
              (set-sprite-position!
               sprite
               (vector2 x (/ (vy size) 2))))
            0 (vx size) 120)
      ;; Rotate 1080 degrees in 120 frames.
      (lerp (lambda (angle)
              (set-sprite-rotation! sprite angle))
            0 360 120)))))

(define demo-scene
  (make-scene
   #:init init
   #:draw (lambda () (draw-sprite (stage-ref sprite)))))

(define actions-demo
  (make-game
   #:title       "Actions"
   #:first-scene demo-scene))

(run-game actions-demo)