Qbasicnews.com
October 22, 2020, 09:12:50 AM
 Welcome, Guest. Please login or register. 1 Hour 1 Day 1 Week 1 Month Forever Login with username, password and session length
 Home Help Search Login Register
 Pages: [1]
 Author Topic: Creating a QB-Pong Game  (Read 1908 times)
drjulio2003
New Member

Posts: 9

 « on: January 07, 2004, 12:08:06 PM »

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!
 Logged
Zack
*/-\*

Posts: 3974

 « Reply #1 on: January 07, 2004, 12:54:32 PM »

Gravity? What do you mean? Acceleration?
I don't see a need for gravity equations in any pong game.
 Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
SCM
Wandering Guru

Posts: 311

 « Reply #2 on: January 07, 2004, 02:37:01 PM »

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
 Logged

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)
toonski84
__/--\__

Posts: 2567

 « Reply #3 on: January 07, 2004, 02:51:47 PM »

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.
 Logged

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
relsoft
*/-\*

Posts: 3927

 « Reply #4 on: January 09, 2004, 03:45:31 AM »

And if you want an example...

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

 Logged

y smiley is 24 bit.

Genso's Junkyard:
http://rel.betterwebber.com/
toonski84
__/--\__

Posts: 2567

 « Reply #5 on: January 09, 2004, 10:42:52 AM »

billiards, rel?
 Logged

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
relsoft
*/-\*

Posts: 3927

 « Reply #6 on: January 12, 2004, 02:16:50 AM »

I tried but the cue ball always bounces ala Masse. ;*)
 Logged

y smiley is 24 bit.

Genso's Junkyard:
http://rel.betterwebber.com/
 Pages: [1]