Drain charge when using defense mode.

This commit is contained in:
Anna Rose 2023-10-04 23:29:48 -04:00
parent 47bbeefecf
commit 37100c84fc

View File

@ -74,8 +74,7 @@ end
function Kani:chargeReserve(change) function Kani:chargeReserve(change)
if change <= 0 then return end if change <= 0 then return end
self.reserveCharge = math.min(self.reserveCharge + change / self.chargeFactor, 100) self:setReserveCharge(math.min(self.reserveCharge + change / self.chargeFactor, 100))
self.ui.chargeMeter:setValue(self.reserveCharge)
end end
function Kani:chargeShot() function Kani:chargeShot()
@ -91,13 +90,21 @@ function Kani:chargeShot()
local effectiveCharge = math.ceil(self.reserveCharge) local effectiveCharge = math.ceil(self.reserveCharge)
if effectiveCharge >= requiredPower then if effectiveCharge >= requiredPower then
self.reserveCharge = effectiveCharge - requiredPower self:setReserveCharge(effectiveCharge - requiredPower)
self.weaponPower += 1 self:setWeaponPower(self.weaponPower+1)
self.ui.chargeMeter:setValue(self.reserveCharge)
self.ui.weaponPowerMeter:setValue(self.weaponPower-1)
end end
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() function Kani:fire()
self.firingTimer:remove() self.firingTimer:remove()
@ -113,8 +120,7 @@ function Kani:fire()
) )
bullet:moveTo(self.x+16, self.y) bullet:moveTo(self.x+16, self.y)
bullet:add() bullet:add()
self.weaponPower = 0 self:setWeaponPower(0)
self.ui.weaponPowerMeter:setValue(0)
end end
function Kani:damage(amount) function Kani:damage(amount)
@ -146,7 +152,9 @@ function Kani:runReady()
end end
local change = select(1, playdate.getCrankChange()) 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 if playdate.buttonJustPressed(playdate.kButtonA) then
self.firingTimer = playdate.timer.keyRepeatTimerWithDelay(self.weaponChargeSpeed / 2, self.firingTimer = playdate.timer.keyRepeatTimerWithDelay(self.weaponChargeSpeed / 2,
@ -158,7 +166,6 @@ function Kani:runReady()
end end
if playdate.buttonIsPressed(playdate.kButtonB) then if playdate.buttonIsPressed(playdate.kButtonB) then
print("Triggering entrance to DEFEND mode")
self.fsm:changeState("DEFEND") self.fsm:changeState("DEFEND")
end end
@ -180,5 +187,8 @@ end
function Kani:runDefend() function Kani:runDefend()
if not playdate.buttonIsPressed(playdate.kButtonB) then if not playdate.buttonIsPressed(playdate.kButtonB) then
self.fsm:changeState("READY") self.fsm:changeState("READY")
return
end end
self:setReserveCharge(self.reserveCharge - 1)
end end