diff --git a/src/entity.lua b/src/entity.lua index 648dec8..c4a78a3 100644 --- a/src/entity.lua +++ b/src/entity.lua @@ -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 diff --git a/src/images/kani/defend-table-1.png b/src/images/kani/defend-table-1.png new file mode 100644 index 0000000..26d786b Binary files /dev/null and b/src/images/kani/defend-table-1.png differ diff --git a/src/images/kani/defend-table-2.png b/src/images/kani/defend-table-2.png new file mode 100644 index 0000000..4627733 Binary files /dev/null and b/src/images/kani/defend-table-2.png differ diff --git a/src/images/kani/defend-table-3.png b/src/images/kani/defend-table-3.png new file mode 100644 index 0000000..cfc04cb Binary files /dev/null and b/src/images/kani/defend-table-3.png differ diff --git a/src/images/kani/defend-table-4.png b/src/images/kani/defend-table-4.png new file mode 100644 index 0000000..b5fc32f Binary files /dev/null and b/src/images/kani/defend-table-4.png differ diff --git a/src/images/kani/defend-table-5.png b/src/images/kani/defend-table-5.png new file mode 100644 index 0000000..ea970b3 Binary files /dev/null and b/src/images/kani/defend-table-5.png differ diff --git a/src/images/kani/defend-table-6.png b/src/images/kani/defend-table-6.png new file mode 100644 index 0000000..38376ff Binary files /dev/null and b/src/images/kani/defend-table-6.png differ diff --git a/src/images/kani/defend-table-7.png b/src/images/kani/defend-table-7.png new file mode 100644 index 0000000..178aa32 Binary files /dev/null and b/src/images/kani/defend-table-7.png differ diff --git a/src/images/kani/defend-table-8.png b/src/images/kani/defend-table-8.png new file mode 100644 index 0000000..a81b4cd Binary files /dev/null and b/src/images/kani/defend-table-8.png differ diff --git a/src/images/kani.png b/src/images/kani/static.png similarity index 100% rename from src/images/kani.png rename to src/images/kani/static.png diff --git a/src/kani.lua b/src/kani.lua index fe00ac6..f9768bf 100644 --- a/src/kani.lua +++ b/src/kani.lua @@ -44,11 +44,17 @@ local SPEED_SIZE_LOOKUP = { [4] = 1, } +-- animations table +local animations = { + 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