feat: add cooldown for weapons

This commit is contained in:
Kazhnuz 2021-11-27 13:20:14 +01:00
parent 516ed301bd
commit 5754d93cc5

View file

@ -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