Game Development Reference
In-Depth Information
accidentally try to create an object of this type. Add the MustInherit keyword
to the very first line:
Public MustInherit Class BasicState
The three classes we create will inherit from BasicState , and we will be able to
create objects of those types. The analogy here is that it is correct to create dogs
and cats and impossible to create generic mammals. So what are the things that
each child class will need to do in its own unique way? Add the following lines
below the class statement.
'Some state functionality must come from the various child states
Public MustOverride Sub Entry(ByVal World As Monster)
Public MustOverride Sub Update(ByVal World As Monster)
Public MustOverride Sub ExitFunction(ByVal World As Monster)
Note that there is no End Sub after each Sub .The MustOverride keyword tells
VB that child classes are required to have a member that has this signature. It
also means that the parent will not supply any common code for those
members. We expect the Update function of the class for the Attack state to be
very different from the Update function of the class for the Flee state. But
werequirealloftheclassesthatinheritfrom BasicState to implement an
Update function.
Not shown in BasicState is the unique initialization that each child class
requires. That initialization will be where we load the transitions out of each state
into the particular states. All states will keep their list of transitions the same way.
Add the following code to the class:
'All kinds of states keep an ordered list of transitions.
Protected MyTransitions As New Collection
The Collection object is very handy in VB. We will exploit many of its cap-
abilities. Since it is an object, we need to ensure that the variable MyTransitions
points to an actual object. The New keyword initializes the variable for us so that
it always starts pointing to an object. We will store all of the transitions for a
lection checking the transitions. Before we can do that, we have to implement
Our approach for transitions will be similar to the one we use for states. We will
create a parent class that describes all Transition objects. We will then create child
classes that inherit from the parent class and implement the unique needs of the
Search Nedrilad ::

Custom Search