#1 Members - Reputation: 346
Posted 20 August 2012 - 05:13 AM
I am wanting to make a pong clone to test my new knowledge with Java and slick. i haven't started anything yet but im planning it out. I am just a it confused on how you get the direction the ball goes after you hit it with the paddle. I don't know anything about physics (im taking it in school though). do i just randomly generate a direction or is there some stupid long mathematical equation thanks for any help.
"C spilled his beer all over C++'s shirt. Outraged, C++ shouted, "Good god, man! Have you no class?"
"Your mother is so fat that the recursive function that was used to calculate her mass created a stack overflow"
#2 Members - Reputation: 121
Posted 20 August 2012 - 05:28 AM
That doesn't sound good regardless of how much I spin it around in my head."stupid long mathematical equation"
Anyway, you could just go with some simple conditional statements and inverse the direction of the ball. If you want something more complex you'd have to do some vector maths with at least the ball's direction vector, the paddle's forward vector and the position the ball hit the paddle.
[source lang="cpp"] // edge of playing field if (pong.ball.centre_y > 0.6f) { pong.ball_velocity_y = -ball_speed; } else if (pong.ball.centre_y < -0.6f) { pong.ball_velocity_y = ball_speed; } // ball hit a paddle on the right side if (pong.ball_velocity_x > 0 && collides(&pong.ball, &pong.bats[1]) ) { pong.ball_velocity_x = -pong.ball_velocity_x; } // ball hit a paddle on the left side if (pong.ball_velocity_x < 0 && collides(&pong.ball, &pong.bats[0]) ) { pong.ball_velocity_x = -pong.ball_velocity_x; }[/source]
Edited by Tudor Nita, 20 August 2012 - 06:09 AM.
#3 Members - Reputation: 346
Posted 20 August 2012 - 05:41 AM
"C spilled his beer all over C++'s shirt. Outraged, C++ shouted, "Good god, man! Have you no class?"
"Your mother is so fat that the recursive function that was used to calculate her mass created a stack overflow"
#4 Crossbones+ - Reputation: 3558
Posted 20 August 2012 - 06:07 AM






