Game Development Reference
In-Depth Information
independent executable. In the code, comments identify the core five vehicles
needed for initial testing. Using all 14 will have a speed impact on the simulation.
Debugging statements, when turned on, will have a serious impact on speeds. A
particularly fast computer is not required. (This topic was written on an eight-
year-old computer with dual 1.2GHz Athlon MP processors and 2GB of RAM
running numerous background server processes at all times.)
The code has two parts: the road and the vehicles. We will develop both of them
together. First we will put some cars on the road; then we will animate them. The
last thing we will do will be to make them think.
The code uses LineShape controls to mark the edges of the pavement. These
controls are part of the Visual Basic PowerPack, a free download fromMicrosoft.
It is available at http://msdn.microsoft.com/en-us/vbasic/bb735936.aspx. Check
the Toolbox window in Visual Basic to see if you already have the controls
installed. If you do not have them and you do not want to download the
PowerPack, the project will operate properly without the two lines. Simply do
not add them when called for and do not add any code that manipulates them.
The text will note these optional additions.
The Road and the Vehicles
Launch Visual Basic and create a project called CarsAndTrucks . Then follow these
steps:
1. Change the name of Form1.vb file to Road.vb. Set its Text property to Cars
and Trucks.
2. Resize the form. 1,050 300 is a good size. Depending on your monitor
width, you may want to unpin the Solution Explorer or the Toolbox to gain
width. Wider is better.
3. Double-click My Project in Solution Explorer. Go to the Compile tab and
set Option Strict to On. Option Strict turns off silent type conversions that
could fail and forces us to make them explicit. Being mindful of type con-
versions as we write the code helps prevent bugs.
4. Save all. Do this on a regular basis as we go.
Add a class to the project and call it Vehicle.vb. Our vehicles will keep a modest
amount of data, most of which will be private. To start with, we will want to be
 
 
Search Nedrilad ::




Custom Search