Game Development Reference
In-Depth Information
If newspeed > currentV Then Me.Body.BackColor = Color.LightGreen
If newspeed < currentV Then Me.Body.BackColor = Color.Pink
'Execute the decisions.
currentV = newspeed
myLane = newlane
End Sub
Private Function SpeedInLane(ByVal somelane As Integer, _
ByVal myIndex As Integer, ByVal theRoad As Road) As Integer
'Want some daylight between our bumper and bumpers in other lanes.
Dim CUTOFF_BUFFER As Integer = 21
'Does the lane exist?
If (somelane > theRoad.Lanes()) Or (somelane < 1) Then
'Debug.WriteLine(Me.ID & " checking lane " & somelane.ToString & _
'
" which does not exist.")
Return 0
End If
'If it's not our current lane, we have to prevent side swiping
'a car in the other lane whose nose is behind our nose.
Dim BlindSpot As Vehicle = CarBehind(somelane, myIndex, theRoad)
If somelane <> myLane Then
'Only if there is somebody in that lane behind me.
If BlindSpot IsNot Nothing Then
'Will I hit them? Add some padding to prevent
'cutting them off.
Dim tail As Integer = Me.X - Me.Length - CUTOFF_BUFFER
'If they are behind me and my tail is behind their nose,
'I'll hit them.
If tail < BlindSpot.X Then
'Debug.WriteLine(Me.ID & " sees that lane " & _
' somelane.ToString & " is blocked by " & BlindSpot.ID)
Return -1
End If
'Are we thinking about being rude?
'I could change this to 1x their speed and actually
'decline the lane, but we'll just cut them off instead.
tail += CUTOFF_BUFFER - BlindSpot.Speed * 2
If tail < BlindSpot.X Then
'Debug.WriteLine("++++" & Me.ID & " considers cutting off " & _