Game Development Reference
In-Depth Information
Open the project and edit the AttackState.vb class. Add the following line to the
Update() routine:
World.BackColor = Color.Pink
Switch to the FleeState.vb class. Add the following line to the Update() routine:
World.BackColor = Color.LightGray
Switch to the HidingState.vb class. Add the following line to the Update() routine:
World.BackColor = Color.LightGreen
Run the code and watch the background of the form change color with the state
of the AI. We have no visual representation of our monster, but we can tell at a
glance how it is feeling. Unfortunately, this forces our monster to be happy any
time it is hiding, even if it is near death and unwilling to fight. The mapping
between our action states and the emotional states is imperfect. It is time to give
our monster a more sophisticated set of feelings.
Using a Separate FSM for Emotions
Comment out or completely remove the three lines you just added and run the
program to make sure that all of them are inoperative. We are going to add a
separate FSM to model the monster's feelings. We will need three new states, but
we can reuse the existing transitions. Once we have created the states, adding
them to the AI will be very easy. Add a new class to the project and name it
FeelHappy.vb. Just inside the class definition, add the following code:
Inherits BasicState
After you press Enter, VB will populate the required skeletons. Add code until
your file looks like the following:
Public Class FeelHappy
Inherits BasicState
Public Sub New()
Dim Txn As BasicTransition
'Get angry if I see intruders while healthy.
Txn = New SeePlayerHighHealthTxn()
'Set the next state name of that transition.
Txn.Initialize(GetType(FeelAngry).Name)
'Add it to our list of transitions.
MyTransitions.Add(Txn)
 
 
Search Nedrilad ::




Custom Search