Hello guys, the answer to my question might be obvious to you, but i have some doubts about the right way I should detect collisions in my program.
So far, I've created three classes: Player, Projectile and Mob.
I move Player object and shoot with Projectile objects,putting them into std::vector projectilesvector. Mobs spawn randomly and they are saved in std::vector mobsvector. In every game loop I check all Projectiles object's and Mob's objects, if they intersect:
for( int i = 0; i < projectilesvector.size(); i++ )
{
for( int j = 0; j < mobsvector.size(); j++ )
{
// if ( projectilesvector[i] intersects mobsvector[j] ) collision detected
}
}
For example, with 500 projectiles and 100 mobs I have to make it through 50000 loops, which takes substantial amount of time.
I wonder if there is a faster way to check collisions, without nested loops.