summaryrefslogtreecommitdiff
path: root/map.fnl
diff options
context:
space:
mode:
authorJakob L. Kreuze <jakob@memeware.net>2018-10-21 19:14:02 -0400
committerJakob L. Kreuze <jakob@memeware.net>2018-10-21 19:14:02 -0400
commit49de0938a3609be7bcf9bed6766bc27f2d389c2a (patch)
tree37c99278dfe5acf818aae8fcf5680a2e4e020562 /map.fnl
parentfdf869cdddf66b1c1cb27380e157d580a5e3fb82 (diff)
Refactoring + initial surface sliming
Diffstat (limited to 'map.fnl')
-rw-r--r--map.fnl48
1 files changed, 33 insertions, 15 deletions
diff --git a/map.fnl b/map.fnl
index 5f75aa1..068c4c6 100644
--- a/map.fnl
+++ b/map.fnl
@@ -15,20 +15,43 @@
;;;; You should have received a copy of the GNU General Public License along
;;;; with swanky. If not, see <http://www.gnu.org/licenses/>.
-(local tileset-values
+(local tiles
+ {:img (love.graphics.newImage "art/tiles.png")
+ :width 32 :height 32
+ :padding-x 8 :padding-y 8
+ :offsets {:bricks 0}})
+
+(local tile-values
{:empty [1 0 0 0]
:bricks [0 0 0 1]})
-;; Returns the keyword for a given tile pixel.
+(local slime
+ {:img (love.graphics.newImage "art/slime.png")
+ :width 32 :height 32
+ :padding-x 8 :padding-y 8
+ :offsets {:top 0 :bottom 1 :left 2 :right 3}})
+
+;; Creates a new tile object of the given `type-type' positioned at world
+;; coordinates (`x', `y').
+(fn make-tile [tile-type x y]
+ {:x-pos x
+ :y-pos y
+ :type tile-type
+ :slimed {:top false
+ :bottom false
+ :left false
+ :right false}})
+
+;; Returns the tile object for a given pixel in `image'.
(fn get-tile [image x y]
- (var res :empty)
+ (var res (make-tile :empty (* x (. tiles :width)) (* y (. tiles :width))))
(let [(r g b a) (: image :getPixel x y)]
- (each [name colors (pairs tileset-values)]
+ (each [tile-type colors (pairs tile-values)]
(when (and (= (. colors 1) r)
(= (. colors 2) g)
(= (. colors 3) b)
(= (. colors 4) a))
- (set res name))))
+ (tset res :type tile-type))))
res)
;; Loads the tile layout of the level from the given ImageData, returning a
@@ -44,20 +67,13 @@
(table.insert tiles row))
(values tiles width height)))
-;; (for [y 0 (- height 1)]
-;; (for [x 0 (- width 1)]
-;; (let [tile (. tiles (+ 1 y) (+ 1 x))]
-;; (if (= tile :empty)
-;; (io.write " ")
-;; :else
-;; (io.write "b"))))
-;; (print))
-
;; Returns the metadata and objects stored in the metadata file at the given
;; path.
(fn load-meta [path]
(fennel.dofile path))
+;; Loads the map of the given name. Will error out if either 'maps/${name}.png'
+;; or 'maps/${name}.fnl' do not exist.
(fn load [name]
(let [tiles-path (.. "maps/" name ".png")
meta-path (.. "maps/" name ".fnl")]
@@ -67,4 +83,6 @@
:height height
:meta (load-meta meta-path)})))
-{:load load}
+{:tiles tiles
+ :slime slime
+ :load load}