Unfortunately, I have a bug which occurs when one of the paddles 'lands' on the ball, if you see what I mean. I think its got something to do with me not reversing the y velocity but I don't know where to put it.Can anybody help? I'll also have a think for myself at work. Here's the code:
// Check if the ball hits player oneif (ball_top < player_one_bottom && ball_bottom > player_one_top && ball_right > player_one_left && ball_left < player_one_right){ // Reverse the x velocity ball->ReverseVelX();}// Check if the ball hit player twoif (ball_top < player_two_bottom && ball_bottom > player_two_top && ball_right > player_two_left && ball_left < player_two_right){ // Reverse the x velocity ball->ReverseVelX();}
Anyway, I have a few days off work from tomorrow which should give me plenty of time to finish Two Player Pong and get started on my Breakout clone.
-AEdmonds
If player 1 is always on the left and player 2 on the right, I'd try setting the ball X velocity to +1 for player 1 collisions and -1 for player 2 collisions explicitly.
The alternative is, when you get a ball collision, to move the ball out of the bat at the point you detect the collision (e.g. for player 1, set ball_left to equal player_right+1 or whatever).
HTH