Ok. My character doesnt always jump when hes on a platform. I think it has something to do with thr jumpheight fluctating, and i dont know how to make it stop without the whole routine not working.
Graphics 800,600 SetBuffer BackBuffer() Global dude = LoadImage("dude.png") Global dline = LoadImage("dudeline.png") Global pltf = LoadImage("platform.png") Global pltfl = LoadImage("platline.png") Global jumpheight# = 10 Global canjump = 0 Global jump = 0 Const gravity# = 0.4 Type player Field x# Field y# Field h# End Type Type platform Field x Field y Field g End Type createplatform() createplayer() While Not KeyHit ( 1 ) Cls Text 50,50,"Jumpheight = " +jumpheight drawlines() renderplatform() renderplayer() moveplayer() playerjump() collisionchecks() Flip Wend End ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; Function : Draw Lines ; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function drawlines() For p.player = Each player DrawImage dline,p\x + 3,p\y + 50 Next For plat.platform = Each platform DrawImage pltfl,plat\x,plat\y - 1 Next End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; Function : Create Platform ; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function createplatform() plat.platform = New platform plat\x = 600 plat\y = 535 End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; Function : Create Player ; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function createplayer() p.player = New player p\x = 300 p\y = 540 p\h = 10 End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; Function : Render Player ; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function renderplayer() For p.player = Each player DrawImage dude,p\x,p\y,0 Next End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; Function :Render Platform ; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function renderplatform() For plat.platform = Each platform DrawImage pltf,plat\x,plat\y Next End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; Function : Move Player ; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function moveplayer() If KeyDown ( 203 ) For p.player = Each player p\x = p\x - 3 Next ElseIf KeyDown ( 205 ) For p.player = Each player p\x = p\x + 3 Next EndIf For p.player = Each player If p\y > 540 Then p\y = 540 canjump = 0 jump = 0 jumpheight = 10 EndIf Next End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; Function : Player Jump ; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function playerjump() If KeyHit ( 57 ) And (jumpheight = 10 Or (Int(jumpheight = -1))) canjump = 1 jump = 1 jumpheight = 10 EndIf If canjump = 1 And jump = 1 Then If jumpheight <=0 Then For p.player = Each player For i = 0 To 1 + Abs(jumpheight) If collisionchecks() = True Then Exit p\y = p\y + 1 Next Next Else For p.player = Each player For i = 0 To jumpheight If collisionchecks = True Then Exit p\y = p\y - 1 Next Next EndIf jumpheight = jumpheight - gravity Else jump = 0 canjump = 0 jumpheight = 10 EndIf End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; Function : Collision checks ; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function collisionchecks() For p.player = Each player For plat.platform = Each platform If ImagesCollide(dline,p\x + 3,p\y + 50,0,pltfl,plat\x,plat\y - 1,0) And jumpheight <0 Then canjump = 1 jump = 0 Return True ElseIf p\y <540 And jumpheight = 10 Then canjump = 1 jump = 1 jumpheight = -1 Return True EndIf Next Next Return False End Function