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

Post Reply
User avatar
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

Post by mundofr » Sat Apr 16, 2005 9:20 pm

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

Post by jbsonicx » Sun Apr 17, 2005 4:56 am

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

Post by jbsonicx » Sun Apr 17, 2005 5:04 am

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.

User avatar
Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:

Post by Mitth'raw'nuruodo » Sun Apr 17, 2005 8:26 am

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"

User avatar
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post by Rattrapmax6 » Sun Apr 17, 2005 8:38 am

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,. :wink: ,.
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)

User avatar
Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:

Post by Mitth'raw'nuruodo » Sun Apr 17, 2005 9:41 am

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. :wink:
"But...It was so beutifully done"

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

Post by mundofr » Sun Apr 17, 2005 12:03 pm

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.. :D
<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">

User avatar
Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:

Post by Mitth'raw'nuruodo » Mon Apr 18, 2005 11:33 am

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"

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

Post by mundofr » Mon Apr 18, 2005 6:20 pm

Hey thanks Mitth 'raw' nurodo. I unterstood the formula u made :D 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 :D
http://www.freewebs.com/mundofr/jumptest.exe
download it :D

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">

User avatar
Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:

Post by Mitth'raw'nuruodo » Tue Apr 19, 2005 2:57 pm

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. :wink:
"But...It was so beutifully done"

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

Post by mundofr » Tue Apr 19, 2005 7:25 pm

thanks a lot! :D :P
<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">

Post Reply