0
\$\begingroup\$

I have made a game that runs poorly. I suspect that the way that I programmed the collision detection in the game loop could be the problem.

My game has two player-controlled tanks which fire missiles; there are also power-ups, "gifts", that tanks can collect from the field. At every iteration of my game loop, I detect collisions like this:

  1. Loop through all the missiles on the screen, and update their location (move them).
  2. Loop through all of tank 1's missiles, and for every one check if collides with tank 2.
  3. Loop through all of tank 2's missiles, and for every one check if collide with tank 1.
  4. Loop through all the missiles on the screen, and check if collide with screen boundaries.
  5. Check if the two tanks collide with each other.
  6. Loop through all of the four "gifts" on the screen, and check if they touch a tank.

This method is presumably inefficient. How can I implement collision detection for all of these objects in a better fashion?

\$\endgroup\$
  • \$\begingroup\$ I have edited your question to reduce it in scope (it was previously too broad); please see the help center for information about asking questions here. Do note that while I made the question focus on the collision detection aspect of your game loop, because that seems to be the most-likely culprit, you should really profile your game to be sure. \$\endgroup\$ – user1430 Jan 25 '14 at 2:07
  • \$\begingroup\$ @JoshPetrie Thanks for editing, the question does look clearer now. Any chance you could help me with profiling tutorials? I searched Google but I'm a beginner to this and found nothing that was basic enough for me to start with. I asked for help on this here: stackoverflow.com/questions/21345660/… \$\endgroup\$ – user3150201 Jan 25 '14 at 2:11
  • \$\begingroup\$ That would be a separate topic (and off-topic here; more suited to StackOverflow, where you have asked it). You could also ask in the Game Development Chat. You can get started with a very basic profiling system by simply using timer objects directly in your code to track the elapsed time around certain functions. \$\endgroup\$ – user1430 Jan 25 '14 at 2:13