Optimizing collision detection

This is really start to eat me. So, I`m making an arcade/shooter game, inspired by Asterax, if anyone still remembers the old Mac game. The game is level based and you have to shoot asteroids with your space ship. every next level increases the asteroid count by one, starting at 3, so at level 10 you would have 13 asteroids. Now, not minding the graphics rendering lag, i really feel like my code should be optimized, as at level 15 the cpu seems to be at full usage.

As it is now, I have a for… in loop on every shot and the ship, that checks the distance to every single asteroid on the field, every frame. I know, very bad programming. What I had in mind was putting a single loop on _root to check all objects for collision (checking the distance seems to be easier on the cpu then the flashs hitTest function), that would probably work better, but at level 30 it would prolly be the same.

Is there any other way?
Thanks in advance, Sigfa.

yea, testing the x distance first seems reasonable.

of course, all the asteroids are on an array, and when one is destroyed it gets spliced, otherwise the for …in loop would overload the cpu.

Ill think about that x distance first, although I dont think it will make much of an improvement.

When checking from the array, you start at the end of the array and work your way to the front. So you start at the end of the array, get x dist, hit check if needed. then if there is contact pop the element and delete the object. Then on the next cycle of the for loop you subtract on from the index you are checking and you loop will be unaffected by the removal of the element on the previous cycle.

It is highly unlikely, that four or more objects collide in the same frame, so your idea wont be much of an improvement, but Ill add it just for the heck of it. only one line of code anyway.