nee help finging simple pong solution
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?
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.
Just do the exact same except with the coordinates for the paddles, then bounce off the same way, except in different directions.
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.
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.
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;}
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement