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 ede83a6..fb3ce13 100644 Binary files a/src/images/kani.png and b/src/images/kani.png differ 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()