Page 1 of 1

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

Posted: Sat Apr 16, 2005 9:20 pm
by mundofr
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

re: making a sprite jump

Posted: Sun Apr 17, 2005 4:56 am
by jbsonicx
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.

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

Posted: Sun Apr 17, 2005 5:04 am
by jbsonicx
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.

Posted: Sun Apr 17, 2005 8:26 am
by Mitth'raw'nuruodo
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.

Posted: Sun Apr 17, 2005 8:38 am
by Rattrapmax6
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: ,.

Posted: Sun Apr 17, 2005 9:41 am
by Mitth'raw'nuruodo
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:

Posted: Sun Apr 17, 2005 12:03 pm
by mundofr
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

Posted: Mon Apr 18, 2005 11:33 am
by Mitth'raw'nuruodo
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!

Posted: Mon Apr 18, 2005 6:20 pm
by mundofr
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

Posted: Tue Apr 19, 2005 2:57 pm
by Mitth'raw'nuruodo
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:

Posted: Tue Apr 19, 2005 7:25 pm
by mundofr
thanks a lot! :D :P