Asteroid physics

Blitz3D Forums/Blitz3D Beginners Area/Asteroid physics

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.

Here you go :-)

;Asteroid physics

Graphics 800,600,16,2
SetBuffer BackBuffer()

Const shipacc#=0.1,shipturnspeed#=2
Global shipx#=400,shipy#=300,shipvx#,shipvy#,shipangle#


Repeat
Cls

shipcontrol
shipupdate

shipdraw(10)



Flip
Until KeyDown(1)
End

Function shipcontrol()
	
	;thrust
	If KeyDown(200)
	
		shipvx#=shipvx#+Cos(shipangle#)*shipacc#
		shipvy#=shipvy#+Sin(shipangle#)*shipacc#
	
	EndIf
	
	If KeyDown(205)
	
		shipangle#=shipangle+shipturnspeed#
	
	EndIf
	
	If KeyDown(203)
	
		shipangle#=shipangle-shipturnspeed#
	
	EndIf
	

End Function

Function shipupdate()
	
	shipx=shipx+shipvx
	shipy=shipy+shipvy
	
	If shipx<0
	
		shipx=800
	
	EndIf
	
	If shipx>800
	
		shipx=0
	
	EndIf
	
	If shipy<0
	
		shipy=600
	
	EndIf
	
	If shipy>600
	
		shipy=0
	
	EndIf
	
End Function

Function shipdraw(size#=1)

	Line shipx-Cos(shipangle)*size,shipy-Sin(shipangle)*size,shipx+Cos(shipangle)*size,shipy+Sin(shipangle)*size

End Function