From 5754d93cc585ab96e3f78248ea91b25d9cf06d62 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 27 Nov 2021 13:20:14 +0100 Subject: [PATCH] feat: add cooldown for weapons --- .../subgames/world/actors/player/weapons.lua | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/sonic-bluestreak.love/game/modules/subgames/world/actors/player/weapons.lua b/sonic-bluestreak.love/game/modules/subgames/world/actors/player/weapons.lua index 7372826..0a0d007 100644 --- a/sonic-bluestreak.love/game/modules/subgames/world/actors/player/weapons.lua +++ b/sonic-bluestreak.love/game/modules/subgames/world/actors/player/weapons.lua @@ -5,6 +5,13 @@ local weaponList = require("datas.gamedata.weapons") function WeaponManager:new(player) self.player = player self:switch(1) + self.cooldown = 0 +end + +function WeaponManager:update(dt) + if (self.cooldown > 0) then + self.cooldown = self.cooldown - dt + end end function WeaponManager:switch(newWeapon) @@ -15,10 +22,14 @@ function WeaponManager:switch(newWeapon) end function WeaponManager:shoot(x, y, z, dir) - local weaponData = weaponList[self.currentWeapon] + if (self.cooldown <= 0) then + local weaponData = weaponList[self.currentWeapon] + + for i,coord in ipairs(weaponData.launch) do + self.player.obj.Weapon(self.player.world, x + coord[1], y + coord[2], z + coord[3], dir, weaponData, self.player) + end - for i,coord in ipairs(weaponData.launch) do - self.player.obj.Weapon(self.player.world, x + coord[1], y + coord[2], z + coord[3], dir, weaponData, self.player) + self.cooldown = 0.3 end end