Game Development Reference
In-Depth Information
Public Overrides Function ShouldTransition(ByVal World As Monster) As String
If Not World.DetectsPlayers Then
'No one to attack or flee from
Return NextState
Else
Return ""
End If
End Function
End Class
Public Class LowHealthTxn
Inherits BasicTransition
Public Overrides Function ShouldTransition(ByVal World As Monster) As String
If Not World.GoodHealth Then
'Stop attacking
Return NextState
Else
Return ""
End If
End Function
End Class
We need to put these transitions into the AttackState class's New() routine. Be
sure you add the code to the state class and not to either of the transition classes!
When complete the New() function of the AttackState class, it will look as
follows:
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
Txn.Initialize(GetType(HidingState).Name)
'Add it to our list of transitions
MyTransitions.Add(Txn)
'Then react to health - if low, flee
Txn = New LowHealthTxn()
'Set the next state name of that transition
Txn.Initialize(GetType(FleeState).Name)
'Add it to our list of transitions
 
Search Nedrilad ::




Custom Search