Game Development Reference
In-Depth Information
able to create a vehicle and draw it. We start with the data that each vehicle needs.
Add the following code to the Vehicle class.
Public Const VehicleWidth As Integer = 20
'We keep most of the vehicle data private.
Private myName As String
'Speeds are in pixels per second.
Private myDesiredSpeed As Integer
'Length is in pixels.
Private myLength As Integer
'Use floating point so that we can accumulate fractions.
Private Xpos As Double = 0
Private myLane As Integer = 1
'Actual speed in pixels per second.
Private currentV As Integer
'Visually, a vehicle is two Label controls and a TextBox control.
'We want to react when the body is clicked, so it is WithEvents.
Dim WithEvents Body As TextBox
Dim HeadLights As Label
Dim NameTag As Label
Most of the data that a Vehicle class object stores will be known when the vehicle
is created. The New() function will have many parameters, so we have a certain
amount of work to do to create our vehicles. Add the following code to the class:
'Create a vehicle.
Public Sub New(ByVal length As Integer, ByVal desiredSpeed As Integer, _
ByVal parent As Road, ByVal X As Integer, ByVal V As Integer, _
ByVal callMe As String)
'Store the basic data.
myName = callMe
myDesiredSpeed = desiredSpeed
currentV = V
Xpos = X
myLength = length
'Create our three controls.
Body = New TextBox
HeadLights = New Label
NameTag = New Label
Search Nedrilad ::

Custom Search