Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating a QB-Pong Game
#1
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!
Reply
#2
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.
Reply
#3
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)
Reply
#4
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
Reply
#5
And if you want an example...

http://faq.qbasicnews.com/?blast=BallToBallCollision

Big Grin
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#6
billiards, rel? Wink
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
Reply
#7
I tried but the cue ball always bounces ala Masse. ;*)
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)