diff options
author | David Thompson <dthompson2@worcester.edu> | 2015-01-24 10:59:11 -0500 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2015-01-24 10:59:11 -0500 |
commit | aa4de8dafeabaaf48ea2b73ec9ce15c2a6da2354 (patch) | |
tree | 05eab1e0541c9d5254e94225c78b54e37b3137f6 | |
parent | 7aa00e8e26eadc0e23da24b56cf314572f1a1f64 (diff) |
render: tileset: Add tileset-invert-index.
* sly/render/tileset.scm (tileset-invert-index): New procedure.
-rw-r--r-- | sly/render/tileset.scm | 12 |
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))) |