summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2013-12-01 22:32:35 -0500
committerDavid Thompson <dthompson2@worcester.edu>2013-12-01 22:32:35 -0500
commit2d6b4200cf731e17f144e86d8b52615e6e78c85b (patch)
treed3e91a16338c1e25808be45db01508ba9b37e96d /examples
parent8f3718977046ce73e0174b0fa550f91a18106e0d (diff)
Update example.
Diffstat (limited to 'examples')
-rw-r--r--examples/rewrite-test.scm29
1 files changed, 15 insertions, 14 deletions
diff --git a/examples/rewrite-test.scm b/examples/rewrite-test.scm
index 311e747..3582174 100644
--- a/examples/rewrite-test.scm
+++ b/examples/rewrite-test.scm
@@ -1,6 +1,7 @@
(use-modules (srfi srfi-1)
(2d color)
(2d game)
+ (2d keyboard)
(2d signals)
(2d sprite)
(2d texture)
@@ -11,34 +12,34 @@
(with-window (make-window #:title "FRP is cool"
#:resolution (vector2 640 480)
#:fullscreen? #f)
-
+ ;; Move when arrow keys are pressed.
(define move
(make-signal
#:init (vector2 320 240)
#:transformer (lambda (value old from)
- (if (eq? from arrows)
- old
- (v+ (vscale (signal-ref arrows) 5)
- old)))
- #:connectors (list arrows (time-every))))
+ (v+ (vscale (signal-ref key-arrows) 4) old))
+ #:filter (lambda (value old from)
+ (not (eq? from key-arrows)))
+ #:connectors (list key-arrows (time-every))))
(define ghost-texture (load-texture "images/ghost.png"))
- (define sprite
- (make-sprite ghost-texture
- #:position move))
+ (define ghost (make-sprite ghost-texture #:position move))
(define follower-count 8)
+
(define followers
(list-tabulate
follower-count
(lambda (i)
(make-sprite ghost-texture
- #:position (time-delay (* (- follower-count i) 1) move)
- #:color (make-color 1 1 1 (/ (1+ i) 16))))))
+ ;; 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))))))
- ;; Temporary hack. There shouldn't be side effects like this in
- ;; signals.
(define quit-on-esc
(signal-lift (lambda (down?)
(when down?
@@ -47,6 +48,6 @@
(define (draw)
(for-each draw-sprite followers)
- (draw-sprite sprite))
+ (draw-sprite ghost))
(run-game #:draw draw))