Asteroid physics

Blitz3D Forums/Blitz3D Beginners Area/Asteroid physics

Craig H. Nisbet(Posted 2004) [#1]
Hi all, Does anyone have any code for fake physics like the kind used in asteroids where the player can turn and he will drift in the direction he was previously moving until he hits the thrusters?


Jeppe Nielsen(Posted 2004) [#2]
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



Sledge(Posted 2004) [#3]
NO! NOOO! NOOOOOOOO! TAKE IT AWAY!!

I was just about to start working on this... now you've posted an example I'll HAVE to look at it, removing 99% of the fun!

Concentrate Sledge -- must...avert...eyes...gnrrrrrhh...pop!...squelch!





Oops.