You see, when developing a mini-game of sorts, I decided to have the number of enemies be randomized, each spawning into a table, and being subsequently removed when the enemy comes in contact with a "bullet". However, the collision function that's supposed to remove the table ends up removing 2 enemies when 3-4 enemies are on screen, 3 enemies when 6 are on screen, etc. i've racked my brain with this one, and making the table check "backwards" isn't working. Maybe y'all can help.
Here's the enemy removal function:
Code: Select all
function bullet_ene_coll(obj, ta)
remE = {}
for i,v in ipairs(p1.shots) do
for ii,vv in ipairs(ta) do
if coll(v.x, v.y, shots.w, shots.h, obj.x, obj.y, obj.w, obj.h) then
table.insert(remE, ii)
table.remove(p1.shots, i)
shots.on = false
shots.dir = "nil"
end
end
end
for i,v in ipairs(remE) do
table.remove(ta, v)
end
end
Code: Select all
function dun:update(dt)
UPDATE_PL(dt)
skin.update(dt)
for i, v in ipairs(new_e) do
new_e[i]:update(dt) --"new_e" is the table that holds all the randomized enemies
bullet_ene_coll(new_e[i], new_e)
end
end