bomberpac/game/tiles.fnl

42 lines
1.1 KiB
Fennel

(local dim (require :game.dim))
(local util (require :lib.util))
(local tileset {})
(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))
(fn tileset.make-tileset [tiles draw]
(each [itile tile (ipairs tiles)]
(tset tiles tile.name itile))
(set tiles.draw draw)
tiles)
(fn tileset.itile-named [tileset name]
(. tileset name))
(fn tileset.bombertile-draw [tile x y]
(match tile.name
:strongwall (rect x y [0.7 0.7 0.7])
:weakwall (rect x y [0.4 0.4 0.4])
:dot (do (love.graphics.setColor 1 1 1)
(love.graphics.circle :fill x y (/ dim.tilesize 8)))))
(set tileset.bombertile (tileset.make-tileset
[{:name :empty
:empty true}
{:name :strongwall
:wall true}
{:name :weakwall
:wall true
:breakable true}
{:name :dot
:edible true}
] (util.fn tileset :bomber-tile-draw)))
tileset