Ok, today I finally got time to continue working on my project.
I created a bool to check for collisions:
bool Collision(const float& TempPositionY1, const float& TempPositionY2, const float& TempPositionX1, const float& TempPositionX2)
{
int distance = ((TempPositionX1 - TempPositionX2) * (TempPositionX1 - TempPositionX2)) + ((TempPositionY1 - TempPositionY2) * (TempPositionY1 - TempPositionY2));
if (distance < ballradius + ballradius )
{
return true;
}
else return false;
}
Okay, I think this should work.
But now I have to create a loop to check all possible combinations of Collisions.
I created something like that first:
for (int i = 0; i < ballcount; i++)
{
for (int j = i + 1; j < ballcount; j++)
{
if (Collision(Ball[i].getPosition().y, Ball[j].getPosition().y, Ball[i].getPosition().x, Ball[j].getPosition().x))
{
// Calculate new direction
}
}
}
But that doesnt detect all the collisions, for example Ball[4] and Ball[8].
So my question is:
How can I effectively cover all the possible Collisions in my loop?