46 lines
1.3 KiB
Plaintext
46 lines
1.3 KiB
Plaintext
|
(local util (require :lib.util))
|
||
|
(local dim (require :game.dim))
|
||
|
|
||
|
(local Bomb {})
|
||
|
(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)
|
||
|
(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 []
|
||
|
{:state :ticking :timer 3 :draw (util.fn Bomb :draw) :update (util.fn Bomb :update)})
|
||
|
|
||
|
(fn Bomb.new-explosion []
|
||
|
{:state :exploding :timer 0.5 :draw (util.fn Bomb :draw) :update (util.fn Bomb :update)})
|
||
|
|
||
|
Bomb
|