Drain charge when using defense mode.
This commit is contained in:
parent
47bbeefecf
commit
37100c84fc
30
src/kani.lua
30
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
|
||||
|
|
Loading…
Reference in New Issue
Block a user