Smooth out weapon usage and movement, add health bar.
This commit is contained in:
parent
e045eec163
commit
a5bb3744b5
3 changed files with 23 additions and 16 deletions
25
src/kani.lua
25
src/kani.lua
|
@ -13,7 +13,7 @@ local WEAPON_CHARGE_LOOKUP <const> = {
|
|||
[0]=5,
|
||||
[1]=15,
|
||||
[2]=30,
|
||||
[3]=49
|
||||
[3]=50
|
||||
}
|
||||
|
||||
-- maximum value the reserve charge can reach
|
||||
|
@ -24,7 +24,7 @@ class("Kani").extends(gfx.sprite)
|
|||
function Kani:init(ui)
|
||||
local img = gfx.image.new("images/kani.png")
|
||||
Kani.super.init(self, img)
|
||||
print(self)
|
||||
|
||||
self:setCollideRect(0, 0, self:getSize())
|
||||
self.vector = {x=0,y=0} -- movement direction
|
||||
self:setGroupMask(0x2)
|
||||
|
@ -39,10 +39,10 @@ function Kani:init(ui)
|
|||
|
||||
-- input handlers
|
||||
self.inputHandlers = {
|
||||
upButtonDown = function() self.vector.y = -1 end,
|
||||
downButtonDown = function() self.vector.y = 1 end,
|
||||
leftButtonDown = function() self.vector.x = -1 end,
|
||||
rightButtonDown = function() self.vector.x = 1 end,
|
||||
upButtonDown = function() self.vector.y = -3 end,
|
||||
downButtonDown = function() self.vector.y = 3 end,
|
||||
leftButtonDown = function() self.vector.x = -3 end,
|
||||
rightButtonDown = function() self.vector.x = 3 end,
|
||||
upButtonUp = function() self.vector.y = 0 end,
|
||||
downButtonUp = function() self.vector.y = 0 end,
|
||||
leftButtonUp = function() self.vector.x = 0 end,
|
||||
|
@ -56,7 +56,7 @@ function Kani:init(ui)
|
|||
end
|
||||
|
||||
function Kani:chargeReserve(change)
|
||||
if change < 0 then return end
|
||||
if change <= 0 then return end
|
||||
self.reserveCharge = math.min(self.reserveCharge + change / 15, 100)
|
||||
self.ui.chargeMeter:setValue(self.reserveCharge)
|
||||
end
|
||||
|
@ -65,9 +65,16 @@ function Kani:chargeShot()
|
|||
if self.weaponPower >= 4 then
|
||||
return -- weapon is fully charged
|
||||
end
|
||||
|
||||
local requiredPower = WEAPON_CHARGE_LOOKUP[self.weaponPower]
|
||||
if self.reserveCharge > requiredPower then
|
||||
self.reserveCharge -= requiredPower
|
||||
|
||||
-- We use math.ceil here so that any fractional charge rounds up.
|
||||
-- This ensures we can always use our last bit of juice for a level 1 shot,
|
||||
-- and smooths out play experience around fully charged values.
|
||||
local effectiveCharge = math.ceil(self.reserveCharge)
|
||||
|
||||
if effectiveCharge >= requiredPower then
|
||||
self.reserveCharge = effectiveCharge - requiredPower
|
||||
self.weaponPower += 1
|
||||
print("Shot charged to size " .. self.weaponPower)
|
||||
self.ui.chargeMeter:setValue(self.reserveCharge)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue