JUMPING!!!!!
Here is an easy way to get a sprite to jump up and come back down.
'*******start code*********
Graphics 600,800
Global x:Float=0 'character coordinates
Global y:Float=400
Global jump:Int=0 'a flag; tells us if we are jumping or not (0=no jump,1=jump)
Global gravity:Float=0.5 'this affects the height of the jump
Global jumpheight:Float=7 'this is the max height of the jump; mess around with these numbers
While Not KeyDown(key_escape)
SetColor 192,0,0 'red
DrawOval x,y,10,15 'x,y,width,height of oval
SetColor 192,192,192 'white
DrawLine 0,415,600,415 'horizontal line from x1,y1 to x2,y2 right below the sprite
If KeyDown(key_space)
jump=1 'flag activated
EndIf
Rem
this is wher you would add left and right movements
discussed in the first post by Jebbs (me)
that way you can move side to side while jumping
these were just copied to save time
EndRem
If KeyDown(key_left)
x:-1 'this makes it seem like you are going against the wind when you go left; could be an idea?
EndIf
If KeyDown(key_right)
x:+5
EndIf
Rem
notice how I took out the going up and down codes;
you don't need them in a jumping side to side scrolling game
howerver, you could add them to see what will happen after you jump at a higher altitude
EndRem
Dojump() 'just a lable, when a function calls it up later, it will be activated
If y>=400 'y starts at 400 remember; once it gets back to 400 after jumping, it will stop falling
'*if y>=400 means, if y is greater than or equal to 350
jump=0 'now launch is over; inorder to jump again, must reset flag to 0
jumpheight=7 'later on, jumpheight will get changed; this just sets it back to normal again
EndIf
Flip
Cls
Wend
Function dojump() 'goes to the line that says "dojump()" and processess through it
If jump=1 'if the flag says "yes" then jump; in otherwords, if spacebar, then flag = 1(yes), then actually jump
y:-jumpheight 'while jump=1, take the y coordinate and subtract it by height
jumpheight:-gravity 'basically widdles "jumpheight" until it starts to go the other way; kinda like a parabola!
EndIf
If jumpheight<=-5
jumpheight=-5 'makes it so that jumpheight doesn't get lower than negative five
EndIf
EndFunction
'********Done!!!!!!!!***********
I give credit to Amon in one of his posts, "Jump Code for Kaisuo". They should be quite similar.
I still am trying to figure out some nice codes for moving sprites myself. I've been looking for a good way of adding momentum to my sprites so that when they hit a wall, they will take several steps back. And other things like that.
Well, I hope this helped you.
Goodluck
PS- Do you know how to insert images as sprites?
Like, substituting the ovals and rectangles with pictures?
Ex.: global Sprite:timage("sprite.png")
drawimage sprite,x,y
Here is an easy way to get a sprite to jump up and come back down.
'*******start code*********
Graphics 600,800
Global x:Float=0 'character coordinates
Global y:Float=400
Global jump:Int=0 'a flag; tells us if we are jumping or not (0=no jump,1=jump)
Global gravity:Float=0.5 'this affects the height of the jump
Global jumpheight:Float=7 'this is the max height of the jump; mess around with these numbers
While Not KeyDown(key_escape)
SetColor 192,0,0 'red
DrawOval x,y,10,15 'x,y,width,height of oval
SetColor 192,192,192 'white
DrawLine 0,415,600,415 'horizontal line from x1,y1 to x2,y2 right below the sprite
If KeyDown(key_space)
jump=1 'flag activated
EndIf
Rem
this is wher you would add left and right movements
discussed in the first post by Jebbs (me)
that way you can move side to side while jumping
these were just copied to save time
EndRem
If KeyDown(key_left)
x:-1 'this makes it seem like you are going against the wind when you go left; could be an idea?
EndIf
If KeyDown(key_right)
x:+5
EndIf
Rem
notice how I took out the going up and down codes;
you don't need them in a jumping side to side scrolling game
howerver, you could add them to see what will happen after you jump at a higher altitude
EndRem
Dojump() 'just a lable, when a function calls it up later, it will be activated
If y>=400 'y starts at 400 remember; once it gets back to 400 after jumping, it will stop falling
'*if y>=400 means, if y is greater than or equal to 350
jump=0 'now launch is over; inorder to jump again, must reset flag to 0
jumpheight=7 'later on, jumpheight will get changed; this just sets it back to normal again
EndIf
Flip
Cls
Wend
Function dojump() 'goes to the line that says "dojump()" and processess through it
If jump=1 'if the flag says "yes" then jump; in otherwords, if spacebar, then flag = 1(yes), then actually jump
y:-jumpheight 'while jump=1, take the y coordinate and subtract it by height
jumpheight:-gravity 'basically widdles "jumpheight" until it starts to go the other way; kinda like a parabola!
EndIf
If jumpheight<=-5
jumpheight=-5 'makes it so that jumpheight doesn't get lower than negative five
EndIf
EndFunction
'********Done!!!!!!!!***********
I give credit to Amon in one of his posts, "Jump Code for Kaisuo". They should be quite similar.
I still am trying to figure out some nice codes for moving sprites myself. I've been looking for a good way of adding momentum to my sprites so that when they hit a wall, they will take several steps back. And other things like that.
Well, I hope this helped you.
Goodluck
PS- Do you know how to insert images as sprites?
Like, substituting the ovals and rectangles with pictures?
Ex.: global Sprite:timage("sprite.png")
drawimage sprite,x,y