bomberpac/game/entities/bomb.fnl

49 lines
1.3 KiB
Plaintext
Raw Normal View History

(local util (require :lib.util))
(local dim (require :game.dim))
(local Bomb (util.hot-table ...))
(fn draw-ticking [bomb x y]
(love.graphics.setColor 0.4 0.4 0.4)
(love.graphics.circle :fill x y (/ dim.tilesize 2))
(love.graphics.setColor 1 0.3 0.3 1)
(love.graphics.print (tostring (math.ceil bomb.timer)) (- x 4) (- y 10)))
(fn draw-exploding [bomb x y]
(let [radius (/ dim.tilesize 2)
l (- x radius)
t (- y radius)]
(love.graphics.setColor 1 0.7 0)
(love.graphics.rectangle :fill l t dim.tilesize dim.tilesize)))
(fn Bomb.draw [x y bomb]
(match bomb.state
:ticking (draw-ticking bomb x y)
:exploding (draw-exploding bomb x y)))
(fn Bomb.set-state [bomb state time]
(set bomb.timer time)
(set bomb.state state)
state)
(fn Bomb.explode [bomb rules]
(Bomb.set-state bomb :exploding 0.5)
2021-04-04 02:36:12 +00:00
(set bomb.bomb nil)
(set bomb.deadly true)
(rules.explode-bomb bomb))
(fn Bomb.update [bomb dt rules]
(set bomb.timer (- bomb.timer dt))
(when (<= bomb.timer 0)
(match bomb.state
:ticking (Bomb.explode bomb rules)
:exploding (rules.clear-bomb bomb))))
(fn Bomb.new []
2021-04-04 02:36:12 +00:00
{:state :ticking :timer 3 :bomb true :draw #(Bomb.draw $...) :update #(Bomb.update $...)})
(fn Bomb.new-explosion []
{:state :exploding :timer 0.5 :deadly true :draw #(Bomb.draw $...) :update #(Bomb.update $...)})
Bomb.hot