When implementing breakout, i am having a hard time trying to figure out how to check if the ball hits the horizontal edges of the paddle. So far everything else works fine, but when the ball touches the paddle edges, the ball goes crazy. I know the problem has to do with how i set up the velocity, but i am unsure how to check this case. Please help?
Below is a snippet of my code.
//move ball in horizontal direction move(ball, 5*horizontalVelocity, verticalVelocity);
//detect collision
GObject object = detectCollision(window, ball);
//check if ball hits paddle or bricks
if(object != NULL){
if(strcmp(getType(object), "GRect") == 0){
if(object == paddle){
verticalVelocity = -verticalVelocity;
//if ball hits bricks
}else{
verticalVelocity = -verticalVelocity;
}
}
}
if
condition does not make sense - you do the same in both cases.