State machines
A video game, more than any other type of application, bases much of its logic on whether the game or entities in that game are currently in one of a number of different states.
This could be checking whether the game is in the intro scene, running in the main gameplay mode, the player has died, the player is idle, a boss enemy has appeared, the game is over, the stage is over, the boss is low on health, and much more.
In the past, it has always been common practice for game developers to write their own custom state machine logic from scratch and then use the update/render cycle to check on these various states. Typically this would be done in a custom class or simply in a custom-made enum object that will shift through various states, such as .GameOver
, .MainGame
, .LowHealth
, and so on. These states could also describe the status of an individual entity in our game and dictate which animation cycle to run...