From 37100c84fcfc114190ff3718435dac9c2cbf621a Mon Sep 17 00:00:00 2001 From: annabunches Date: Wed, 4 Oct 2023 23:29:48 -0400 Subject: [PATCH] Drain charge when using defense mode. --- src/kani.lua | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/kani.lua b/src/kani.lua index 9de5c6a..fe00ac6 100644 --- a/src/kani.lua +++ b/src/kani.lua @@ -74,8 +74,7 @@ end function Kani:chargeReserve(change) if change <= 0 then return end - self.reserveCharge = math.min(self.reserveCharge + change / self.chargeFactor, 100) - self.ui.chargeMeter:setValue(self.reserveCharge) + self:setReserveCharge(math.min(self.reserveCharge + change / self.chargeFactor, 100)) end function Kani:chargeShot() @@ -91,13 +90,21 @@ function Kani:chargeShot() local effectiveCharge = math.ceil(self.reserveCharge) if effectiveCharge >= requiredPower then - self.reserveCharge = effectiveCharge - requiredPower - self.weaponPower += 1 - self.ui.chargeMeter:setValue(self.reserveCharge) - self.ui.weaponPowerMeter:setValue(self.weaponPower-1) + self:setReserveCharge(effectiveCharge - requiredPower) + self:setWeaponPower(self.weaponPower+1) end end +function Kani:setReserveCharge(newCharge) + self.reserveCharge = newCharge + self.ui.chargeMeter:setValue(self.reserveCharge) +end + +function Kani:setWeaponPower(newPwr) + self.weaponPower = newPwr + self.ui.weaponPowerMeter:setValue(math.max(self.weaponPower-1, 0)) +end + function Kani:fire() self.firingTimer:remove() @@ -113,8 +120,7 @@ function Kani:fire() ) bullet:moveTo(self.x+16, self.y) bullet:add() - self.weaponPower = 0 - self.ui.weaponPowerMeter:setValue(0) + self:setWeaponPower(0) end function Kani:damage(amount) @@ -146,7 +152,9 @@ function Kani:runReady() end local change = select(1, playdate.getCrankChange()) - self:chargeReserve(change) + if not playdate.buttonIsPressed(playdate.kButtonA) then + self:chargeReserve(change) + end if playdate.buttonJustPressed(playdate.kButtonA) then self.firingTimer = playdate.timer.keyRepeatTimerWithDelay(self.weaponChargeSpeed / 2, @@ -158,7 +166,6 @@ function Kani:runReady() end if playdate.buttonIsPressed(playdate.kButtonB) then - print("Triggering entrance to DEFEND mode") self.fsm:changeState("DEFEND") end @@ -180,5 +187,8 @@ end function Kani:runDefend() if not playdate.buttonIsPressed(playdate.kButtonB) then self.fsm:changeState("READY") + return end + + self:setReserveCharge(self.reserveCharge - 1) end