# How to improve collision detection memory usage?

I am making an action platform 2D game, something like Megaman. I am using XNA to make it.

I already made player physics, collisions, bullets, enemies and AIs, map editor, scrolling X Y camera (about 75% of game is finished ). As I progressed I noticed that my game would be more interesting to play if bullets would be destroyed on collision with regular(stationary) map blocks, only problem is that if I use my collision detection (each bullet with each block) sometimes it begins to lag(btw if my bullet exits the screen player can see it is removed from bullet list)

So how to improve my collision detection so that memory usage would be so high? :) ( on a map 300x300 blocks for example don't think that bigger map should be made);

            int block = 0;
int bulet= 0;
bool destroy_bullet = false;

while (bulet < bullets.Count)
{
while (block <  blocks.Count)
{
if (bullets[bulet].P_Bul_rec.Intersects( blocks[block].rect))
{//bullets and block are Lists that holds objects of bullet and block classes
//P_Bul_rec just  bullet rectangle

destroy_bullet = true;
}
block++;
}
if (destroy_bullet)
{ bullets.RemoveAt(bulet); destroy_bullet = false; }
else { bulet++; }
block = 0;
}

• A CD check between the bullet and a tile should be O(1). If you can convert from screen position to tile location usually Tile[x / tileWidth + (y / tileHeight) * mapWidth] you can completely remove the inner while block. – ClassicThunder Mar 19 '12 at 23:17
• Alternately, when you move the bullet, raycast from its current location to the final location, and you won't have fast bullets teleporting through blocks. – AndrewS Jul 29 '14 at 22:26