Smooth out weapon usage and movement, add health bar.
This commit is contained in:
parent
e045eec163
commit
a5bb3744b5
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)
|
||||
|
|
|
@ -24,9 +24,7 @@ function Meter:setValue(value)
|
|||
x = 0
|
||||
w = self.width
|
||||
y = self.height - playdate.math.lerp(0, self.height, value / 100)
|
||||
print(y)
|
||||
h = self.height - y
|
||||
print(h)
|
||||
else
|
||||
y = 0
|
||||
h = self.height
|
||||
|
|
12
src/ui.lua
12
src/ui.lua
|
@ -2,22 +2,24 @@
|
|||
-- we'll keep the OO semantics.
|
||||
import "CoreLibs/object"
|
||||
import "meter"
|
||||
-- import "weaponpowermeter"
|
||||
-- import "weaponpowerwidget"
|
||||
|
||||
class("UI", {}).extends(playdate.object)
|
||||
|
||||
function UI:init()
|
||||
self.chargeMeter = Meter(100, 10, 60)
|
||||
-- self.healthMeter = Meter(100, 60, 10, false)
|
||||
-- self.weaponPowerMeter = WeaponPowerMeter()
|
||||
self:moveTo(394, 159)
|
||||
self.healthMeter = Meter(100, 60, 10, false)
|
||||
-- self.weaponPowerWidget = WeaponPowerWidget()
|
||||
self:moveTo(359, 199)
|
||||
end
|
||||
|
||||
function UI:add()
|
||||
self.chargeMeter:add()
|
||||
self.healthMeter:add()
|
||||
end
|
||||
|
||||
function UI:moveTo(x, y)
|
||||
-- figure out correct offsets later
|
||||
self.chargeMeter:moveTo(x, y + 50)
|
||||
self.chargeMeter:moveTo(x + 35, y)
|
||||
self.healthMeter:moveTo(x, y + 35)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user