Game Development Reference
In-Depth Information
Find the Public Stuff region and add the following code. We want to be able to
click on a vehicle to make it the reference vehicle, so the Vehicle class will need a
way to tell the form that a vehicle got clicked.
Public WriteOnly Property ReferenceVehicle() As Vehicle
Set(ByVal value As Vehicle)
refVehicle = value
RefLabel.Text = refVehicle.ID
End Set
End Property
Find Road_Load, the form's Load event handler, and add the following code to it
after the code that adds the last vehicle. At startup, the reference vehicle is the
middle one.
'The middle vehicle is our starting reference vehicle.
Me.ReferenceVehicle = CType(ToyBox(1 + ToyBox.Count \ 2), Vehicle)
Switch to Vehicle.vb. We need to handle the floating marker, and we need to
react if the user clicks a vehicle to make it the reference vehicle. Add the following
code to the class:
Public Sub MoveFloatingMarker(ByVal refV As Vehicle, _
ByVal Framerate As Integer, ByVal halfSize As Integer)
If refV.Speed = 0 Then Return
'Markers appear to go backward.
Xpos -= refV.Speed / Framerate
'After it falls off the back end, put it back on the front.
While Xpos < refV.X - halfSize
Xpos += 2 * halfSize
End While
'If the user changed the refV, the marker may be too far ahead.
While Xpos > refV.X + halfSize + 1
Xpos -= 2 * halfSize
End While
End Sub
'Let the user tell us which car to follow.
Private Sub Body_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Body.Click
Dim theRoad As Road = CType(Body.Parent, Road)
theRoad.ReferenceVehicle = Me
End Sub
Search Nedrilad ::

Custom Search