PDA

Click to See Complete Forum and Search --> : pong physics


MidgetsBro
May 15th, 2001, 11:15 AM
How can I make the ball bounce in pong? I want to be able to bounce the ball of the wall and have it go in the relative direction. It's no fun when the ball bounces straight back and forth...

Thanx for any help.

Fox
May 15th, 2001, 01:36 PM
Here's a little demo I just made to teach someone a bit programming...

Have fun

MidgetsBro
May 15th, 2001, 02:48 PM
Thanks. That's pretty cool, but it's not really what I need, unless I can figure out how to change the code to make the code automatic. I need the ball to bounce around without having to press buttons. You should know what I'm talking about, everyone has played pong before...

Fox
May 15th, 2001, 03:28 PM
mmm... I thought this would not be a problem and you just need the code for collision or movement erm..

Well you can simply set the speed variables to a value each time

Sastraxi
May 15th, 2001, 03:34 PM
When it collides with the right/left wall, use this:

XSpeed = -XSpeed 'where xspeed is the movement of the ball on the x-axis in pixels, in game seconds


And when it hits the top/bottom wall...

YSpeed = -YSpeed 'where yspeed is the movement of the ball on the y-axis in pixels, in game seconds

/\/\isanThr0p
May 18th, 2001, 10:23 AM
If I understand you right you really want to know the basics
so what you need to do for the ball to move automatically is increase the X and Y of the ball by Xspeed and Yspeed. Sastraxi described how to change the X- and Y-speed on collision with the walls.
But that still would not make the ball move in different angles. So what you should do is if the ball hits the paddle further at the left you should decrease the xspeed value and if you hit it further on the right increase the xspeed value.
I hope this was kind of understandable.

Just ask if there are more questions. ( I can look for some old Pong games I wrote long time ago)

MidgetsBro
May 18th, 2001, 02:31 PM
I finished my pong game, but I didn't do it the way your mentioned. I'll upload it to ths post.