public interface State extends Updatable
In other word, gameplay can be represented as a finite state machine. This will ensure gameplay state validity, instead of checking tons of boolean to catch the right state.
The only counter part is the number of class, which is usually one class per state. So typically, for a simple
gameplay (Idle, Walk, Jump
), it will need 3 state classes, plus the StateFactory
.
Usage is quite simple:
enter()
one time on the state (reset default state and prepare for update)Updatable.update(double)
the state for each game loopStateFactory
will allow to choose which state should be then returned if needed, and enter()
will be called, and so on
It is possible to listen to InputDevice
, by implementing children of StateInputUpdater
.
StateTransition
,
StateHandler
,
StateFactory
,
StateInputUpdater
Modifier and Type | Method and Description |
---|---|
void |
addTransition(StateTransition transition)
Add a transition with another state.
|
Enum<?> |
checkTransitions(InputDevice input)
Check the transitions in order to find the next state.
|
void |
clearTransitions()
Clear all transitions defined.
|
void |
enter()
Called by the
StateFactory when entering in the state. |
void |
exit()
Called by the
StateHandler when exiting the state. |
Enum<?> |
getState()
Get the corresponding state enum value.
|
void addTransition(StateTransition transition)
transition
- The transition to add.void clearTransitions()
void enter()
StateFactory
when entering in the state.void exit()
StateHandler
when exiting the state.Enum<?> checkTransitions(InputDevice input)
input
- The input device reference.null
if none).Enum<?> getState()
Copyright © 2017 Byron 3D Games Studio. All rights reserved.