Animate transition into and out of defend mode.
|
@ -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
|
||||
|
|
BIN
src/images/kani/defend-table-1.png
Normal file
After Width: | Height: | Size: 562 B |
BIN
src/images/kani/defend-table-2.png
Normal file
After Width: | Height: | Size: 525 B |
BIN
src/images/kani/defend-table-3.png
Normal file
After Width: | Height: | Size: 499 B |
BIN
src/images/kani/defend-table-4.png
Normal file
After Width: | Height: | Size: 442 B |
BIN
src/images/kani/defend-table-5.png
Normal file
After Width: | Height: | Size: 365 B |
BIN
src/images/kani/defend-table-6.png
Normal file
After Width: | Height: | Size: 322 B |
BIN
src/images/kani/defend-table-7.png
Normal file
After Width: | Height: | Size: 314 B |
BIN
src/images/kani/defend-table-8.png
Normal file
After Width: | Height: | Size: 285 B |
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 4.8 KiB |
17
src/kani.lua
|
@ -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
|
||||
|
|