miko wrote:So it was real 2-D problem, which can not (easily) be "linearized", like your case (in which there are no interactions between mobs and ents elements).
for i=math.max(#mobs, #ents), 1, -1 do
local m,isDead = mobs[i]
for i=#ents, 1, -1 do
local e = ents[i]
if whateverItIsYoureDoing then
isDead = true
table.remove(ents, i)
end
end
if isDead then table.remove(mobs, i) end
end
The same basic method I presented still applies.
Not in this case - you have somewhat complicated the code, but still did not solve the problem Note that your magical whateverItIsYoureDoing() function could remove elements from mobs and/or ents table at the index lower than the current value of i, which would break your iteration.
Just remember that you need to check collisions between PlayerBullets[1] and Enemies[N], and also between PlayerBullets[M] and Enemies[1] (and every combination in between).
Well, Don't Do That! The whateverItIsYoureDoing function represents checking collision or whatever to see if a pair of things need to be removed. That you can stick arbitrary code designed to mess up the example into a placeholder is a given.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit! Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Taehl wrote:Well, Don't Do That! The whateverItIsYoureDoing function represents checking collision or whatever to see if a pair of things need to be removed. That you can stick arbitrary code designed to mess up the example into a placeholder is a given.
And that was my point. The original code was "designed" just to "mess up", or in other words - you cannot easily do the same logic in one pass with one loop. Or if you can - just try to write it.
I /do/ write it like that. As I said, that's my normal method.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit! Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.