Jump to content
Sign in to follow this  
  • entries
  • comments
  • views

Birds Flew Backwards

Sign in to follow this  


So I haven't managed to finish Two Player Pong today but I did manage to get scores working, a regulated frame rate and producing a new ball when the old one goes out of play (now that I've listed what I've done it doesn't sound like a lot [lol]).

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 one
if (ball_top < player_one_bottom &&
ball_bottom > player_one_top &&
ball_right > player_one_left &&
ball_left < player_one_right)
// Reverse the x velocity

// Check if the ball hit player two
if (ball_top < player_two_bottom &&
ball_bottom > player_two_top &&
ball_right > player_two_left &&
ball_left < player_two_right)
// Reverse the x velocity

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.

Sign in to follow this  


Recommended Comments

Is it possible that after you reverse the velocity, the ball is still "inside" the bat, so next frame it gets its X velocity reversed again, and so on and so on?

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).


Share this comment

Link to comment
Yes I found that (after changing its colour) the ball seemed to be bouncing inside the paddle. Thanks for the suggestions, I will try them out tomorrow.

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!