# questions about arrays basic collision detection

• 07-23-2008
The_Hermit
questions about arrays basic collision detection
So, I'm writing this side scrolling rpg (think link to the past or secret of mana), and I'm at a point where I need collision detection.

I've got this idea to hand code the bounding boxes for solid objects into arrays, and use a for loop to check for collisions; something like this:

Code:

```int object_max_x[A_BAJILLION] int object_max_y[A_BAJILLION] int object_min_x[A_BAJILLION] int object_min_y[A_BAJILLION] // a bajillion being a #define for the number of solid objects in a given map. int character_max_x int character_max_y int character_min_x int character_min_y int collision_detection() { for (a=0; a<A_BAJILLION; a++)  {   if (character_max_x>object_min_x[a]     return 1;   if (character_max_y>object_min_y[a]     return 1;   if (character_min_x<object_max_x[a]     return 1;   if (character_min_y<object_max_x[a]     return 1;  } return 0: }```
but I'm worried about the size of those arrays. Is it efficient to have a for loop run through every possible collision during every frame? I'm not quite sure, but I'd like to find out before writing that much potentially 'bad' code. Thanks for any insight you're willing to offer.
• 07-23-2008
Salem
Assuming that your objects don't hyperspace to random positions each time they move, then things which were close by on the last iteration are the ones most likely to collide on this iteration.

Use this to your advantage when trying to figure out what to compare.
• 07-23-2008
The_Hermit
Thanks, man. That makes sense.

lol, god of the C