From my beginner point of view, it's the same but maybe there are potencial bugs coming once the proyect moves forward so that's why i'm asking:
Code: Select all
for i, m in ipairs(monsters) do
for j, b in ipairs(bullets) do
if check_collision(b.x, b.y, b.width, b.height, m.x, m.y, m.width, m.height) then
table.remove(bullets, j)
m.hp = m.hp - b.damage
if m.hp == 0 then
table.remove(monsters, i)
end
end
end
end
Code: Select all
for i, m in ipairs(monsters) do
for j, b in ipairs(bullets) do
if check_collision(b.x, b.y, b.width, b.height, m.x, m.y, m.width, m.height) then
b.dead = true
m.hp = m.hp - b.damage
if m.hp == 0 then
m.dead = true
end
end
end
end
for i=#monsters,1,-1 do
local m = monsters[i]
if m.dead == true then
table.remove(monsters, i)
end
end
for i=#bullets, 1, -1 do
local b = bullets[i]
if b.dead == true then
table.remove(bullets, i)
end
end
Thanks in advance!