summaryrefslogtreecommitdiff
path: root/examples/tiled.scm
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2018-01-29 19:16:19 -0500
committerDavid Thompson <dthompson2@worcester.edu>2018-01-29 22:31:31 -0500
commit6ba2755dd1ba3bcb1de88799284e908cf7f42b3a (patch)
tree03d0ca3f8f658e77058d1ca6a94904336bea74ba /examples/tiled.scm
parent9c99fc7d12a5c90555b649ed845ab28d6a1b174c (diff)
Add tile map example.
* examples/images/tiles.png: New file. * examples/map/example.tmx: New file. * examples/tiled.scm: New file. * Makefile.am (EXTRA_DIST): Add them. * examples/images/AUTHORS: Credit the author of the tileset.
Diffstat (limited to 'examples/tiled.scm')
-rw-r--r--examples/tiled.scm31
1 files changed, 31 insertions, 0 deletions
diff --git a/examples/tiled.scm b/examples/tiled.scm
new file mode 100644
index 0000000..9e42301
--- /dev/null
+++ b/examples/tiled.scm
@@ -0,0 +1,31 @@
+(use-modules (chickadee)
+ (chickadee math vector)
+ (chickadee math rect)
+ (chickadee render tiled)
+ (ice-9 match))
+
+(define map #f)
+(define camera (vec2 0.0 0.0))
+
+(define (load)
+ (set! map (load-tile-map "maps/example.tmx")))
+
+(define (draw alpha)
+ (draw-tile-map map #:position camera))
+
+(define inc 8.0)
+(define (key-press key scancode modifiers repeat?)
+ (match key
+ ('up (set-vec2-y! camera (- (vec2-y camera) inc)))
+ ('down (set-vec2-y! camera (+ (vec2-y camera) inc)))
+ ('right (set-vec2-x! camera (- (vec2-x camera) inc)))
+ ('left (set-vec2-x! camera (+ (vec2-x camera) inc)))
+ ('q (abort-game))
+ (_ #t)))
+
+(add-hook! load-hook load)
+(add-hook! draw-hook draw)
+(add-hook! key-press-hook key-press)
+(add-hook! quit-hook abort-game)
+
+(run-game #:window-width 320 #:window-height 240 #:window-title "tile map demo")