Driving Code

Blitz3D Forums/Blitz3D Programming/Driving Code

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.

When I change modes to walk, drive, or fly, I need to reset the values to 0 the first time in a loop after changing the mode. For example, I'm driving a car to the airport and switch to an airplane. I need to save the values for the modes that I switch from, reset the values to 0 the first time in a loop, and when I switch from airplane to car, restore the values. Here's the latest code:

While Not KeyDown(1)
	If KeyDown(59)= True Then mode=0:modestring="Walk"
	If KeyDown(60)= True Then mode=1:modestring="Drive"
	If KeyDown(61)= True Then mode=2:modestring="Fly"
	If mode=0 Then
		If KeyDown(205)=True Then TurnEntity camera,0,-0.25,0
		If KeyDown(203)=True Then TurnEntity camera,0,0.25,0
		If KeyDown(208)=True Then MoveEntity camera,0,0,-0.1
		If KeyDown(200)=True Then MoveEntity camera,0,0,0.1
	EndIf
	If mode=1 Then
		If JoyHit(13,1) Then gear=gear-1:If gear<-1 Then gear=-1
		If JoyHit(14,1) Then gear=gear+1:If gear>1 Then gear=1
		If gear=-1 Then gearstring="Reverse"
		If gear=0 Then gearstring="Neutral"
		If gear=1 Then gearstring="Drive"
		If JoyY(1) < -0.05
			If gear=1
	  			speed=speed+0.005
	  			If speed>2 Then speed=2
				MoveEntity camera,0,0,speed
			End If
			If gear=-1
	  			speed=speed-0.005
      			If speed<-0.5 Then speed=-0.5
				MoveEntity camera,0,0,speed
			EndIf
		End If
		If JoyY(1) > 0.05
			speed=speed-0.01
			If speed<0 Then speed=0
			If speed>0 Then speed=speed*0.99
			MoveEntity camera,0,0,speed
		End If
		If JoyY(1) > -0.05 And JoyY(1) < 0.05
			speed=speed*0.99
			MoveEntity camera,0,0,speed
		End If	
		If JoyX(1) < -0.05
    		steer=-JoyX(1)/2
    		If steer>0.5 Then steer=0.5
			TurnEntity camera,0,steer,0
		End If
		If JoyX(1) > 0.05
    		steer=-JoyX(1)/2
    		If steer<-0.5 Then steer=-0.5
			TurnEntity camera,0,steer,0
		End If
		If JoyX(1) > -0.05 And JoyX(1) < 0.05 Then steer=0
	EndIf
	If mode=2 Then
		throttle=(JoyU(0)-1) * -0.5
		If throttle>0
			speed=speed+0.1
			MoveEntity camera,0,0,speed
		End If
		If JoyY(0) < -0.05
  			height=height-0.01
			MoveEntity camera,0,height,speed
		End If
		If JoyY(0) > 0.05
			height=height+0.01
			MoveEntity camera,0,height,speed
		End If
		If JoyX(0) < 0.05
    		steer=-JoyX(0)
    		If steer>0.5 Then steer=0.5
			TurnEntity camera,0,steer,0
		End If
		If JoyX(0) > 0.05
    		steer=-JoyX(0)
    		If steer<-0.5 Then steer=-0.5
			TurnEntity camera,0,steer,0
		End If
		If JoyX(0) > -0.05 And JoyX(0) < 0.05 Then steer=0
		If JoyY(0) > -0.05 And JoyY(0) < 0.05
			speed=speed*0.99
			MoveEntity camera,0,0,speed
		End If	
		If throttle=0
			speed=speed*0.99
			height=height*0.99
			MoveEntity camera,0,height,speed
		End If
	EndIf
	UpdateWorld
	RenderWorld
	Text 0,0,"Mode:"+modestring
	If mode=1 Then Text 0,15,"Car speed:"+speed*100
	If mode=2 Then Text 0,15,"Air speed:"+speed*100
	If mode=1 Then Text 0,30,"Gear:"+gearstring
	If mode=2 Then Text 0,30,"Height:"+height
	If mode=2 Then Text 0,45,"Throttle:"+throttle
	Flip
Wend