diff options
| author | Eltrac <hi@guhub.cn> | 2025-03-16 15:10:30 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-03-16 15:10:30 +0800 |
| commit | dfdb1023f6513014fc0f955142d2667d7bda80c9 (patch) | |
| tree | cecb9113f5da747ffe3398701a1dd089bc4697ee /objects | |
| parent | d6a4ca82a3874f2fca58ea7948185d697acf078a (diff) | |
feat(controller): easier bullet management
old approach: press number keys to put specific heart to the end of the line
new approach: press Q or E to move the next bullet index
Diffstat (limited to 'objects')
| -rw-r--r-- | objects/Player.lua | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/objects/Player.lua b/objects/Player.lua index aabc9e2..89b1b54 100644 --- a/objects/Player.lua +++ b/objects/Player.lua @@ -19,11 +19,13 @@ function Player.new() hearts = { "purpleheart", "redheart", "redheart", "redheart", "shinyheart", "shinyheart", "stickyheart" }, facing = Direction.DOWN, moving = false, - frameTimer = FrameTimer:new(config.frameRate, 2) + frameTimer = FrameTimer:new(config.frameRate, 2), }, Player) physics.bodifyObject(G.world, player) + player.nextBullet = #player.hearts + return player end @@ -68,7 +70,7 @@ end function Player:shoot(target) local hearts = self.hearts - local currentBullet = hearts[#hearts] + local currentBullet = hearts[self.nextBullet] -- red hearts and the last heart will take some more time to shoot if currentBullet == "redheart" or #hearts == 1 then @@ -89,7 +91,8 @@ function Player:shoot(target) -- shoot the bullet bullets.fire(currentBullet, target, self) - table.remove(self.hearts) + table.remove(self.hearts, self.nextBullet) + self.nextBullet = self.nextBullet - 1 self.shootCooldown = G.time + config.player.shoot.cooldown end |
