feat: add cooldown for weapons
This commit is contained in:
parent
516ed301bd
commit
5754d93cc5
1 changed files with 14 additions and 3 deletions
|
@ -5,6 +5,13 @@ local weaponList = require("datas.gamedata.weapons")
|
||||||
function WeaponManager:new(player)
|
function WeaponManager:new(player)
|
||||||
self.player = player
|
self.player = player
|
||||||
self:switch(1)
|
self:switch(1)
|
||||||
|
self.cooldown = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
function WeaponManager:update(dt)
|
||||||
|
if (self.cooldown > 0) then
|
||||||
|
self.cooldown = self.cooldown - dt
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function WeaponManager:switch(newWeapon)
|
function WeaponManager:switch(newWeapon)
|
||||||
|
@ -15,11 +22,15 @@ function WeaponManager:switch(newWeapon)
|
||||||
end
|
end
|
||||||
|
|
||||||
function WeaponManager:shoot(x, y, z, dir)
|
function WeaponManager:shoot(x, y, z, dir)
|
||||||
|
if (self.cooldown <= 0) then
|
||||||
local weaponData = weaponList[self.currentWeapon]
|
local weaponData = weaponList[self.currentWeapon]
|
||||||
|
|
||||||
for i,coord in ipairs(weaponData.launch) do
|
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.player.obj.Weapon(self.player.world, x + coord[1], y + coord[2], z + coord[3], dir, weaponData, self.player)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self.cooldown = 0.3
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return WeaponManager
|
return WeaponManager
|
||||||
|
|
Loading…
Reference in a new issue