Posts: 9
Threads: 3
Joined: Dec 2003
Hello everyone!
It's me again, I'm trying to create a QBasic Pong game and I'm having a problem with the gravity of the game. I have no much skills in QBasic with controlling gravity or adding gravity to the game. :oops: Can you please help me!
Thank you!
Posts: 3,616
Threads: 287
Joined: Jan 2003
Gravity? What do you mean? Acceleration?
I don't see a need for gravity equations in any pong game.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Posts: 309
Threads: 15
Joined: Jul 2003
You should have 2 components for your velocity . I'll use Vx and Vy for the change in horizontal and vertical position in 1 time period. I'll use g for the acceleration of gravity in 1 time period. If up is positive then g is a negative number (The default values for QB are the opposite). Try different values for g to get the effect you want.
When the ball doesn't bounce off any thing:
Code:
x = x + Vx
y = y + Vy + g / 2 'The " + g / 2" is more accurate but not necessary
Vy = Vy + g
hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)
For God so loved the world, that He gave His only begotten Son,
that whoever believes in Him should not perish, but have eternal life.(John 3:16)
Posts: 2,020
Threads: 24
Joined: Jun 2002
to expand on what he's saying, you want two velocity values for simplicity.
Code:
x = x + vx
y = y + vy
when the ball hits a paddle or the top/bottom, you just do the like:
Code:
if y > paddle1 and y < paddle1 + 20 and x < 0 then vx = -vx
if y > paddle2 and y < paddle2 + 20 and x > 319 then vx = -vx
if y < 0 or y > 199 vy = -vy
the top two lines reverse the x speed of the ball if it hits a paddle at location paddle1 on the left and paddle2 on the right. the second changes the y speed of the ball if it hits the roof.
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Posts: 3,288
Threads: 167
Joined: Nov 2001
Posts: 2,020
Threads: 24
Joined: Jun 2002
billiards, rel?
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Posts: 3,288
Threads: 167
Joined: Nov 2001
I tried but the cue ball always bounces ala Masse. ;*)