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