summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2015-03-09 08:52:14 -0400
committerDavid Thompson <dthompson2@worcester.edu>2015-03-09 08:58:42 -0400
commitd84bb24d2359be9c4be7b3e4f05caf3daf68f243 (patch)
treed57b082948ef75bdd0f9cc5d1c15a8d70d784d26 /examples
parent8ac70ff3cef2963c460ce5382e37946eb0a4914e (diff)
render: Merge <group> into <model>.
* sly/render/model.scm (<model>): Add 'transform' and 'children' fields. (model-transform, model-children): New accessors. (make-model): Add 'transform' and 'children' keyword arguments. (set-transform-identity!): New procedure. (draw-model): Recursively draw model and all children. (model-paint, model-blend): Renamed. (paint, blend, group, group*, move, place): New procedures. * sly/render/group.scm: Delete. * Makefile.am (SOURCES): Remove it. * examples/2048/2048.scm: Update example. * examples/animation.scm: Likewise. * examples/font.scm: Likewise. * examples/joystick.scm: Likewise. * examples/mines/mines.scm: Likewise. * examples/simple.scm: Likewise. * examples/tilemap.scm: Likewise. * README.org (Example): Update sample code.
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/2048/2048.scm72
-rw-r--r--examples/animation.scm13
-rw-r--r--examples/font.scm15
-rw-r--r--examples/joystick.scm9
-rw-r--r--examples/mines/mines.scm23
-rw-r--r--examples/simple.scm13
-rw-r--r--examples/tilemap.scm11
7 files changed, 75 insertions, 81 deletions
diff --git a/examples/2048/2048.scm b/examples/2048/2048.scm
index 73cb5f6..7bffe0b 100755
--- a/examples/2048/2048.scm
+++ b/examples/2048/2048.scm
@@ -37,7 +37,6 @@
(sly render color)
(sly render context)
(sly render font)
- (sly render group)
(sly render model)
(sly render sprite)
(sly render texture)
@@ -324,14 +323,15 @@
(label (assoc-ref tile-label-cache n))
(label-color (tile-text-color n))
(bg-color (tile-bg-color n)))
- (group-move (vector2 (* x w) (* y h))
- (make-group
- (cons (model-paint bg-color tile-sprite)
- (if (zero? n)
- '()
- (list (group-move (vector2 (/ w 2) (/ h 2))
- (group (model-paint label-color
- label))))))))))
+ (move (vector2 (* x w) (* y h))
+ (group*
+ (cons (paint bg-color tile-sprite)
+ (if (zero? n)
+ '()
+ (list (move (vector2 (/ w 2) (/ h 2))
+ (group
+ (paint label-color
+ label))))))))))
(define window-width 640)
(define window-height 480)
@@ -347,7 +347,7 @@
(define-signal tiles
(signal-map (lambda (board)
- (make-group
+ (group*
(append-map
(match-lambda
((y (row ...))
@@ -361,24 +361,24 @@
(define play-again-font (load-default-font 16))
(define-signal status-message
- (let ((play-again (model-paint black (label play-again-font
- "Press N to play again"
- #:anchor 'top-center)))
- (game-over (model-paint black (label font "GAME OVER"
- #:anchor 'bottom-center)))
- (you-win (model-paint black (label font "YOU WIN!"
- #:anchor 'bottom-center))))
+ (let ((play-again (paint black (label play-again-font
+ "Press N to play again"
+ #:anchor 'top-center)))
+ (game-over (paint black (label font "GAME OVER"
+ #:anchor 'bottom-center)))
+ (you-win (paint black (label font "YOU WIN!"
+ #:anchor 'bottom-center))))
(signal-map
(lambda (board)
(let ((message (cond
((board-lose? board) game-over)
((board-win? board) you-win)
(else #f))))
- (group-move (vector2 (/ board-width 2)
- (/ board-height 2))
- (make-group (if message
- (list message play-again)
- '())))))
+ (move (vector2 (/ board-width 2)
+ (/ board-height 2))
+ (group* (if message
+ (list message play-again)
+ '())))))
board)))
(define instruction-font (load-default-font 16))
@@ -387,11 +387,11 @@
"Use the arrow keys to join the numbers and get to the 2048 tile!")
(define-signal instructions
- (group-move (vector2 (/ board-width 2) (- window-height (vy center-pos)))
- (group
- (model-paint text-color-1
- (label instruction-font instruction-text
- #:anchor 'top-center)))))
+ (move (vector2 (/ board-width 2) (- window-height (vy center-pos)))
+ (group
+ (paint text-color-1
+ (label instruction-font instruction-text
+ #:anchor 'top-center)))))
(define score-header-font (load-default-font 14))
(define score-font (load-default-font 22))
@@ -408,13 +408,13 @@
(signal-map (lambda (score timer)
(let ((score (label score-font (number->string score)
#:anchor 'center)))
- (group-move (vector2 x (- window-height 28))
- (group
- (model-paint text-color-1 header)
- (group-move (position-tween timer)
- (group
- (model-paint (color-tween timer)
- score)))))))
+ (move (vector2 x (- window-height 28))
+ (group
+ (paint text-color-1 header)
+ (move (position-tween timer)
+ (group
+ (paint (color-tween timer)
+ score)))))))
score
(signal-drop (lambda (t) (> t duration))
0 (signal-since 1 score)))))
@@ -427,7 +427,7 @@
(- board-width (/ board-width 4))))
(define-signal 2048-scene
- (signal-map (cut group-move center-pos <>)
+ (signal-map (cut move center-pos <>)
(signal-map group instructions tiles score
best-score status-message)))
@@ -438,7 +438,7 @@
(define (draw-2048 dt alpha)
(signal-let ((scene 2048-scene))
- (draw-group scene camera)))
+ (draw-model scene camera)))
;;;
;;; Initialization
diff --git a/examples/animation.scm b/examples/animation.scm
index cc84c27..ef736d2 100644
--- a/examples/animation.scm
+++ b/examples/animation.scm
@@ -22,7 +22,7 @@
(sly math tween)
(sly math vector)
(sly render camera)
- (sly render group)
+ (sly render model)
(sly render sprite)
(sly render tileset))
@@ -45,18 +45,15 @@
(tween (compose floor lerp) (compose ease-linear ease-loop)
0 frame-count (* frame-count frame-rate))))
-(define-signal timer
- (signal-fold + 0 (signal-every 1)))
-
(define-signal scene
(signal-map (lambda (time)
- (group-move (position-tween time)
- (group (vector-ref walk-cycle (frame-tween time)))))
- timer))
+ (move (position-tween time)
+ (vector-ref walk-cycle (frame-tween time))))
+ (signal-timer)))
(define camera (orthographic-camera 640 480))
-(add-hook! draw-hook (lambda _ (draw-group (signal-ref scene) camera)))
+(add-hook! draw-hook (lambda _ (draw-model (signal-ref scene) camera)))
(with-window (make-window #:title "Animation")
(start-game-loop))
diff --git a/examples/font.scm b/examples/font.scm
index 177879e..b3fcfc3 100644
--- a/examples/font.scm
+++ b/examples/font.scm
@@ -24,7 +24,7 @@
(sly render color)
(sly render font)
(sly render model)
- (sly render group)
+ (sly render model)
(sly input mouse))
(load "common.scm")
@@ -34,21 +34,20 @@
(define font (load-default-font 18))
(define-signal message-label
- (group-move (vector2 320 240)
- (group
- (label font "The quick brown fox jumped over the lazy dog."
- #:anchor 'center))))
+ (move (vector2 320 240)
+ (label font "The quick brown fox jumped over the lazy dog."
+ #:anchor 'center)))
(define-signal fps-label
(signal-map (lambda (fps)
(let ((text (format #f "FPS: ~d" fps)))
- (group-move (vector2 0 480) (group (label font text)))))
+ (move (vector2 0 480) (label font text))))
fps))
(define-signal mouse-label
(signal-map (lambda (p)
(let ((text (format #f "Mouse: (~d, ~d)" (vx p) (vy p))))
- (group-move (vector2 0 460) (group (label font text)))))
+ (move (vector2 0 460) (label font text))))
(signal-throttle 5 mouse-position)))
(define-signal scene
@@ -56,7 +55,7 @@
(define camera (orthographic-camera 640 480))
-(add-hook! draw-hook (lambda _ (draw-group (signal-ref scene) camera)))
+(add-hook! draw-hook (lambda _ (draw-model (signal-ref scene) camera)))
(with-window (make-window #:title "Fonts")
(start-game-loop))
diff --git a/examples/joystick.scm b/examples/joystick.scm
index 57955c9..7aa83c7 100644
--- a/examples/joystick.scm
+++ b/examples/joystick.scm
@@ -28,7 +28,6 @@
(sly input joystick)
(sly render camera)
(sly render model)
- (sly render group)
(sly render sprite)
(sly render texture)
(sly render font))
@@ -56,8 +55,7 @@
(define-signal caption
(signal-map (lambda (text)
- (group-move (vector2 -76 -90)
- (group (label font text))))
+ (move (vector2 -76 -90) (label font text)))
(signal-merge
(make-signal "Press a button")
(button-caption-signal "Hello there" 0)
@@ -67,13 +65,12 @@
(define-signal scene
(signal-map (lambda (position caption)
- (group-move position
- (group player caption)))
+ (move position (group player caption)))
player-position caption))
(define camera (orthographic-camera (vx resolution) (vy resolution)))
-(add-hook! draw-hook (lambda _ (draw-group (signal-ref scene) camera)))
+(add-hook! draw-hook (lambda _ (draw-model (signal-ref scene) camera)))
(add-hook! joystick-axis-hook
(lambda (which axis value)
diff --git a/examples/mines/mines.scm b/examples/mines/mines.scm
index 97d77b0..663e146 100644
--- a/examples/mines/mines.scm
+++ b/examples/mines/mines.scm
@@ -37,7 +37,6 @@
(sly render camera)
(sly render color)
(sly render font)
- (sly render group)
(sly render model)
(sly render sprite)
(sly input keyboard)
@@ -332,24 +331,24 @@
(lambda (tile)
;; A tile may or may not have an overlay, so we do a little
;; quasiquoting magic to build the right list.
- (make-group
+ (group*
`(,(tile-base-sprite tile)
,@(let ((overlay (tile-overlay-sprite tile)))
(if overlay
- (list (group-place offset (group overlay)))
+ (list (place offset (group overlay)))
'())))))))
(define-signal board-view
(signal-map (lambda (board)
(define (draw-column tile x)
- (group-move (vector2 (* x tile-size) 0)
- (draw-tile tile)))
+ (move (vector2 (* x tile-size) 0)
+ (draw-tile tile)))
(define (draw-row row y)
- (group-move (vector2 0 (* y tile-size))
- (make-group (enumerate-map draw-column row))))
+ (move (vector2 0 (* y tile-size))
+ (group* (enumerate-map draw-column row))))
- (make-group (enumerate-map draw-row board)))
+ (group* (enumerate-map draw-row board)))
board))
(define-signal status-message
@@ -357,9 +356,9 @@
(define (make-message message)
(label font message #:anchor 'center))
- (group-move
+ (move
(vector2 (/ (vx resolution) 2) (- (vy resolution) 64))
- (make-group
+ (group*
(cond
((board-lose? board)
(list (make-message "GAME OVER - Press N to play again")))
@@ -372,7 +371,7 @@
(signal-map (lambda (board-view status center-position)
(group
status
- (group-move center-position board-view)))
+ (move center-position board-view)))
board-view status-message center-position))
(define camera
@@ -382,7 +381,7 @@
#:clear-color tango-dark-plum)))
(define (draw-scene dt alpha)
- (draw-group (signal-ref scene) camera))
+ (draw-model (signal-ref scene) camera))
;;;
;;; Initialization
diff --git a/examples/simple.scm b/examples/simple.scm
index 9560f6f..1596cfe 100644
--- a/examples/simple.scm
+++ b/examples/simple.scm
@@ -17,20 +17,23 @@
(use-modules (sly game)
(sly window)
+ (sly utils)
(sly math vector)
(sly render camera)
- (sly render group)
- (sly render sprite))
+ (sly render model)
+ (sly render sprite)
+ (sly render color))
(load "common.scm")
(define scene
- (group-move (vector2 320 240)
- (group (load-sprite "images/p1_front.png"))))
+ (chain (load-sprite "images/p1_front.png")
+ (paint red)
+ (move (vector2 320 240))))
(define camera (orthographic-camera 640 480))
-(add-hook! draw-hook (lambda _ (draw-group scene camera)))
+(add-hook! draw-hook (lambda _ (draw-model scene camera)))
(with-window (make-window #:title "Simple Sprite Demo")
(start-game-loop))
diff --git a/examples/tilemap.scm b/examples/tilemap.scm
index 1615c88..5e54bde 100644
--- a/examples/tilemap.scm
+++ b/examples/tilemap.scm
@@ -26,7 +26,6 @@
(sly utils)
(sly render camera)
(sly render color)
- (sly render group)
(sly render model)
(sly render mesh)
(sly render shader)
@@ -91,15 +90,15 @@
(225 225 176 242 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65))))
(define scene
- (group-move (v- (vector2 320 240)
- (v* (vector2 tile-width tile-height)
- (vector2 10 15/2)))
- (apply group (compile-tile-layer map-tiles 32 32))))
+ (move (v- (vector2 320 240)
+ (v* (vector2 tile-width tile-height)
+ (vector2 10 15/2)))
+ (group* (compile-tile-layer map-tiles 32 32))))
(define camera
(orthographic-camera 640 480))
-(add-hook! draw-hook (lambda _ (draw-group scene camera)))
+(add-hook! draw-hook (lambda _ (draw-model scene camera)))
(with-window (make-window #:title "Tilemap")
(start-game-loop))