Game Development Reference
In-Depth Information
Public Overrides Sub Entry(ByVal World As Monster)
World.Say("I feel so angry!")
End Sub
Public Overrides Sub ExitFunction(ByVal World As Monster)
End Sub
Public Overrides Sub Update(ByVal World As Monster)
World.BackColor = Color.Pink
End Sub
End Class
What remains is to put those states into an FSM and wire that FSM to the user
interface. We need a new FSM for the feelings. Switch to the code for Monster.vb
and locate the declaration for the monster's Brains . Add code for feelings so that
we have two FSMs as follows:
'We need an FSM.
Dim Brains As New FSM
'We need to feel as well as act.
Dim Feelings As New FSM
Now that we have a new FSMmachine for feelings, we need to load it with states.
Add the following lines to Monster_Load() below the lines that states into Brains :
'Load our feelings (make the start state appropriate).
Feelings.LoadState(New FeelHappy)
Feelings.LoadState(New FeelAfraid)
Feelings.LoadState(New FeelAngry)
Now we have to tell our monster to examine its feelings. Locate ThinkButton_Click()
and add the following line to make our monster feel each time it thinks:
Feelings.RunAI(Me)
Now run the project. Lower the monster's hit points first and watch it become
afraid while hiding. When we piggy-backed the monster's feeling onto its
actions, we could not make it feel that way while it was hiding. Run it through
the rest of the transitions to make sure that its feelings match the conditions. If
we need finer-grained control, we could have the feeling FSM react to different
levels of hit points than the action FSM machine uses. Our monster might be in
combat, take damage, feel afraid but stay in combat, take more damage, and
then flee.
Search Nedrilad ::




Custom Search