public class FiniteStateMachine
extends java.lang.Object
Constructor and Description |
---|
FiniteStateMachine(BaseEntity owner)
A FSM belongs to an entity (it cannot be shared by other entities)
|
FiniteStateMachine(BaseEntity owner,
State currentState,
State previousState,
State globalState) |
Modifier and Type | Method and Description |
---|---|
void |
changeState(State newState)
Change the current state of the entity.
|
State |
getCurrentState()
Get the current state
|
State |
getGlobalState()
Get the global state
|
java.lang.String |
getNameOfCurrentState() |
State |
getPreviousState() |
boolean |
isCurrentState(State state)
Sees if the current state is of the same type (class) as the parameter.
|
boolean |
isGlobalState(State state)
Sees if the global state is of the same type (class) as the parameter.
|
boolean |
isPreviousState(State state)
Sees if the previous state is of the same type (class) as the parameter.
|
boolean |
isUsingState(State st)
Use this method if using the singleton objects for each state.
|
boolean |
onMessage(Telegram msg)
This method is called when a telegram for the owning entity is received.
|
void |
revertToPreviousState()
Performs the same actions as the changeState() method but the new state
will be the previous state.
|
void |
setCurrentState(State s)
Use this to set the current state.
|
void |
setGlobalState(State s)
Use this to set the global state.
|
void |
setPreviousState(State s)
Use this to set the previous state.
|
void |
update(double deltaTime,
World world)
This method is called by the world update method and should not be caled directly.
|
public FiniteStateMachine(BaseEntity owner)
owner
- public FiniteStateMachine(BaseEntity owner, State currentState, State previousState, State globalState)
owner
- currentState
- previousState
- globalState
- public void setCurrentState(State s)
s
- the state to usepublic void setGlobalState(State s)
s
- the state to usepublic void setPreviousState(State s)
s
- the state to usepublic void update(double deltaTime, World world)
deltaTime
- world
- public boolean onMessage(Telegram msg)
msg
- the telegrampublic void changeState(State newState)
newState
- the new current statepublic void revertToPreviousState()
public boolean isGlobalState(State state)
state
- the state we want to compare with.public boolean isPreviousState(State state)
state
- the state we want to compare with.public boolean isCurrentState(State state)
state
- the state we want to compare with.public boolean isUsingState(State st)
st
- the current state objectpublic State getCurrentState()
public State getGlobalState()
public State getPreviousState()
public java.lang.String getNameOfCurrentState()
Processing library AI_for_2D_Games by Peter Lager. (C) 2013