Game Development Reference
In-Depth Information
'The front has a higher subscript.
Ahead = CType(ToyBox(i + 1), Vehicle)
'Are they out of order?
If Ahead.X < Behind.X Then
'The one we thought should be ahead is not;
'we need to swap them.
swapped = True
'Debug.WriteLine("*** " & Behind.ID & _ " has passed " &
Ahead.ID)
ToyBox.Remove(i + 1)
ToyBox.Add(Ahead, , i)
End If
Next
End While
'Grab the leader and trailer to set the scrollbar.
Behind = CType(ToyBox(1), Vehicle)
Ahead = CType(ToyBox(ToyBox.Count), Vehicle)
'The world is half a form bigger on each side of the pack.
Dim offset As Integer = CInt(Me.Width / 2)
'The slow vehicle sets the minimum.
PanScrollBar.Minimum = Behind.X - offset
'The fast vehicle sets the maximum.
PanScrollBar.Maximum = Ahead.X - offset
If refVehicle IsNot Nothing Then
'Get the value right.
PanScrollBar.Value = refVehicle.X - offset
End If
'This more properly belongs on the resize event.
PanScrollBar.LargeChange = Me.Width \ 4
'Protective code to check that our code works OK.
Call CollisionDetect()
End Sub
'Run any time the list is sorted.
Private Sub CollisionDetect()
Dim Toy As Vehicle
Search Nedrilad ::




Custom Search