summaryrefslogtreecommitdiff
path: root/examples/animation.scm
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2015-09-21 19:44:10 -0400
committerDavid Thompson <dthompson2@worcester.edu>2015-09-21 19:48:44 -0400
commit46544b7dba0081f22e686f70c606a338c7fa52dd (patch)
tree9688f43493606f7b0e4da8784a7804cc32f128eb /examples/animation.scm
parentb7bf25020f146331d161d86ef30df31d2959a8dc (diff)
render: Reimplement rendering engine using functional combinators.
Warning: This is a huge commit. I completely gutted the old scene graph and replaced it with a somewhat monadic rendering combinator module instead. The interface remains purely functional, but replaces the <model> data type with procedures in the rendering monad instead. This opens the door for rendering *anything*, not just meshes. Now I can implement particle systems and other non-static things.
Diffstat (limited to 'examples/animation.scm')
-rw-r--r--examples/animation.scm23
1 files changed, 14 insertions, 9 deletions
diff --git a/examples/animation.scm b/examples/animation.scm
index 5dc9166..8aaff2e 100644
--- a/examples/animation.scm
+++ b/examples/animation.scm
@@ -15,25 +15,29 @@
;;; along with this program. If not, see
;;; <http://www.gnu.org/licenses/>.
-(use-modules (sly game)
+(use-modules (sly utils)
+ (sly game)
(sly window)
(sly signal)
(sly math)
+ (sly math rect)
(sly math tween)
(sly math vector)
+ (sly render)
(sly render camera)
- (sly render model)
(sly render sprite)
- (sly render tileset)
- (sly render scene))
+ (sly render tileset))
(load "common.scm")
+(define sprite* (memoize make-sprite))
+(define move* (memoize move))
+
(define walk-cycle
(let ((tiles (load-tileset "images/princess.png" 64 64)))
(list->vector
(map (lambda (id)
- (sprite (tileset-ref tiles id)))
+ (sprite* (tileset-ref tiles id)))
'(19 20 21 22 23 24 25 26)))))
(define position-tween
@@ -46,13 +50,14 @@
(tween (compose floor lerp) (compose ease-linear ease-loop)
0 frame-count (* frame-count frame-rate))))
-(define camera (orthographic-camera 640 480))
+(define camera (2d-camera #:area (make-rect 0 0 640 480)))
(define-signal scene
(signal-let ((time (signal-timer)))
- (let* ((frame (vector-ref walk-cycle (frame-tween time)))
- (model (model-move (position-tween time) frame)))
- (make-scene camera model))))
+ (let* ((frame (vector-ref walk-cycle (frame-tween time))))
+ (with-camera camera
+ (move* (position-tween time)
+ (render-sprite frame))))))
(with-window (make-window #:title "Animation")
(run-game-loop scene))