Of platforms, invisible barriers, and Multi-Jumps

BlitzPlus Forums/BlitzPlus Programming/Of platforms, invisible barriers, and Multi-Jumps

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

This may help, it was from a mini game embedded in Dungeons of Fear. It may be of use; I solved the double jump problem by not eliminating the double jump, but by making it so weak its useless. As for the single jump when falling, just set the jump "power" to 0 when a fall is detected... this could be done by a simple variable If-Then statement in my code, but I didn't add it.

Graphics 400,300,32,2
frametimer=CreateTimer(60)
Const player$="0"
Const ground$="xxxxxxxxxx"
Const leftarrow$="<=="
Const rightarrow$="==>"
Const gate$="ll"

Global gameover=False
Global time=2000
Global jump=10
Global door=False

Type player 
	Field x,y
End Type

Type arrow
	Field image$
End Type

Global platformer.player=New player
platformer\x=10
platformer\y=270

Global dir.arrow=New arrow
dir\image$=rightarrow$

While gameover=False
	WaitTimer(frametimer)
	UpdatePlatformerBackground()
	UpdatePlatformerPlayer()
	Gravity()
	Flip
	Cls
	Delay 10
Wend

Function UpdatePlatformerBackground()
	;Text StringWidth(ground$)*1,280,ground$   <=== Floor pieces
	;Text StringWidth(ground$)*2,280,ground$
	;Text StringWidth(ground$)*3,280,ground$
	;Text StringWidth(ground$)*4,280,ground$
	If time>0
		Text 0,280,ground$
		Text 100,250,ground$
		Text 200,220,ground$
		Text 100,190,ground$
		Text 0,160,ground$
		Text 0,130,ground$
		Text 0,100,ground$
		Text 0,70,ground$
		Color 128,128,128
		Text 150,100,"Leap of Faith"
		Color 255,255,255
		Text 340,150,ground$
		Text 340,120,ground$
		Text 340,90,ground$
		Text 340,60,ground$
		Text 240,30,ground$
		Text 120,30,ground$ 
	EndIf
	
	Text 370,0,dir\image$	
	Text 370,12,time
	Text 370,24,jump
	time=time-1
	If time<=0
		time=0
	EndIf 
	Text 120,20,gate$
End Function 

Function UpdatePlatformerPlayer()
	Text platformer\x,platformer\y,player$
	If KeyDown(2)
		If dir\image$=leftarrow$
			platformer\x=platformer\x-4
		EndIf
		If dir\image$=rightarrow$
			platformer\x=platformer\x+4
		EndIf 
	EndIf
	If KeyHit(3)
		If dir\image$=leftarrow$
			dir\image$=rightarrow$
		Else
			dir\image=leftarrow$
		EndIf 
	EndIf
	If KeyHit(11)
		platformer\y=platformer\y-jump
		jump=0 
	EndIf 
	
	If platformer\x<=0
		platformer\x=0
	EndIf
	If platformer\x>=395
		platformer\x=395
	EndIf	
	If platformer\y>300
		gameover=True
	EndIf
	jump=jump+1
	If jump>=50
		jump=50
	EndIf 
End Function 


Function Gravity()
	If time>0
	;0,280;0,160;0,130;0,100;0,70;0,10
	If platformer\x>=0 And platformer\x<=0+StringWidth(ground$)
		If platformer\y>=270 And platformer\y<=282
			platformer\y=270
		EndIf
		If platformer\y>=150 And platformer\y<=162
			platformer\y=150
		EndIf
		If platformer\y>=120 And platformer\y<=132
			platformer\y=120
		EndIf 
		If platformer\y>=90 And platformer\y<=102
			platformer\y=90
		EndIf
		If platformer\y>=60 And platformer\y<=72
			platformer\y=60
		EndIf 
	EndIf	
	;100,250 and 100,190
	If platformer\x>=100 And platformer\x<=100+StringWidth(ground$)
		If platformer\y>=240 And platformer\y<=252
			platformer\y=240
		EndIf
		If platformer\y>=180 And platformer\y<=192
			platformer\y=180
		EndIf
	EndIf
	;200,220
	If platformer\x>=200 And platformer\x<=200+StringWidth(ground$)
		If platformer\y>=210 And platformer\y<=222
			platformer\y=210
		EndIf
	EndIf
	;150,100
	If platformer\x>=150 And platformer\x<=150+StringWidth(ground$)
		If platformer\y>=90 And platformer\y<=102
			platformer\y=90
		EndIf
	EndIf
	;340,150;340,120;340,90;340,60
	If platformer\x>=340 And platformer\x<=340+StringWidth(ground$)
		If platformer\y>=140 And platformer\y<=152
			platformer\y=140
		EndIf
		If platformer\y>=110 And platformer\y<=122
			platformer\y=110
		EndIf 
		If platformer\y>=80 And platformer\y<=92
			platformer\y=80
		EndIf
		If platformer\y>=50 And platformer\y<=62
			platformer\y=50
		EndIf  
	EndIf
	;240,30
	If platformer\x>=240 And platformer\x<=240+StringWidth(ground$)
		If platformer\y>=20 And platformer\y<=32
			platformer\y=20
		EndIf
	EndIf
	;120,30
	If platformer\x>=120 And platformer\x<=120+StringWidth(ground$)
		If platformer\y>=20 And platformer\y<=32
			platformer\y=20
		EndIf
	EndIf
	;gate
	If platformer\x>=120 And platformer\x<=120+StringWidth(gate$)
		If platformer\y>=20 And platformer\y<=32
			platformer\y=20
			Text 0,0,"You win!!"
			door=True
			gameover=True 
		EndIf
	EndIf
	
	EndIf 
	platformer\y=platformer\y+4
End Function


Hope it helps in some way.