summaryrefslogtreecommitdiff
path: root/examples/joystick.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/joystick.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/joystick.scm')
-rw-r--r--examples/joystick.scm34
1 files changed, 22 insertions, 12 deletions
diff --git a/examples/joystick.scm b/examples/joystick.scm
index a191de5..661b18e 100644
--- a/examples/joystick.scm
+++ b/examples/joystick.scm
@@ -1,5 +1,6 @@
;;; Sly
;;; Copyright (C) 2014 Jordan Russell <jordan.likes.curry@gmail.com>
+;;; Copyright (C) 2015 David Thompson <davet@gnu.org>
;;;
;;; This program is free software: you can redistribute it and/or
;;; modify it under the terms of the GNU General Public License as
@@ -17,21 +18,21 @@
;;; Commentary:
;;
-;; Joystick example code
+;; Joystick example code.
;;
;;; Code:
(use-modules (sly game)
(sly signal)
(sly window)
+ (sly math rect)
(sly math vector)
(sly input joystick)
+ (sly render)
(sly render camera)
- (sly render model)
(sly render sprite)
(sly render texture)
- (sly render font)
- (sly render scene))
+ (sly render font))
(load "common.scm")
@@ -42,7 +43,10 @@
(define resolution (vector2 640 480))
-(define player (load-sprite "images/p1_front.png"))
+(define player-texture
+ (load-texture "images/p1_front.png"))
+
+(define player (make-sprite player-texture))
(define-signal player-position
(signal-fold v+ (vector2 320 240)
@@ -56,7 +60,8 @@
(define-signal caption
(signal-map (lambda (text)
- (model-move (vector2 -76 -90) (label font text)))
+ (move (vector2 -76 -90)
+ (render-sprite (make-label font text))))
(signal-merge
(make-signal "Press a button")
(button-caption-signal "Hello there" 0)
@@ -64,15 +69,20 @@
(button-caption-signal "This is the other caption" 2)
(button-caption-signal "This is the other other caption" 3))))
-(define-signal model
- (signal-map (lambda (position caption)
- (model-move position (model-group player caption)))
- player-position caption))
+(define-signal view
+ (signal-let ((position player-position)
+ (caption caption))
+ (move position
+ (render-begin
+ (render-sprite player)
+ caption))))
-(define camera (orthographic-camera (vx resolution) (vy resolution)))
+(define camera
+ (2d-camera #:area (make-rect (vector2 0 0) resolution)))
(define-signal scene
- (signal-map (lambda (model) (make-scene camera model)) model))
+ (signal-let ((view view))
+ (with-camera camera view)))
(add-hook! joystick-axis-hook
(lambda (which axis value)