Got my collision detection working!
Now all I have left to do is centralize the rendering process and take the draw functions out of the ball and paddle classes!
Code:
void Logic::check_collision()
{
if(ball->getVelocity().x > 0)
{
if (collision2d(ball->getMinimum(), ball->getMaximum(), player2->paddle->getMinimum(), player2->paddle->getMaximum()))
{
reverse_x_velocity(ball->getVelocity());
}
else if(planeCollision2d(right, ball->getLocation()))
{
reverse_x_velocity(ball->getVelocity());
ball->getLocation().x = 0;
ball->getLocation().y = 0;
player1->goal();
}
}
if(ball->getVelocity().x < 0)
{
if (collision2d(ball->getMinimum(), ball->getMaximum(), player1->paddle->getMinimum(), player1->paddle->getMaximum()))
{
reverse_x_velocity(ball->getVelocity());
}
else if(planeCollision2d(left, ball->getLocation()))
{
reverse_x_velocity(ball->getVelocity());
ball->getLocation().x = 0;
ball->getLocation().y = 0;
player2->goal();
}
}
if(ball->getVelocity().y > 0)
{
if (planeCollision2d(top, ball->getLocation()))
{
reverse_y_velocity(ball->getVelocity());
}
}
if(ball->getVelocity().y < 0)
{
if (planeCollision2d(bottom, ball->getLocation()))
{
reverse_y_velocity(ball->getVelocity());
}
}
}