summaryrefslogtreecommitdiff
path: root/examples/tilemap.scm
diff options
context:
space:
mode:
Diffstat (limited to 'examples/tilemap.scm')
-rw-r--r--examples/tilemap.scm52
1 files changed, 29 insertions, 23 deletions
diff --git a/examples/tilemap.scm b/examples/tilemap.scm
index 2e6bdf9..430e6a0 100644
--- a/examples/tilemap.scm
+++ b/examples/tilemap.scm
@@ -47,13 +47,13 @@
;; loading. Just a hardcoded tile map that demonstrates the
;; split-texture procedure.
-(define (build-map tile-indices)
+(define (build-map tileset tile-indices)
(list->vlist*
(map (lambda (row)
(map (cut tileset-ref tileset <>) row))
tile-indices)))
-(define (random-map width height)
+(define (random-map tileset width height)
(let ((n (vector-length (tileset-tiles tileset))))
(list->vlist*
(list-tabulate
@@ -66,39 +66,45 @@
(define tile-width 32)
(define tile-height 32)
-(define tileset
- (load-tileset "images/tiles.png" tile-width tile-height))
(define map-width 20)
(define map-height 15)
(define map-tiles
- (build-map
- '((65 65 65 65 65 65 65 65 65 224 194 225 194 192 209 210 65 65 65 65)
- (65 65 65 65 65 65 65 65 208 193 225 194 176 241 177 192 210 65 65 65)
- (65 65 65 65 65 65 65 65 224 225 194 194 226 65 240 177 192 210 65 65)
- (65 65 65 65 65 65 65 65 224 225 225 176 242 65 65 240 177 226 65 65)
- (65 65 65 65 65 65 65 208 193 225 225 226 65 65 65 65 224 226 65 65)
- (65 65 65 65 65 65 208 193 194 225 225 226 65 65 65 208 193 226 65 65)
- (65 65 65 65 208 209 193 194 194 225 194 192 209 209 209 193 176 242 65 65)
- (65 65 65 65 224 194 194 194 225 176 241 241 177 225 225 194 192 209 209 209)
- (65 65 65 65 240 177 225 225 176 242 65 65 240 241 241 177 225 225 194 225)
- (65 65 65 208 209 193 225 176 242 65 65 65 65 65 65 240 241 241 241 241)
- (65 65 208 193 225 225 176 242 65 65 65 65 65 65 65 65 65 65 65 65)
- (65 208 193 225 176 241 242 65 65 65 65 65 65 65 65 65 65 65 65 65)
- (208 193 225 176 242 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65)
- (193 225 225 226 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65)
- (225 225 176 242 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65))))
+ '((65 65 65 65 65 65 65 65 65 224 194 225 194 192 209 210 65 65 65 65)
+ (65 65 65 65 65 65 65 65 208 193 225 194 176 241 177 192 210 65 65 65)
+ (65 65 65 65 65 65 65 65 224 225 194 194 226 65 240 177 192 210 65 65)
+ (65 65 65 65 65 65 65 65 224 225 225 176 242 65 65 240 177 226 65 65)
+ (65 65 65 65 65 65 65 208 193 225 225 226 65 65 65 65 224 226 65 65)
+ (65 65 65 65 65 65 208 193 194 225 225 226 65 65 65 208 193 226 65 65)
+ (65 65 65 65 208 209 193 194 194 225 194 192 209 209 209 193 176 242 65 65)
+ (65 65 65 65 224 194 194 194 225 176 241 241 177 225 225 194 192 209 209 209)
+ (65 65 65 65 240 177 225 225 176 242 65 65 240 241 241 177 225 225 194 225)
+ (65 65 65 208 209 193 225 176 242 65 65 65 65 65 65 240 241 241 241 241)
+ (65 65 208 193 225 225 176 242 65 65 65 65 65 65 65 65 65 65 65 65)
+ (65 208 193 225 176 241 242 65 65 65 65 65 65 65 65 65 65 65 65 65)
+ (208 193 225 176 242 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65)
+ (193 225 225 226 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65)
+ (225 225 176 242 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65)))
-(define render
+(define (render tiles)
(move (v- (vector2 320 240)
(v* (vector2 tile-width tile-height)
(vector2 10 15/2)))
- (list->renderer (compile-tile-layer map-tiles 32 32))))
+ (list->renderer
+ (compile-tile-layer (build-map tiles map-tiles) 32 32))))
(define camera (2d-camera #:area (make-rect 0 0 640 480)))
+(define-signal tileset
+ (on-start
+ (load-tileset "images/tiles.png" tile-width tile-height)))
+
(define-signal scene
- (with-camera camera render))
+ (signal-let ((tileset tileset))
+ (if tileset
+ (with-camera camera
+ (render tileset))
+ render-nothing)))
(with-window (make-window #:title "Tilemap")
(run-game-loop scene))