Introducing state machines
Games, web applications, heck, even cryptocurrency miners, have to manage the state of the system. After all, if the system isn't doing something right now, if it doesn't have a current state, then it's not running, is it? The state is also fractal. In our game, we have a state of playing
, and another one of game over
. Once we add menu items, we'll have even more states. Meanwhile, our RHB also has states: he's running, sliding, jumping, dying, and dead. Let's say unconscious, that's less dark.
The point is our game is doing a lot of things and is maintaining a large game state with a lot of mini-states inside it. As the application moves from one state to another, the rules of the system change. For example, when RHB is running, the spacebar might make him jump, but when he's jumping, hitting the spacebar doesn't do anything. The rule is you can't jump when you're already jumping. One way you can...