Animate transition into and out of defend mode.

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

View File

@ -83,6 +83,8 @@ end
-- animate the entity based on the passed in imageTable. If reverse is true, play the
-- animation backwards. duration is how long the animation should be in total
-- TODO: it would be nice to be able to reverse the *current* animation without
-- starting all the way over at the beginning...
function Entity:animate(imgTable, duration, reverse)
self.animationTable = imgTable
local startValue = 1

Binary file not shown.

After

Width:  |  Height:  |  Size: 562 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 525 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 499 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 442 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 365 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 322 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 314 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 285 B

View File

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

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