help with collision

on collision, the entire spawned enemies on the screen are removed instead of only one.
here is the code

[code]
bricks1 = {}

local n = 0

– the bullet animation goes here
local function throwBrick2()
n = n + 1

– goes here

bricks1[n] = display.newImage(“bomb.png”, plane.x + 10 , plane.y + 2)

physics.addBody( bricks1[n],{ density=0, friction= 0, bounce=0 } )

startListening()

– remove the “isBullet” setting below to see the brick pass through cans without colliding!
bricks1[n].isBullet = true

bricks1[n].angularVelocity =0
bricks1[n]:applyForce( 5000, 0, bricks1[n].x, bricks1[n].y )

end

here is the enemy

dudes22 = {}

local function makeDude3()
dude22 = display.newImageRect(“enemyblack13.png”, 200, 200)
dude22.xScale = .5
dude22.yscale = .1
dude22.x, dude22.y = math.random(500, 600), math.random(50, 280)
– change to 50 70
dudes22[#dudes22+1] = dude22

end

local function listener3(event)
for i, v in pairs(dudes22) do
n = n + 1
physics.addBody( dudes22[i], “kinematic” ,{density=10000, friction=0, bounce=0,radius= 35} )

if dudes22[i].x <1 then
dudes22[i]:removeSelf()
dudes22[i] = nil

else

local speed = 5
dudes22[i].x = dudes22[i].x - speed
– timer.performWithDelay( 500, throwBrick1, 1 )
– startListening()

end
end
end

timer.performWithDelay(1000, makeDude3, 500)

here is collision

function startListening()
– if egg1 has a postCollision property then we’ve already started listening
– so return immediately
for k, v in next, bricks1 do

if bricks1[k].postCollision then
return
end
end

local function onEggCollision ( self, event )

– uses “postSolve” event to get collision force

print( "force: " … event.force )

– Crack this egg if collision force is high enough
if ( event.force ==0 ) then
for k, v in next, dudes22 do
dudes22[k]:removeSelf()
– table.remove(dudes22[k],k)
dudes22[k] = nil
– After this egg cracks, it can ignore further collisions
–self:removeEventListener( “postCollision”, self )

end
return true

end
end

– Set table listeners in each egg to check for collisions
for k, v in next, dudes22 do
dudes22[k].postCollision = onEggCollision
dudes22[k]:addEventListener( “postCollision”, dudes22[k] )

end

end

hel [import]uid: 40990 topic_id: 7544 reply_id: 307544[/import]

This doesn’t belong in this area of the forum. This is “What’s New” - posting in an appropriate section will get you more help.

*Edit: moved thread to appropriate sub forum. [import]uid: 10144 topic_id: 7544 reply_id: 27188[/import]