Animate transition into and out of defend mode.

This commit is contained in:
Anna Rose Wiggins 2023-10-05 15:26:31 -04:00
parent 37100c84fc
commit f1e29e1ac5
11 changed files with 16 additions and 3 deletions

View file

@ -44,11 +44,17 @@ local SPEED_SIZE_LOOKUP <const> = {
[4] = 1,
}
-- animations table
local animations <const> = {
defend=gfx.imagetable.new("images/kani/defend")
}
class("Kani").extends(Entity)
function Kani:init(ui)
Kani.super.init(self, gfx.image.new("images/kani.png"), 100)
Kani.super.init(self, gfx.image.new("images/kani/static.png"), 100)
self.type = 'kani'
self:setGroupMask(0x2)
@ -96,6 +102,9 @@ function Kani:chargeShot()
end
function Kani:setReserveCharge(newCharge)
if newCharge < 0 then
newcharge = 0
end
self.reserveCharge = newCharge
self.ui.chargeMeter:setValue(self.reserveCharge)
end
@ -165,7 +174,7 @@ function Kani:runReady()
self:fire()
end
if playdate.buttonIsPressed(playdate.kButtonB) then
if playdate.buttonIsPressed(playdate.kButtonB) and self.reserveCharge > 0 then
self.fsm:changeState("DEFEND")
end
@ -178,14 +187,16 @@ end
function Kani:onDefend()
self.armor = 5
self:animate(animations.defend, 500)
end
function Kani:onDefendExit()
self.armor = 0
self:animate(animations.defend, 500, true)
end
function Kani:runDefend()
if not playdate.buttonIsPressed(playdate.kButtonB) then
if self.reserveCharge == 0 or not playdate.buttonIsPressed(playdate.kButtonB) then
self.fsm:changeState("READY")
return
end