It's impossible to keep track of every single entity's state in a game with just if and else branches.
The concept of Finite State Machines solves the complexity of keeping track of states within a game. A state machine takes a set of inputs and responds to those inputs by changing its state.
A character can either be Idle, Walk, Jump
What are the rules for Finite State Machines?
- There are a fixed number of states (a character can only walk, jump or be idle)
- Can only be in one state at a time (you cant be idle and walk at the same time)
- Can only be responsible for one thing (jump state lets you jump only, walk state lets you walk only)
- Active state receives input then responds
This flowchart is a State Machine:
