4

detectCollision assumes that the width of your ball is RADIUS*2. You have initialized your ball with a width of RADIUS. So detectCollision will return a collision before the ball hits the paddle.


2

Solved! Defining the velocity outside of the while loop, instead of inside, has fixed the problem. When it was inside the loop, the velocity was reset to a positive number every time the while loop was run, so the ball could never go backwards.


1

I think you may need a separate velocity variable for each dimension (e.g., Vx and Vy). I think this will clear up the angle problem.


1

It's not too bad on the math side. In summary, you just reverse the values of the x and y velocity when it contacts the object. For instance, if the ball hits the right edge of the window. the x-velocity variable (controlling up and down motion) would remain unchanged while the y-velocity variable would be reversed; //if collision between ball and right ...


1

One thing that had me for a bit was my functions for instantiating the paddle and the ball. since we have to program movement inside of main we want ball and paddle exist inside of that function. make sure your initPaddle and initBall RETURN paddle and ball respectively. That might help with some of the issues you are having with movement.


1

Try to change the == in the object detection section with either >= or <=


1

Add the following line before your #include statements: #define _XOPEN_SOURCE


Only top voted, non community-wiki answers of a minimum length are eligible