2021-03-07 16:55:50 +00:00
|
|
|
(local util (require :lib.util))
|
|
|
|
(local dim (require :game.dim))
|
2021-04-11 03:39:42 +00:00
|
|
|
(local {: defmethod} (util.require :lib.multimethod))
|
|
|
|
(local {: update} (util.require :game.entity))
|
|
|
|
(local {: drawtile} (util.require :game.tilemap))
|
2021-03-07 16:55:50 +00:00
|
|
|
|
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)))
|
|
|
|
|
2021-04-11 03:39:42 +00:00
|
|
|
(defmethod drawtile :bomb (fn [bomb x y]
|
2021-03-07 16:55:50 +00:00
|
|
|
(match bomb.state
|
|
|
|
:ticking (draw-ticking bomb x y)
|
2021-04-11 03:39:42 +00:00
|
|
|
:exploding (draw-exploding bomb x y))))
|
2021-03-07 16:55:50 +00:00
|
|
|
|
|
|
|
(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))
|
|
|
|
|
2021-04-11 03:39:42 +00:00
|
|
|
(defmethod update :bomb (fn [bomb dt rules]
|
2021-03-07 16:55:50 +00:00
|
|
|
(set bomb.timer (- bomb.timer dt))
|
|
|
|
(when (<= bomb.timer 0)
|
|
|
|
(match bomb.state
|
|
|
|
:ticking (Bomb.explode bomb rules)
|
2021-04-11 03:39:42 +00:00
|
|
|
:exploding (rules.clear-bomb bomb)))))
|
2021-03-07 16:55:50 +00:00
|
|
|
|
|
|
|
(fn Bomb.new []
|
2021-04-11 03:39:42 +00:00
|
|
|
{:state :ticking :timer 3 :bomb true :entity :bomb})
|
2021-03-07 16:55:50 +00:00
|
|
|
|
|
|
|
(fn Bomb.new-explosion []
|
2021-04-11 03:39:42 +00:00
|
|
|
{:state :exploding :timer 0.5 :deadly true :entity :bomb})
|
2021-03-07 16:55:50 +00:00
|
|
|
|
2021-03-30 23:24:52 +00:00
|
|
|
Bomb.hot
|