summaryrefslogtreecommitdiff
path: root/examples/animation.scm
blob: bf43be9b9d98140a116094ecf11641a305c0dd83 (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
(use-modules (2d animation)
             (2d game)
             (2d game-loop)
             (2d scene)
             (2d sprite)
             (2d stage)
             (2d tileset)
             (2d vector2)
             (2d window))

(define (demo-animation)
  "Load a texture, split it into 64x64 tiles, and build an animated
sprite out of it."
  (let* ((tiles (load-tileset "images/princess.png" 64 64))
         (frames (vector (tileset-ref tiles 19)
                         (tileset-ref tiles 20)
                         (tileset-ref tiles 21)
                         (tileset-ref tiles 22)
                         (tileset-ref tiles 23)
                         (tileset-ref tiles 24)
                         (tileset-ref tiles 25)
                         (tileset-ref tiles 26))))
    (make-animation frames 6 #t)))

(define (demo-sprite)
  (make-sprite (demo-animation)
               #:position (vector2 320 240)))

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

(define animation-demo
  (make-game
   #:title       "Animation"
   #:first-scene demo-scene))

(run-game animation-demo)