Sign in to follow this  
kingpinzs

nee help finging simple pong solution

Recommended Posts

I can bounce the ball off the walls is easy. I am just trying to figure out how to bounce the ball off of the paddle. any one have a tut I can read about how to do this?

Share this post


Link to post
Share on other sites
How do you do collision detection with the walls?

Just do the exact same except with the coordinates for the paddles, then bounce off the same way, except in different directions.

Share this post


Link to post
Share on other sites
Presumably you've got a set position on the x co-ordinate for your paddle, that is to say your paddle can only move up and down.

What you could do is something like this (pseudocode):

1) Keep checking to see if the ball's x position is within the range of the paddle's width.

2) If it is, check to see if it's within the paddle's current height co-ordinates.

3) If not, the ball continues on its old path.

4) If it matches both those criteria, the ball must be reflected and sent in the opposite direction.

You could alter step 4 to set an angle at which the ball bounces off at, depending on its position on the paddle when the collision occurs. If you've got any further questions, I'd be happy to help.

Good luck, hope I've helped!

ukdeveloper.

Share this post


Link to post
Share on other sites
I know what you mean, it is very easy to do collision tests with sides of the screen but slightly more complicated with graphics objects. This function should help.


bool Collision(RECT* rect1, RECT* rect2)
{
if(rect1->left < rect2->right && rect1->right > rect2->left)
if(rect1->top < rect2->bottom && rect1->bottom > rect->top)
return true;
return false;
}



Share this post


Link to post
Share on other sites
One of my issues is finding the left rect of the paddle
is it the (x + (y+width)) or is it something else?

And also ukdeveloper how do I set an angle at which the ball bounces off at?

I can reverse the direction but I want it so if the paddle is in a upwered motion the ball will go that direction

Thanks for the help so far it help me understand a little more

Share this post


Link to post
Share on other sites

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

Sign in to follow this