[SOLVED] Attack system based on DT
Posted: Thu Oct 19, 2023 5:21 am
Hello everyone!
I'm working on my first small game and I need some help from the community.
Here's the deal, I need to implement an enemy attack system with support for attack speed.
At the moment it looks like this:
It is a bit junky and doesn't do what i need.
What do i need exactly:
Some system that will allow me automatically execute attack on player. E.g. First enemy will attack twice in a sec. and second enemy will attack once in a sec.
Full code of the game - GitHub
Any help would be appreciated, thanks!
I'm working on my first small game and I need some help from the community.
Here's the deal, I need to implement an enemy attack system with support for attack speed.
At the moment it looks like this:
Code: Select all
CurrentDelta = 0
function EnemiesAttack(object)
local sumOfDamage = 0
if GetItemsCount(Enemies) ~= 0 then
for enemyIndex, enemy in pairs(Enemies) do
sumOfDamage = sumOfDamage + enemy:getDamage()
end
object.health = object.health - sumOfDamage
end
end
function love.update(dt)
CurrentDelta = math.ceil(CurrentDelta + (dt * 100))
if CurrentDelta % 100 == 1 then
EnemiesAttack(Player)
end
end
What do i need exactly:
Some system that will allow me automatically execute attack on player. E.g. First enemy will attack twice in a sec. and second enemy will attack once in a sec.
Full code of the game - GitHub
Any help would be appreciated, thanks!