Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / A question about ping pong

Author
Message
sgalland
21
Years of Service
User Offline
Joined: 18th Nov 2002
Location: United States
Posted: 18th Nov 2002 07:50
Hello,

I was trying to make a ping pong game and I have a working model, like the ball can move and the paddle moves and stops at screen edges. The problem I have is how to work the ball physics - like how to I get the ball to move in a consistent direction, and how to get collision detection to deflect the ball, etc. Any help is appreciated!
Shadow Robert
21
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 18th Nov 2002 07:58
i'd recommend searching the internet about Vectors
they will be very helpful to you!

DBpro has them builtin ... so perhaps checkout how that uses them too - once you have Vectors down reproducing the physics require for rebound is simple Trig and speed will depend on Reaction Forces

Anata aru kowagaru no watashi!
sgalland
21
Years of Service
User Offline
Joined: 18th Nov 2002
Location: United States
Posted: 18th Nov 2002 07:58
Thanks man

Anonymous
21
Years of Service
User Offline
Joined: 25th Oct 2002
Location: Australia
Posted: 18th Nov 2002 08:14
If you are using Dark BASIC(Not Dark BASIC Pro, just Dark BASIC)theres a tutorial for collisions. At the Dark Basic site (www.darkbasic.com)in the "Create" secton. That might help your collision problems.

actarus
21
Years of Service
User Offline
Joined: 29th Aug 2002
Location: 32 Light Years away
Posted: 18th Nov 2002 15:53
Hey I was just thinking lately how PC's lack Ping pong games...and boxing too but that's another debate.

Looking forward to see that.

QuothTheRaven
21
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 19th Nov 2002 02:15
You know way back in the day when I was programming games like pong and tron on my calculator, that question came up too. I found the best way to keep the ball in a not so realistic yet working motion:
Ball position is A,B (it's a 2d field, overhead view)
It's movement per turn is C,D
In the loop the code is
A=A+C
B=B=D
So if you started out with c and d being 1, it would add 1 to the horizontal position and 1 to the vertical position of the ball in each loop. If it hit a wall on the left or right side, it would reverse C. So C=-C. If it hit a wall on the top or bottom it would reverse D. So D=-D.

So if it's moving up and right, both C and D are 1. If it hits the right wall, it reverse C so that it is moving up (D is still 1) but it is going LEFT because C is now -1. And A=A-1 will make the ball move left. Get what I'm saying?

It's a very effective, though not too realistic method, for keeping track of your balls.
sgalland
21
Years of Service
User Offline
Joined: 18th Nov 2002
Location: United States
Posted: 19th Nov 2002 11:08
I got the vector math x = x1 - x2
Is this correct? I am not good with physics or math, but once I get an idea of what I am doing I can implement it like nuts

Thanks,
Sean

QuothTheRaven
21
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 19th Nov 2002 14:38
X=X1-X2? That sounds like a not complete forumla for slope, where slope = (Y2-Y1)/(X2-X1) That's when you have two Y points, y1 and y2, and two x points, x1 and x2. That gives you the slope in terms of rise/run. Is that what you wanted?
sgalland
21
Years of Service
User Offline
Joined: 18th Nov 2002
Location: United States
Posted: 20th Nov 2002 02:49
YES! that is what I meant, but thanks for clarifying it for me. This is forum is good, I tried other game programming language forums and they suck. Thanks a lot guys, I will post when I complete my game

sgalland
21
Years of Service
User Offline
Joined: 18th Nov 2002
Location: United States
Posted: 20th Nov 2002 03:49
OK one more question, my code doesn't seem functional and I have no idea what I am doing wrong, any suggestions on this chunk would be helpful. Also sprite 2 is the ball...


sgalland
21
Years of Service
User Offline
Joined: 18th Nov 2002
Location: United States
Posted: 20th Nov 2002 04:13
I changed the code to what I think is logical and it still isn't working... so any ideas are apprecitated! Thanks again in advance


Login to post a reply

Server time is: 2024-03-02 17:36:04
Your offset time is: 2024-03-02 17:36:04