summaryrefslogtreecommitdiff
path: root/examples/shapes.scm
diff options
context:
space:
mode:
Diffstat (limited to 'examples/shapes.scm')
-rw-r--r--examples/shapes.scm56
1 files changed, 35 insertions, 21 deletions
diff --git a/examples/shapes.scm b/examples/shapes.scm
index abaf371..1c20219 100644
--- a/examples/shapes.scm
+++ b/examples/shapes.scm
@@ -15,7 +15,8 @@
;;; along with this program. If not, see
;;; <http://www.gnu.org/licenses/>.
-(use-modules (sly game)
+(use-modules (srfi srfi-26)
+ (sly game)
(sly window)
(sly utils)
(sly signal)
@@ -31,45 +32,58 @@
(load "common.scm")
-(define crate-texture
- (load-texture "images/crate.png"))
+(define-signal crate-texture
+ (on-start (load-texture "images/crate.png")))
-(define sky-background
- (load-sprite "images/country-sky.png"))
+(define-signal sky-background
+ (on-start (load-sprite "images/country-sky.png")))
-(define forest-background
- (load-sprite "images/country-trees.png"))
+(define-signal forest-background
+ (on-start (load-sprite "images/country-trees.png")))
-(define background
+(define (make-background sky forest)
(scale 1/10
(move (vector3 0 0 -10)
(render-begin
- (render-sprite sky-background)
- (render-sprite forest-background)))))
+ (render-sprite sky)
+ (render-sprite forest)))))
-(define unit-cube
- (make-cube 1 #:texture crate-texture))
+(define-signal background
+ (signal-map-maybe make-background
+ sky-background
+ forest-background))
-(define cubes
+(define-signal unit-cube
+ (signal-map-maybe (cut make-cube 1 #:texture <>)
+ crate-texture))
+
+(define (make-cubes unit-cube)
(move (vector3 0 0 -3)
(render-begin
(move (vector3 2 0 0) unit-cube)
unit-cube
(move (vector3 -2 0 0) unit-cube))))
+(define-signal cubes
+ (signal-map-maybe make-cubes unit-cube))
+
(define camera
(3d-camera #:area (make-rect 0 0 640 480)))
(define-signal scene
(signal-let ((rotation (signal-map (lambda (x) (/ x 48))
- (signal-timer))))
- (with-camera camera
- (render-begin
- background
- ;; Spinnin' cubes!
- (with-depth-test #t
- (rotate-x (* rotation 2)
- (rotate-y rotation cubes)))))))
+ (signal-timer)))
+ (background background)
+ (cubes cubes))
+ (if (and background cubes)
+ (with-camera camera
+ (render-begin
+ background
+ ;; Spinnin' cubes!
+ (with-depth-test #t
+ (rotate-x (* rotation 2)
+ (rotate-y rotation cubes)))))
+ render-nothing)))
(with-window (make-window #:title "Shapes!")
(run-game-loop scene))