State Machine
About
This module allows you to create simple and hierarchical StateMachines. State Machines are composed of states, and each state has (optional) callbacks for entering and exiting state. It's also possible to restrict the transition from states using the from property.
Learn more about state machines and its applications on http://ai-depot.com/FiniteStateMachines/FSM.html
Usage
Available states can be set with addState and initial state can be set using initialState setter.
The following example creates a state machine for a player model with 3 states (Playing, paused and stopped)
var playerSM = ; playerSM; playerSM; playerSM; playerSM; playerSM; playerSMinitialState = "stopped";
It's also possible to create hierarchical state machines using the argument "parent" in the addState method. This example shows the creation of a hierarchical state machine for the monster of a game (Its a simplified version of the state machine used to control the AI in the original Quake game)
var monsterSM = ; monsterSM; monsterSM; monsterSM; monsterSM; monsterSM; monsterSM; monsterSM; monsterSMinitialState = "idle";
Ports
License
Copyright (c) 2009-15 Cássio M. Antonio
Released under the Open Source MIT license, which gives you the possibility to use it and modify it in every circumstance.