From 5d1c36ea2fd83367d12cd09aabec0e5ea03ae7cb Mon Sep 17 00:00:00 2001 From: annabunches Date: Fri, 29 Sep 2023 22:07:02 -0400 Subject: [PATCH] Improve firing code. --- src/bullet.lua | 2 +- src/images/kani.png | Bin 659 -> 4601 bytes src/kani.lua | 33 ++++++++++++++++++++++----------- src/main.lua | 1 + 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/bullet.lua b/src/bullet.lua index 3fcd6a1..88184fb 100644 --- a/src/bullet.lua +++ b/src/bullet.lua @@ -10,7 +10,7 @@ class("Bullet").extends(gfx.sprite) function Bullet:init(size, friendly) local img = gfx.image.new(size, size) gfx.pushContext(img) - gfx.drawCircleInRect(0, 0, size, size) + gfx.fillCircleInRect(0, 0, size, size) gfx.popContext() Bullet.super.init(self, img) diff --git a/src/images/kani.png b/src/images/kani.png index ede83a67e45bd58583c30cf3285b8a398f9d4a84..fb3ce138f93e403d1509df9ea23170dcd3ca6ec6 100644 GIT binary patch literal 4601 zcmeHKYj6|S6<&v?c2sPjWkQ*Nt|K=xb&{%=QJ}N z&xC*0%xd?Zd(L;x`R;e`?5?&i%8pmfR3QiwZ_Tmf!TU^jp>f}V|4rL}w-(-dD;-60 z9veafLD4060V-Dn01Co_3qiu?*F1f0&7@hA2X@wMx>Sm6ZckqS#}~2m+Cx0GzHrGx z)ABEtuUq@~26v^r{>hG4^O~>aPL(9V{$zadVt#Mp%O})_Lsc6--}qkRfwH=JlVa~3 zH+pN;roJamWY2E8qH1~L=#B2S?`}IKZjYN&+u8Eri)h~JwcfMO%A5Z3>IKi;tkAAA zB(`Dm(GOOpIu?{)FZf7x>tKHtNOIgf(ZrqC798K0+_~VXf~2L((%+2VKPl7vZ_Ddt zJ0AKv_k%gN7qlSH|LFa$eo=Sl;<0@@(l4iTjWa&_aoK;ao>xsnkeC!9Bg1aZ$QbGy zcKh1ab>@Zb_USJ*WPS0ytzFNv9ZnJOM%A|uC?AgI3roVI+v`9OU0x%Y5H>ypZV+`Nk@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yxMHEW|^P+ zRclVw9F5@p5!O6de}yQHtC@ek@e5)VP@%_qu$+^r5H1KE76>egTvdRR z-w-H&&`Cr=R7l62RY?-VFbG3T{{Ln5(3!@7+3F)PAc5pS=7%C80vp6KeU!uFa*VmJ zI_{qI)pa^%1vu%R6@b8$h@}||&<$t29XQAc6l}RKp@Wtluyf!Z8*->DvC?3{ZHO2s zvDpI3iP84IU1u|L3Qj6mq+c7VY!3eOLV0#(1=trrOTl>o^NkxR(Mx%@hj)EHMd(V( zZTNK=Q`b5QPh#i14G%#F|Kq}!A#QFye@eO(63d6wJt*4F95o&tT8J4r9lMY#dCY&V dSbNcBd;nvbKr>p?;xPaK002ovPDHLkV1lJn3K9SS diff --git a/src/kani.lua b/src/kani.lua index 208c9fc..b1b1917 100644 --- a/src/kani.lua +++ b/src/kani.lua @@ -2,10 +2,16 @@ import "CoreLibs/object" import "CoreLibs/graphics" import "CoreLibs/sprites" +import "CoreLibs/timer" import "bullet" local gfx = playdate.graphics +-- the amount of charge needed to increase the shot size by 1 +local SHOT_INCREMENT = 10 +-- maximum value the reserve charge can reach +local MAX_CHARGE = 100 + class("Kani").extends(gfx.sprite) function Kani:init() @@ -17,8 +23,9 @@ function Kani:init() self:setGroupMask(0x2) self:setCollidesWithGroupsMask(0x19) - self.reserveCharge = 0 + self.reserveCharge = 100 self.shotCharge = 0 + self.firingMode = false -- input handlers self.inputHandlers = { @@ -31,31 +38,35 @@ function Kani:init() leftButtonUp = function() self.vector.x = 0 end, rightButtonUp = function() self.vector.x = 0 end, cranked = function(change, accelChange) self:chargeReserve(change) end, - AButtonDown = function() self:chargeShot(1) end, + AButtonDown = function() + self.firingTimer = playdate.timer.keyRepeatTimerWithDelay(0, 500, self.chargeShot, self) + end, AButtonUp = function() self:fire() end, } end function Kani:chargeReserve(change) - self.reserveCharge += change / 10 + self.reserveCharge = math.min(self.reserveCharge + change / 15, 100) + print("Reserve charge at " .. self.reserveCharge) end -function Kani:chargeShot(amount) - if self.reserveCharge > amount then - self.shotCharge += amount - self.reserveCharge -= amount - elseif self.reserveCharge > 0 then - self.shotCharge += self.reserveCharge - self.reserveCharge = 0 +function Kani:chargeShot() + if self.reserveCharge > SHOT_INCREMENT then + self.shotCharge += 1 + self.reserveCharge -= SHOT_INCREMENT + print("Shot charged to size " .. self.shotCharge) end end function Kani:fire() + self.firingTimer:remove() + if self.shotCharge <= 0 then return end - local bullet = Bullet(self.shotCharge) + print("Creating bullet of size " .. self.shotCharge) + local bullet = Bullet(self.shotCharge * 2) bullet:moveTo(self.x+16, self.y) bullet:add() self.shotCharge = 0 diff --git a/src/main.lua b/src/main.lua index 4fd47ea..d83f738 100644 --- a/src/main.lua +++ b/src/main.lua @@ -49,6 +49,7 @@ end function playdate.update() gfx.sprite.update() + playdate.timer.updateTimers() end setup()