Game Development Reference
In-Depth Information
Run this code in the debugger. Notice that on the first animation frame, the view
jumps from 200 to center on the reference vehicle. Click a vehicle and watch the
view center on that vehicle. You can walk up and down the chain this way. Below
the vehicles, you can see the marker fly by at 50 pixels per second.
Now we will finish adding the final user-interface elements. While we have
not yet added the AI, we can predict that the richness of the interactions will
be greatly enhanced if we can have more than a single lane. Take a glance at
Figure 8.2 and then switch to the Design view of Road.vb.
1. Drag a Label control to the form and place it to the right of the RefLabel.
Change the Text property of the new label to Lanes.
2. Drag a NumericUpDown control next to the new label. Resize the control
and make it smaller because it has to display only a single-digit number.
Change the Name property to LanesUpDown. Change the Maximum
property to 5 and the Minimum property to 1.
3. Enlarge the PanScrollBar control so that it takes up all of the rest of the
available space.
4. If you have the PowerPack, drag a LineShape control to anywhere on the
form. Change its Name property to FastLineShape. Drag another LineShape
control to the form and change its Name property to SlowLineShape.
Switch to the Code view of Road.vb and locate the Public Stuff region. The AI
will want to ask the form howmany lanes there are. Add the following code to the
region:
'Tell others how many lanes.
Public Function Lanes() As Integer
Return CInt(LanesUpDown.Value)
End Function
If you have the PowerPack and added the two LineShape controls to the form,
add the following code to the form:
Private Sub Road_Resize(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Resize
'Get the slow line into place.
SlowLineShape.X1 = 0
SlowLineShape.X2 = Me.Width
 
Search Nedrilad ::




Custom Search