## How to make a Character jump!! in a 2d game, not rpg

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

mundofr
Coder
Posts: 34
Joined: Sat Apr 16, 2005 9:11 pm
Location: IN, USA
Contact:

### How to make a Character jump!! in a 2d game, not rpg

I was wondering the other day how to make a sprite jump, like how to measure the heigth and time in the air, does any1 kno statement or loop to make that possible?
im trying to create some kind of 2d game, but i cant make my char jump

jbsonicx

### re: making a sprite jump

Jumping can be kind of complicated. In my game, the sprite is made to jump in a parabolic path.

A parabola has the form:
y= (a)x ^ 2 + (b)
Pretty simple if a = 1 and b = 0

So basically, as your sprite moves, calculate the distance travelled in the x direction after you hit the jump button, and make the Height = the square of that amount.

Hope this helps.

jbsonicx

### Actually, it is a bit more complicated than I let on

To make your character jump, remember that "A" must be = -1, and the highest point is where x = 0. Make "B" = the height you want your character to jump. Also, decide how far you want your character to travel when it jumps. Ie, where on the X axis will Y = 0. If you want it to travel 10 pixels, you have to start from x = -5, and calculate things as x increases to +5.

I said it was complicated.

Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:
No vectors are the way.

Code: Select all

``````SCREEN 13
power = 12    'power  of jump 0=no jump
speed = 4      'speed horizontally of guy
gravity = 1    'gravity value: 0=no gravity
y = 200         'Starting y pos
x = 50           'Starting x pos
xv = speed
yv = power
DO
CLS
y = y - yv
x = x + xv
yv = yv - gravity
PSET (x, y), 15
IF y >= 200 THEN EXIT DO
WAIT &H3DA, 8
WAIT &H3DA, 8, 8
LOOP
``````
Not really that hard. Hope that helps.
"But...It was so beutifully done"

Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:
Um, Mitth.. the value of gravity (Given if each pixel represents a meter) is 9.81 m/sec^2.. (Given if each pixel is a centemeter) it would be 981 cm/sec^2...

Just saying,. ,.
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)

Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:
lol Rattra. I knew that.
But this is a different unit of gravity. You can compare it to Earth's gravity. Just change it to find out.
"But...It was so beutifully done"

mundofr
Coder
Posts: 34
Joined: Sat Apr 16, 2005 9:11 pm
Location: IN, USA
Contact:
wow thanks a lot, it actually works now, but i was wondering if u can move the sprite while it is in the air?
and also were can i put that code that Mitth 'raw' nurodo posted..
<b><i> "Rock is the first thing in life, after rock comes the comp...." Rock on Big M</i></b>
<img src="http://www.freewebs.com/mundofr/bigm2.bmp">

Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:
where can you put my code? ummm....depends on your program, it was ment as a learning program, that you can learn how it works and make your own that you can make it fit in your program.

As for the other question: plauy around with it!
"But...It was so beutifully done"

mundofr
Coder
Posts: 34
Joined: Sat Apr 16, 2005 9:11 pm
Location: IN, USA
Contact:
Hey thanks Mitth 'raw' nurodo. I unterstood the formula u made and now i can make my game cooler.. i just deleted the speed varaiable so the speed is actually the left or rigth, i made a demo for the physisis if any1 wants it
http://www.freewebs.com/mundofr/jumptest.exe

Thanks a lot, post somethign back
<b><i> "Rock is the first thing in life, after rock comes the comp...." Rock on Big M</i></b>
<img src="http://www.freewebs.com/mundofr/bigm2.bmp">

Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:
Cool. Glad you figured it out.
Looks cool.

Now if you know the Get/Put comds you can make a sprite jump and stuff with that forumla.
"But...It was so beutifully done"

mundofr
Coder
Posts: 34
Joined: Sat Apr 16, 2005 9:11 pm
Location: IN, USA
Contact:
thanks a lot!
<b><i> "Rock is the first thing in life, after rock comes the comp...." Rock on Big M</i></b>
<img src="http://www.freewebs.com/mundofr/bigm2.bmp">