bomberpac/game/tiles.fnl

42 lines
1.1 KiB
Plaintext
Raw Normal View History

(local dim (require :game.dim))
(local util (require :lib.util))
2021-04-11 03:39:42 +00:00
(local {: defmethod} (util.require :lib.multimethod))
(local {: drawtile} (util.require :game.tilemap))
(local tileset (util.hot-table ...))
(fn rect [x y color]
(love.graphics.setColor (table.unpack color))
(love.graphics.rectangle :fill
(- x (/ dim.tilesize 2))
(- y (/ dim.tilesize 2))
dim.tilesize
dim.tilesize))
2021-04-11 03:39:42 +00:00
(fn tileset.make-tileset [tiles]
(each [itile tile (ipairs tiles)]
(tset tiles tile.name itile))
tiles)
(fn tileset.itile-named [tileset name]
(. tileset name))
2021-04-11 03:39:42 +00:00
(defmethod drawtile :strongwall (fn [tile x y] (rect x y [0.7 0.7 0.7])))
(defmethod drawtile :weakwall (fn [tile x y] (rect x y [0.4 0.4 0.4])))
(defmethod drawtile :dot (fn [tile x y]
(love.graphics.setColor 1 1 1)
(love.graphics.circle :fill x y (/ dim.tilesize 8))))
(set tileset.bombertile (tileset.make-tileset
2021-02-07 21:56:19 +00:00
[{:name :empty
:empty true}
2021-02-07 21:56:19 +00:00
{:name :strongwall
2021-04-04 02:36:12 +00:00
:wall true}
2021-02-07 21:56:19 +00:00
{:name :weakwall
2021-04-04 02:36:12 +00:00
:wall true
:breakable true}
2021-02-07 21:56:19 +00:00
{:name :dot
:edible true}
2021-04-11 03:39:42 +00:00
]))
tileset.hot