summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2020-09-19 22:44:44 +0200
committerThomas White <taw@physics.org>2020-09-19 22:44:44 +0200
commit5bfc87ce83b1c22e06879b8a0f0704e08ec7204b (patch)
treea62fd29f75b75d710a18f21d1165e0338f00f01b
parent62027ba25490f15acfc01fb3efdafea5cb9a1ba6 (diff)
Load grid objects
-rw-r--r--heyllama.scm24
-rw-r--r--llama.tmx6
2 files changed, 28 insertions, 2 deletions
diff --git a/heyllama.scm b/heyllama.scm
index 885918a..abe9a77 100644
--- a/heyllama.scm
+++ b/heyllama.scm
@@ -1,6 +1,7 @@
(use-modules (chickadee)
(chickadee math vector)
(chickadee math rect)
+ (chickadee math grid)
(chickadee render font)
(chickadee render sprite)
(chickadee render texture)
@@ -63,6 +64,7 @@
(define llama #f)
(define tile-map #f)
(define view-pos #v(0.0 0.0))
+(define grid (make-grid 16))
(define (load)
(set! llama (make <animal>
@@ -74,7 +76,27 @@
#:spacing 48
#:margin 24)))
- (set! tile-map (load-tile-map "llama.tmx")))
+ (set! tile-map (load-tile-map "llama.tmx"))
+
+ ;; Add objects from map to grid
+
+ (define (add-to-grid obj)
+ (let ((shape (map-object-shape obj)))
+ (grid-add grid
+ (map-object-id obj)
+ (rect-x shape)
+ (rect-y shape)
+ (rect-width shape)
+ (rect-height shape))))
+
+
+ (let ((objects (object-layer-objects
+ (vector-ref (tile-map-layers tile-map)
+ 1))))
+ (for-each (lambda (obj)
+ (add-to-grid obj))
+ objects)))
+
;; ------------------------------------------------
diff --git a/llama.tmx b/llama.tmx
index a2be262..4600eb1 100644
--- a/llama.tmx
+++ b/llama.tmx
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<map version="1.2" tiledversion="1.3.2" orientation="orthogonal" renderorder="right-down" compressionlevel="-1" width="100" height="16" tilewidth="32" tileheight="32" infinite="0" nextlayerid="2" nextobjectid="1">
+<map version="1.2" tiledversion="1.3.2" orientation="orthogonal" renderorder="right-down" compressionlevel="0" width="100" height="16" tilewidth="32" tileheight="32" infinite="0" nextlayerid="3" nextobjectid="5">
<tileset firstgid="1" name="llama" tilewidth="32" tileheight="32" tilecount="25" columns="5">
<image source="Tileset_ground.png" width="160" height="160"/>
</tileset>
@@ -23,4 +23,8 @@
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
</data>
</layer>
+ <objectgroup id="2" name="Object Layer 1">
+ <object id="3" x="1.33333" y="384.667" width="862" height="126.667"/>
+ <object id="4" x="708.667" y="256.667" width="120.667" height="28"/>
+ </objectgroup>
</map>