(Solved) Enemy removal code is not working as intended
Posted: Wed Jan 09, 2013 1:48 am
For anyone else that might have problems, I simply added a new value to my table named removeEnemy and set it to false.
If a collision is detected, I think set this value to true.
Then in my enemy update loop I check this variable. If it is true, I remove it from the table. If it is false, I run the missile update.
Any help would be appreciated. My problem is that my enemies are not moving as intended. Basically, this is a missile command type of game. You fire a missile, it explodes and takes any incoming missiles with it. In my case, the collision detection is working, but not all of the incoming missiles get removed. If only one missile is hit, it works. If multiple collisions occur, it remove n-1 incoming missiles. So, if I collide with 4 incoming missiles, 3 will be removed. I know the collision detection is working because it will score for 4. Relevant code is below, I am attaching the .love file.
If a collision is detected, I think set this value to true.
Then in my enemy update loop I check this variable. If it is true, I remove it from the table. If it is false, I run the missile update.
Any help would be appreciated. My problem is that my enemies are not moving as intended. Basically, this is a missile command type of game. You fire a missile, it explodes and takes any incoming missiles with it. In my case, the collision detection is working, but not all of the incoming missiles get removed. If only one missile is hit, it works. If multiple collisions occur, it remove n-1 incoming missiles. So, if I collide with 4 incoming missiles, 3 will be removed. I know the collision detection is working because it will score for 4. Relevant code is below, I am attaching the .love file.
Code: Select all
--update our bullets
for i,v in ipairs(player.bullets) do
bulletUpdate(dt, v)
local okToRemove = bulletUpdate(dt, v)
if okToRemove == true then
table.insert(bulletsToRemove, i)
bulletExplosionX = v.x - halfFrameSize
bulletExplosionY = v.y - halfFrameSize
bulletShowExplosion = true
for ii, vv in ipairs(missileAttacks) do
if CheckCollision(bulletExplosionX, bulletExplosionY, explosionFrameSize, explosionFrameSize, vv.x, vv.y, vv.image:getWidth(), vv.image:getHeight()) then
--okToRemove = true
table.insert(attacksToRemove, ii)
--Score!
player.score = player.score + 100
--explosionX = vv.x - vv.image:getWidth()
--explosionY = vv.y - vv.image:getHeight()
--showExplosion = true
end
end
--remove our missiles that collided with bullets
for i,v in ipairs(attacksToRemove) do
table.remove(missileAttacks, v)
end
end
end