I used the code given in the set
GObject object = detectCollision(window, ball);
if(object !=NULL)
{
if(object== paddle)
{
y_velocity=-y_velocity
}
}
else if (strcmp(getType(object), "GRect") == 0) { removeGWindow(window, object); y_velocity = -y_velocity; } }
after that I check to see if it is bouncing off the sides...
This is all within the while loop, but when I run the breakout.c, the ball doesn't bounce / deflect until it reaches the bottom of the window. :(
Oddly enough, the code to detect for GRects (if(strcmp(getType(object), “GRect”)==0))
does bounce off the bricks at the top. I got rid of the (object==paddle)
part of the code and only checked for GRect
s (and made the y-velocity change), but the ball still didn't deflect from the paddle, even though it still did for the bricks?? It’s like the code doesn't know that the paddle is an GObject
/ GRect
?
Any suggestions??
Thanks!
initPaddle
? 'cause it seems likepaddle
(inmain
) doesn't hold the correct value.