Part 2 - Declaring Variables
Now
that we have all of our classes defined we can proceed to declare some
variables. Open up the Code View for Form1 and copy and paste the
fallowing code.
- Private Const NumberOfFlies As Integer = 25
- Private Const SpawnStinkyInterval As Integer = 1000 \ 30 ' 1000 ms div 30 fps
- Private Const UpdateFliesInterval As Integer = 1000 \ 60 ' 1000 ms div 60 fps
- Private mobjPlayer As Actor
- Private mobjFlies As Generic.List(Of Fly)
- Private mobjScents As Generic.List(Of Scent)
- Private WithEvents mobjTimer As Timers.Timer
- Private WithEvents mobjFlyUpdater As Timers.Timer
- Private WithEvents mobjStinkySpawner As Timers.Timer
- Private mobjGraphics As BufferedGraphics
The first 3 constants are as fallows..
- NumberOfFlies - Specifies how many flies our app will use.
- SpawnStinkyInterval - Specifies how many times per second the
app will update the scent objects in the scene. The scent objects will
be updated 30 times per second.
- UpdateFliesInterval - Specifies how many timer per second
the app will update the flies in the scene. Flies will be updated 60
times per second.
After the constants is the player object,
which is just defined as an actor. The next two variables are
collections to store the flies and scent objects.
The next three
variables after that are timers that will be used to update the flies
and scent objects as well as draw them on screen at specified intervals.
The
last variable is a BufferedGraphics object that is new in .NET 2.0 and
we will use it to draw our graphics on screen. The BufferedGraphics
object will help prevent any flickering on the screen when we draw our
flies and scent objects.