summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2015-01-24 10:59:11 -0500
committerDavid Thompson <dthompson2@worcester.edu>2015-01-24 10:59:11 -0500
commitaa4de8dafeabaaf48ea2b73ec9ce15c2a6da2354 (patch)
tree05eab1e0541c9d5254e94225c78b54e37b3137f6
parent7aa00e8e26eadc0e23da24b56cf314572f1a1f64 (diff)
render: tileset: Add tileset-invert-index.
* sly/render/tileset.scm (tileset-invert-index): New procedure.
-rw-r--r--sly/render/tileset.scm12
1 files changed, 11 insertions, 1 deletions
diff --git a/sly/render/tileset.scm b/sly/render/tileset.scm
index fd82400..13ec869 100644
--- a/sly/render/tileset.scm
+++ b/sly/render/tileset.scm
@@ -41,7 +41,8 @@
tileset-spacing
tileset-rows
tileset-columns
- tileset-ref))
+ tileset-ref
+ tileset-invert-index))
(define-record-type <tileset>
(%make-tileset texture tiles width height margin spacing rows columns)
@@ -104,3 +105,12 @@ FILENAME and splitting the texture into tiles."
(define (tileset-ref tileset i)
"Return the tile texture of TILESET at index I."
(vector-ref (tileset-tiles tileset) i))
+
+(define (tileset-invert-index tileset index)
+ "Convert INDEX, whose origin is the top-left corner of TILESET, to
+an index whose origin is the bottom-left corner."
+ (let* ((w (tileset-columns tileset))
+ (h (tileset-rows tileset))
+ (x (modulo index w))
+ (y (- h 1 (floor (/ index w)))))
+ (+ (* y w) x)))