Jump around

Miscellaneous Forums/Blitz Showcase/Jump around

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.

Scrolling and game over :)
Type box
	Field x#,y#,w,h
End Type

Graphics 640,480,0,2

x#=GraphicsWidth()/2
y#=GraphicsHeight()/2

xd#=0
yd#=0

angle#=180

power#=0

Const keyleft=203
Const keyright=205
Const keyjump=208
Const keyFineAngle = 54

Global gotr=0
Global gotg=0
Global gotb=0
Global angleMod = 5

SetBuffer BackBuffer()

SeedRnd 1010
For n=1 To 50
	box.box = New box
	box\x = Rand(0,GraphicsWidth())
	box\y = Rand(0,GraphicsHeight())
	box\w = Rand(0,200)
	box\h = 10
Next

Repeat

	Cls
	If KeyDown(keyFineAngle) Then angleMod = 1 Else angleMod = 5 
	If KeyDown(keyright) And angle<270 Then angle=angle+angleMod
	If KeyDown(keyleft) And angle>90 Then angle=angle-angleMod
	
	If KeyDown(keyjump) And deck=True And Int(xd+yd)=0 Then power=power+2
	If power>100 Then power=0
	
	; jump
	If KeyDown(keyjump)=False And power>0
		power=power/10
		xd=Sin(-angle)*power
		yd=Cos(-angle)*power
		power=0
	EndIf
	
	yd=yd+.1
	xd=xd*.99
	yd=yd*.99
	
	oldx#=x
	oldy#=y
	
	x=x+xd
	y=y+yd
	
	
	; draw level
	Color 255,255,0
	Rect 0,GraphicsHeight()-10,GraphicsWidth(),10
	Color 0,255,0
	Rect 0,0,GraphicsWidth(),10
	Rect 0,10,10,GraphicsHeight()-20
	Rect GraphicsWidth()-10,10,10,GraphicsHeight()-20
	For box.box = Each box
		Rect box\x,box\y,box\w,box\h,True
		box\y = box\y + 0.05
		If box\y > GraphicsHeight()
			box\x = Rand(0,GraphicsWidth())
			box\y = -10
			box\w = Rand(0,200)
			box\h = 10
		End If
	Next
	
	; check of hitting sides, anypixel with a green component counts as solid.
	deck=False

	LockBuffer BackBuffer()

	If yd>0
		getrgb(BackBuffer(),x,y+2)
		deck=True
	Else
		getrgb(BackBuffer(),x,y-2)
	EndIf
	
	If gotg>0
		If gotr>0
			gameover = True
		End If

		y=oldy
		xd=xd*.9
		yd=-yd/3
	EndIf
		
	If xd>0
		getrgb(BackBuffer(),x+2,y)
	Else
		getrgb(BackBuffer(),x-2,y)
	EndIf
	
	If gotg>0
		x=oldx
		xd=-xd/2
	EndIf
	
	UnlockBuffer BackBuffer()
	
	If gameover
		Color 255,255,255
		Text GraphicsWidth()/2,GraphicsHeight()/2,"GAME OVER",True,True
	Else	
		; draw player
		Color 255,255,255
		Rect x-2,y-2,5,5,True
		Line x,y,x+(Sin(-angle)*10),y+(Cos(-angle)*10)
		
		; draw power bar
		Color 255,0,0
		Rect 0,2,(GraphicsWidth()/100)*power,6
	End If
Flip
Until KeyHit(1)
End

Function getrgb(buffer,x,y)
	argb=ReadPixelFast(x,y,buffer)
	gotr=(ARGB Shr 16) And $ff 
	gotg=(ARGB Shr 8) And $ff 
	gotb=ARGB And $ff
End Function