Game Development Reference
In-Depth Information
MyTransitions.Add(Txn)
End Sub
Recall that we disambiguate transitions by taking the first valid transition and
controlling the order in which they are evaluated. They are evaluated in the order
loaded, so reacting to players should be loaded first. We do not want our monster
to flee from players who are not there. This completes the Attack state. We will
add the Attack state to the FSM after we complete the Flee state.
Switch to FleeState.vb so that we can add the two transitions that leave the Flee
state as seen in Figure 3.2. Before we add them, note that the No Players tran-
sition in the Flee state has the same decision criteria as the No Players transition
in the Attack state. We can reuse the NoPlayersTxn class we created in Attack
State.vb as it is. We still have to create the High Health transition and load
both transitions into the state. Add the following class to the bottom of the
FleeState.vb file below the End Class statement:
Public Class HighHealthTxn
Inherits BasicTransition
Public Overrides Function ShouldTransition(ByVal World As Monster) As String
If World.GoodHealth Then
'Stop flight
Return NextState
Else
Return ""
End If
End Function
End Class
The only differences between this and LowHealthTxn are the names, the word Not
in the comparison, and the comment text. You can save yourself some typing via
copy and paste as long as you remember to edit what is pasted.
Now we will add the two transitions to the New() routine for the state. When
finished it will look like the following:
Public Sub New()
Dim Txn As BasicTransition
'Order is important - react to players first
'If no players, hide
Txn = New NoPlayersTxn()
'Set the next state name of that transition
 
Search Nedrilad ::




Custom Search