I'm having trouble getting collisions to work in breakout. I wrote my own code, which despite a lot of fixes didn't work, so I attempted to just copy-paste the bounce.c code in an effort to figure out what was wrong with mine. Bounce compiles and runs normally, but when I use the bounce code (with needed alterations) in breakout, the ball just goes out past the edge of the window (the velocity never reverses). I tried a printf statement to make sure the loop was running and it was, but the ball still doesn't bounce. Here's the relevant portion of the code;
ETA: Here is the entire while loop
velocity = abs(velocity);
and when it hits the right side,velocity = -abs(velocity);
(remember#include stdlib.h
) This should kill the infinite loop because it will always force the ball to go back into the window. It won't matter how fast the loops are running because the ball will only reverse direction once at each edge. If this doesn't give you a workaround, let us know what it does. Also, once you get all of the code for breakout finished, you may find that the current code may actually work, due to timing issues being altered by added code.