2021-03-07 16:55:50 +00:00
|
|
|
(local util (require :lib.util))
|
|
|
|
(local dim (require :game.dim))
|
|
|
|
|
2021-03-30 23:24:52 +00:00
|
|
|
(local Bomb (util.hot-table ...))
|
|
|
|
|
2021-03-07 16:55:50 +00:00
|
|
|
(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)
|
2021-03-28 19:23:08 +00:00
|
|
|
(set bomb.deadly true)
|
2021-03-07 16:55:50 +00:00
|
|
|
(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 $...)})
|
2021-03-07 16:55:50 +00:00
|
|
|
|
|
|
|
(fn Bomb.new-explosion []
|
2021-03-30 23:24:52 +00:00
|
|
|
{:state :exploding :timer 0.5 :deadly true :draw #(Bomb.draw $...) :update #(Bomb.update $...)})
|
2021-03-07 16:55:50 +00:00
|
|
|
|
2021-03-30 23:24:52 +00:00
|
|
|
Bomb.hot
|