libgdx/ashley — pull request #28 by andresaraujo (2014-07-06 18:17:55+00:00)
Title: Implement finite state machines

It is a port from [ash framework](https://github.com/richardlord/Ash/blob/master/src/ash/fsm/README.textile) finite state machines. Richard Lord (the author of ash) made a good [post](http://www.richardlord.net/blog/finite-state-machines-with-ash) explaining how this works.

Creating states for an entity looks something like this:
```java
Entity spaceshipEntity = new Entity();
EntityStateMachine fsm = new EntityStateMachine( spaceshipEntity );

fsm.createState( "playing" )
.add( Motion.class ).withInstance( new Motion( 0, 0, 0, 15 ) )
.add( MotionControls.class ).withInstance( new MotionControls( Keyboard.LEFT, Keyboard.RIGHT, Keyboard.UP, 100, 3 ) )
.add( Gun.class ).withInstance( new Gun( 8, 0, 0.3, 2 ) )
.add( GunControls.class ).withInstance( new GunControls( Keyboard.SPACE ) )
.add( Collision.class ).withInstance( new Collision( 9 ) )
.add( Display.class ).withInstance( new Display( new SpaceshipView() ) );

SpaceshipDeathView deathView = new SpaceshipDeathView();
fsm.createState( "destroyed" )
.add( DeathThroes.class ).withInstance( new DeathThroes( 5 ) )
.add( Display.class ).withInstance( new Display( deathView ) )
.add( Animation.class ).withInstance( new Animation( deathView ) );

spaceshipEntity
.add( new Spaceship(fsm) )
.add( new Position( 300, 225, 0 ) );

fsm.changeState( "playing" );
engine.addEntity( spaceshipEntity );
```

Later in a system (i.e. collision system)
```java
Spaceship ss = spaceshipEntity.getComponent(Spaceship.class);
ss.fsm.changeState( "destroyed" );
```

To do:
- jdoc
- Add new tests