simple jump code anyone?

BlitzPlus Forums/BlitzPlus Beginners Area/simple jump code anyone?

Ice T.(Posted 2006) [#1]
I need some simple basic jumping code or stratagies to go on, I am a big fan of the mario bros. side-veiw games and really want to make a simple one but I cant make them jump!

thanx


Andres(Posted 2006) [#2]
Gravity# = .7
YSpeed# = 0
Jump# = -3.0

While NOT KeyHit(1)
YSpeed# = YSpeed# + Gravity#

Ypos# = Ypos# + YSpeed#

if keyhit(57) then YSpeed# = Jump#
Wend



Ice T.(Posted 2006) [#3]
where did you learn to code like that and how long did it take to learn it?


Andres(Posted 2006) [#4]
I've been programming in blitz for 4 years or so.


Pineapple(Posted 2006) [#5]
I've also mailed you a copy of a Dizzy thingy... Should show how to do a few things!

Dabz


Ice T.(Posted 2006) [#6]
Iv been programming for about 2 years but just this last year I have really gotten into it, and Dabz, I tryed
to download the program but said its not a "valid archive"...?


Pineapple(Posted 2006) [#7]
mmmm, weird, I zipped it using windows own zippy thingy!?!

Try this:-

http://myweb.tiscali.co.uk/mdplasteringservices/Dizzy.zip

Dabz


Andres(Posted 2006) [#8]
Dabz's code shows how a character jumps x frames up and then falls x frames, but the one i provided jumps by velocity so it's more realistic and smoother.


Pineapple(Posted 2006) [#9]
That example was based obviously on the Dizzy character, which needs to spin and land pretty much within the jump frames!

But, he has two sets of code to look at now, which use two different ways... Much better in my opinion! :D

Dabz


Ice T.(Posted 2006) [#10]
sorry, I dont now much about winzip exept to click on the Icons, could ya help me out? and I'v always wondered whats all that weird writing done on notepad, like yours thats labeled "thumbs"


robot(Posted 2006) [#11]
heres the way i learned to make people jump. This is psedo-code, so you'll haveta apply it to ur siduation
if(keyhit(jumpkey)and y=abletojump)
 yv=32
endif

if(y <> abletojump)
 playery=playery-y/3
 yv=yv-1

 ;see if the player has hit the top of a block
 if(player_hit_bottom_of_block)
  yv=0
  while(player_hit_bottom_of_block)
   playery=playery+2
  wend
 endif
 
 ;see if the player has hit the bottom
 if(player_hit_top_of_block)
  yv=abletojump
  while(player_hit_top_of_block
   playery=playery-2
  wend
 endif
endif
 

i just typed this up in a few minutes from what i can remeber, so if somthing is unclear to you, tell me and i'll try to fix it.


Ice T.(Posted 2006) [#12]
on second thought, I dont know how to use Andres or your code in blitz+ with my characters, I mean I can understand it for the most part but how do I USE it?...hmm


robot(Posted 2006) [#13]
idk. o well. maybe if you tell us where ur stuck, we could help.


Pineapple(Posted 2006) [#14]
To unzip, right click the Dizzy.zip icon, select 'Extract All' then follow the wizard, when the wizard finishes, make sure the 'show extracted files' checkbox is ticked and click 'finish'

"thumbs" is a file created by windows, it uses this file to organise the contents of the folder! When unzipped, you shouldnt see it!

Erm, if you get the zip open, below is a version of the source included, I've commented a little more in there, but you are going to have to do what the majority of us have done... study the source code a little more, unless you want to post some code and we could fill in the gaps, while explaining what we've done! :)



Right, gotta go to work, late already! :)

Dabz


Adam Novagen(Posted 2006) [#15]
Hey Dabz, is it really a good idea to use a seperate bitmap for a character's movements/jumps/directions? I mean, sure it looks the same, but if you want the game to run lean, the fewer seperate files the better... After all, individual bitmaps have some seemingly erroneous data in their headers...


Pineapple(Posted 2006) [#16]

Hey Dabz, is it really a good idea to use a seperate bitmap for a character's movements/jumps/directions? I mean, sure it looks the same, but if you want the game to run lean, the fewer seperate files the better... After all, individual bitmaps have some seemingly erroneous data in their headers...



Your right Adam, but Ice T seems new to Blitz, so giving him source that is too overly complicated may just put him off, the Dizzy one above, uses different images for different actions, which may provided more understanding about what one section of the source is doing!

After all, he was after jumping code, not how to orangize images from an image strip! ;)

Dabz


Ice T.(Posted 2006) [#17]
the part with the jump code that I'm having trouble with is that nothings jumping.
how do I put in my image and assign it to the code so that my image is jumping, oh and yeah Dabz Im still working on putting my images all into one strip so thanx


Adam Novagen(Posted 2006) [#18]
Your right Adam, but Ice T seems new to Blitz, so giving him source that is too overly complicated may just put him off, the Dizzy one above, uses different images for different actions, which may provided more understanding about what one section of the source is doing!

After all, he was after jumping code, not how to orangize images from an image strip! ;)


Of course, the "phsychology factor" I always fail to take into account. Bravo, Dabz, I stand corrected!


Ice T.(Posted 2006) [#19]
Hey! looking back at the first jumping code I just really cant figure out how to apply it in my code! can anyone help?!!!!

p.s I'v been using a cruddy jumping code for a while and I would really like to learn more advanced jumping code techneques but I cant understand it. I want to actually UNDERSTAND it so if I needed to alter the code to fit the situation.


b32(Posted 2006) [#20]
If you want to make a smooth curve, you could use:
speed# = 2.0
y# = y# - speed#
instead of:
y = y - 2

Then, you can decrease the speed by using:
speed# = speed# / 1.02

To make a jump frame, use a variable 'jump' in a Select..Case block:



Réno(Posted 2006) [#21]
And draw sprites with Ceil#() for more smoth ;)

( instead of Blitz will convert variables in Int() )


Ice T.(Posted 2006) [#22]
but how do I apply that to somthing like




Graphics 800,600

SetBuffer BackBuffer()

AutoMidHandle True
;31x34
metroid = LoadAnimImage("metroid_animation.bmp",25,34,0,4)



metroid_x=400
metroid_y=300
metroid_frame=0

If metroid_frame>3
metroid_frame=0
ElseIf metroid<0
metroid_frame=3
EndIf

While Not KeyDown(1)

Cls

If KeyDown(203)
metroid_x=metroid_x-4
metroid_frame=metroid_frame-1

EndIf

If KeyDown(205)
metroid_x=metroid_x+4
metroid_frame=metroid_frame+1
EndIf

If metroid_frame>3
metroid_frame=0

ElseIf metroid_frame<0
metroid_frame=3

EndIf

DrawImage metroid,metroid_x,metroid_y,metroid_frame
Delay 50
Flip
Wend


Ice T.(Posted 2006) [#23]
^
^
^
^
can any one help with putting jump code in this code?


DjBigWorm(Posted 2006) [#24]
Hi,

I can possibley shed some light on the subject here for you. There are several things that have to happen in order for the player to appear to "jump". In fact there is no jumping what so ever. The jump code that was shown to you simply pulls the "player image" to the bottom of the screen. There is also no floor defined??

If you already have the walking code down then the "jump code" will be no problem. You have to set up a "flag" to tell the program that you are jumping. for example

; Don't be afraid to comment the code :)
Graphics 800,600

SetBuffer BackBuffer()

AutoMidHandle True
Gravity# = .7 ; this defines what the gravity strength is. A positive number at the y location pulls the character down
Jump# = -3.0 ; this tells how high the player will go before the gravity will affect it. change the jump# value to lower negative number for a higher jump
;31x34
metroid = LoadAnimImage("metroid_animation.bmp",25,34,0,4)

metroid_x=400
metroid_y=300
metroid_frame=0

If metroid_frame>3
metroid_frame=0
ElseIf metroid<0
metroid_frame=3
EndIf

While Not KeyDown(1)

Cls

If KeyDown(57) and jumping=0 ; space bar and check to see if we have already pressed it, no double jump
jumping=1 ; setting this to a 1 value tells the program to execute the jump code calculation.
YSpeed# = Jump# ; this will now affect the location of our player since the yspeed# isn't 0 anymore
EndIf


If KeyDown(203) ; left arrow key
metroid_x=metroid_x-4
metroid_frame=metroid_frame-1

EndIf

If KeyDown(205) ; right arrow key
metroid_x=metroid_x+4
metroid_frame=metroid_frame+1
EndIf

If metroid_frame>3
metroid_frame=0

ElseIf metroid_frame<0
metroid_frame=3

EndIf

If jumping=1 ; check that we have pushed the jump key
YSpeed# = YSpeed# + Gravity# ; this will calculate the y location in pixels
metroid_y = metroid_y + YSpeed# ; this will add our calculated number to our current y position
EndIf
If metroid_y>300 ; check to see if our player has fallen past our floor
metroid_y=300 ; set our y location on 300 so that the player doesn't appear to have its feet in the ground
jumping = 0 ; this is set to 0 so that gravity will not affect the player when he has landed on the floor
EndIf
;Oval metroid_x-3,metroid_y-3,6,6

DrawImage metroid,metroid_x,metroid_y,metroid_frame
Delay 50
Flip
Wend


hope it is commented enought to let you undertand the trickery that what you see on the screen is just that illusion of something happening when it doesn't really do anything but change numbers on ya!!! happy programming


Ice T.(Posted 2006) [#25]
yes!!! thank you, I now understand it!