From a5bb3744b519abfd5e90868aa3f3ac96252d3a8f Mon Sep 17 00:00:00 2001 From: annabunches Date: Sat, 30 Sep 2023 01:25:07 -0400 Subject: [PATCH] Smooth out weapon usage and movement, add health bar. --- src/kani.lua | 25 ++++++++++++++++--------- src/meter.lua | 2 -- src/ui.lua | 12 +++++++----- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/kani.lua b/src/kani.lua index 59b3f5c..8c1198f 100644 --- a/src/kani.lua +++ b/src/kani.lua @@ -13,7 +13,7 @@ local WEAPON_CHARGE_LOOKUP = { [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) diff --git a/src/meter.lua b/src/meter.lua index 96949a6..d790e2c 100644 --- a/src/meter.lua +++ b/src/meter.lua @@ -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 diff --git a/src/ui.lua b/src/ui.lua index 2caf1b5..073a636 100644 --- a/src/ui.lua +++ b/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