improve Collision detection memory usage (blocks with bullets)

Posted by Eddy on Game Development See other posts from Game Development or by Eddy
Published on 2012-03-19T21:03:37Z Indexed on 2012/03/19 23:39 UTC
Read the original article Hit count: 304

i am making a action platform 2D game, something like Megaman. I am using XNA to make it. already made player phisics,collisions, bullets, enemies and AIs, map editor, scorolling 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;
            }

© Game Development or respective owner

Related posts about XNA

Related posts about 2d