Game Development Reference
In-Depth Information
'The bag holds groups of vehicles by lane.
Dim Bag As New Collection
'We use myBag to access one of those groups.
Dim myBag As Collection
Dim key As String
For Each Toy In ToyBox
'Convert the lane to a string so that we can
'use it as a key.
key = Toy.Lane.ToString
If Not Bag.Contains(key) Then
'This is the first one in that lane we've seen.
'Create the group.
Bag.Add(New Collection, key)
End If
'Get my group out of the bag...
myBag = CType(Bag(key), Collection)
'...and put me in it.
myBag.Add(Toy)
Next
'Since we started with a sorted ToyBox, all
'the groups have to be sorted.
Dim Behind As Vehicle
Dim Ahead As Vehicle
Dim i As Integer
For Each myBag In Bag
Fori=1TomyBag.Count - 1
'Grab two vehicles.
Behind = CType(myBag(i), Vehicle)
Ahead = CType(myBag(i + 1), Vehicle)
'My nose is ahead of your nose, so if my tail is
'behind your nose, we conflict.
If Ahead.X - Ahead.Length <= Behind.X Then
Debug.WriteLine("###### COLLISION: " & Behind.ID & _
" is hitting " & Ahead.ID)
End If
Next
Next
End Sub
Search Nedrilad ::




Custom Search