This is collision detection with paddle (bottom right and left ) But the ball passes through the paddle and it is velocity does not change.
my questions are
Is this the right implementation of collision detection with paddle ?
Where should i call collision detection function ?
GObject detectCollision(GWindow window, GOval ball)
{
// ball's location
double x = getX(ball);
double y = getY(ball);
// initial velocity
double x_velocity = 1;
double y_velocity = 1.5 ;
// for checking for collisions
GObject object;
// check for collision at ball's bottom-left corner
object = getGObjectAt(window, x, y + 2 * RADIUS);
if (object != NULL)
{
if (strcmp(getType(object), "GRect") == 0)
{
y_velocity = -y_velocity ;
}
return object;
}
// check for collision at ball's bottom-right corner
object = getGObjectAt(window, x + 2 * RADIUS, y + 2 * RADIUS);
if (object != NULL)
{
if (strcmp(getType(object), "GRect") == 0)
{
y_velocity = -y_velocity ;
}
return object;
}
// no collision
return NULL;
}