1. ## Bouncing Ball Algorithm

I've been playing around with WriteConsoleOutput() and other CHAR_INFO, SMALL_RECT stuff, and I soon want to be making a Pong clone. I try to make a ball bounce diagnally, but when it gets to the top it messes up. I don't care about my code, or fixing it, especially since it's just a driver program. But does anyone have a good ball algorithm(sp?)

2. I wrote a couple of bouncing ball/paddle apps a little while ago.
They should still be available here.

3. Have you tried looking at the code in my game?

4. The best ball bouncing system that I've found goes like this:
Code:
```struct ballt {
}ball;

//in main...
ball.x = (rand() % (SCREEN_W - ball.radius * 4)) + ball.radius * 2;
ball.y = (rand() % (SCREEN_H - ball.radius * 4)) + ball.radius * 2;
ball.dx = rand() % 2 * 2 - 1; //-1 or 1
ball.dy = rand() % 2 * 2 - 1;

void move_ball() {
ball.x += ball.dx;
ball.y += ball.dy;
ball.dy *= -1;
ball.dx *= -1;
}```
yeah? worked for me

5. Bouncing Ball Algorithm
I would expect a really good bouncing ball algorithm to use a quadratic equation

6. The appeal of this system is collision with the paddle:
Code:
```if (ball.x <= paddle.width && ball.y >= paddle.y
ball.dx *= -1;
}```
see? easy.

7. ## Sorry...

I would expect a really good bouncing ball algorithm to use a quadratic equation
struct ballt {

Sorry, this is my fault. You see, I'm making a simple ball test. My "ball" is really a char(219) and I just want it to bounce diagnally. Think of pong, with no paddles. I just couldn't do that. Does anyone have an algorithm (am I spelling that right?) for a simple char(219) bouncing "ball".

8. Well I'm not going to continue to say too much because I really think this is something you can figure out on your own. I am just going to say that when things bounce, they don't just go at 90 degrees (sometimes it will, it depends on what angle it forms with the surface you are colliding against).

EDIT: if you don't get what I just said, I'll draw a picture, but only if you care enough to ask.

9. things bounce off of a wall at the same angle that they collided...so to confuse you, the vector for the ball's approach to the wall mirrored over the wall's normal is the vector of the direction it will leave (pointed the wrong direction, but that's okay)

Code:
```\    /
a\  /b
__\/___```
angle a= angle b

10. unless, of course, there is some english on the ball

11. Here's an example of what happens when I try:
EDIT: My beutiful Ascii art did not come out right

If it is going up and right, and hits the north part of the screen, it should go down and right (in the most simple case). Well mine hits the top and come back going left and down

12. Originally posted by Stan100
Here's an example of what happens when I try:
EDIT: My beutiful Ascii art did not come out right

If it is going up and right, and hits the north part of the screen, it should go down and right (in the most simple case). Well mine hits the top and come back going left and down
if this is 2D ( i assume it is)

you are reflecting both the y and x. that is why it comes back left and down. in general, if it hits the top or bottom, just reflect the y, if it hits the left or right, just reflect the x.

13. I would expect a really good bouncing ball algorithm to use a quadratic equation
Wouldn't an absolute value equation serve better for this use than a quadratic equation?