Direction Control

BlitzMax Forums/BlitzMax Beginners Area/Direction Control

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.

OK, the truck moves correctly.
I'm very stuck on making the trailer move realistically forward and backward.
Would really appreciate a helping hand here.
The truck.png is a square 21x21, the trailer.png is a rectangle 21x62.
Graphics 800,600
Global truck = LoadImage("media/images/truck.png")
MidHandleImage truck
Global trailer = LoadImage("media/images/trailer.png")
SetImageHandle trailer,10,1
Global truckx#=320, trucky#=240, truckangle#=0, trailerangle#=0, thrustdx#=0, thrustdy#=0
While Not KeyDown(key_escape)
	Cls
	SetRotation truckangle
	DrawImage truck,truckx,trucky
	SetRotation trailerangle
	DrawImage trailer,truckx,trucky+12
	If KeyDown(KEY_LEFT) And KeyDown(key_up) truckangle:-1 trailerangle:+1
	If KeyDown(KEY_RIGHT) And KeyDown(key_up) truckangle:+1 trailerangle:-1
	If KeyDown(KEY_LEFT) And KeyDown(key_down) truckangle:+1 trailerangle:-1
	If KeyDown(KEY_RIGHT) And KeyDown(key_down) truckangle:-1 trailerangle:+1
	If KeyDown(key_up)
		tdx#=Cos( truckangle-90 ) * 0.03
		tdy#=Sin( truckangle-90 ) * 0.03
		thrustdx = thrustdx + tdx
		thrustdy = thrustdy + tdy
	EndIf
	If KeyDown(key_down)
		tdx#=Cos( truckangle-90 ) * 0.03
		tdy#=Sin( truckangle-90 ) * 0.03
		thrustdx = thrustdx - tdx
		thrustdy = thrustdy - tdy
	EndIf
	truckx:+thrustdx
	trucky:+thrustdy
	thrustdx:*0.955
	thrustdy:*0.955
	If truckx>GraphicsWidth()+14 truckx=-14		'bounds check
	If truckx<-14 truckx=GraphicsWidth()+14
	If trucky>GraphicsHeight()+14 trucky=-14
	If trucky<-14 trucky=GraphicsHeight()+14
	FlushMem
	Flip
Wend