blob: e5dce93ce934f418cb8568ec6cfd2316a9212933 (
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
43
44
45
46
|
(use-modules (2d sprite)
(2d game-loop)
(2d window)
(2d helpers)
(2d agenda)
(2d coroutine)
(2d actions)
(2d vector))
(define window-width 800)
(define window-height 600)
;; Open the window.
(open-window window-width window-height)
;; Load a sprite and center it on the screen.
(define sprite
(load-sprite "images/sprite.png"
#:position (vector (/ window-width 2)
(/ window-height 2))))
(define (key-down key mod unicode)
(cond ((any-equal? key 'escape 'q)
(close-window)
(quit))))
;; Draw our sprite
(define (render)
(draw-sprite sprite))
;; Register callbacks.
(add-hook! on-render-hook (lambda () (render)))
(add-hook! on-key-down-hook (lambda (key mod unicode) (key-down key mod unicode)))
(schedule-action
(action-parallel
;; Move horizontally across the screen in 60 frames.
(lerp (lambda (x)
(set-sprite-position! sprite (vector x (/ window-height 2))))
0 800 60)
;; Rotate 1080 degrees in 120 frames.
(lerp (lambda (angle)
(set-sprite-rotation! sprite angle))
0 1080 60)))
(run-game-loop)
|