Game Development Reference
In-Depth Information
This code deals with the sideways road, but it needs help from the class in terms
of the X position. Our virtual world is one of integer values, usually in terms of
pixels, made possible by our flat, 2D simulation. We use a floating point value to
store position so that we can accumulate fractions of a pixel of motion because
our frame rate and speeds do not always divide evenly. Aside from that, every-
thing is integer pixels, so we will provide a function that converts our floating-
point position to the closest integer. While we are doing that, we will provide the
rest of the functions used to get read-only access to the internal data of the
vehicle. Add the following code to the Vehicle class.
Public Function ID() As String
Return myName
End Function
'Where along the road is it?
Public Function X() As Integer
Return CInt(Xpos)
End Function
'How fast am I going?
Public Function Speed() As Integer
Return currentV
End Function
'How long is my car?
Public Function Length() As Integer
Return myLength
End Function
'What lane am I in?
Public Function Lane() As Integer
Return myLane
End Function
That gives us a good start on vehicles. We can test the code by adding some code
to the Road form to create a few vehicles. We need to change our focus from
the Vehicle class to the Road form. View the code of the Road.vb and add the
following code:
#Region "Public Stuff"
'A place to keep our car collection.
Public ToyBox As New Collection
Search Nedrilad ::

Custom Search