Public Group

# nee help finging simple pong solution

This topic is 4824 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 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 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 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

1. 1
Rutin
26
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633312
• Total Posts
3011309
• ### Who's Online (See full list)

There are no registered users currently online

×