blob: 760afb0861cb708639997fbf5a31ed1830cf83a5 (
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
47
48
49
50
51
52
|
(use-modules (srfi srfi-1)
(2d color)
(2d game)
(2d keyboard)
(2d signals)
(2d sprite)
(2d texture)
(2d time)
(2d vector2)
(2d window))
(with-window (make-window #:title "FRP is cool"
#:resolution (vector2 640 480)
#:fullscreen? #f)
(define speed 4)
;; Move when arrow keys are pressed.
(define move
(signal-fold (lambda (direction position)
(v+ (vscale direction speed) position))
(vector2 320 240)
(time-every key-arrows)))
(define ghost-texture (load-texture "images/ghost.png"))
(define ghost (make-sprite ghost-texture #:position move))
(define follower-count 8)
(define followers
(list-tabulate
follower-count
(lambda (i)
(make-sprite ghost-texture
;; Follow ghost with some delay.
#:position (time-delay (* (- follower-count i) 10) move)
;; Make each ghost more translucent than the last.
#:color (let ((alpha (/ (1+ i)
(* 2 follower-count))))
(make-color 1 1 1 alpha))))))
(define quit-on-esc
(signal-lift (lambda (down?)
(when down?
(quit-game)))
(key-down? 'escape)))
(define (draw)
(for-each draw-sprite followers)
(draw-sprite ghost))
(run-game #:draw draw))
|