Unit 1 · Game loops and real-time systems
A game usually has modes such as title, playing, paused, and game over. A state enum gives those modes names and prevents unrelated booleans from creating impossible combinations such as “paused and title screen” at the same time.
enum GameState { TITLE, PLAYING, PAUSED, GAME_OVER }
GameState state = GameState.TITLE;
void update(Input input, double delta) {
switch (state) {
case TITLE -> { if (input.startPressed()) state = GameState.PLAYING; }
case PLAYING -> updateWorld(input, delta);
case PAUSED -> { if (input.pausePressed()) state = GameState.PLAYING; }
case GAME_OVER -> { if (input.startPressed()) reset(); }
}
}Transitions should have clear triggers. Entering PAUSED may stop simulation time while keeping the render active. Leaving GAME_OVER should reset the minimum required world state, not rely on stale objects.
1. What is a state transition?
2. Why should paused gameplay stop simulation updates?
3. What is an impossible state combination?
A strong design uses one GameState value, transition triggers such as start, pause, player death, and restart, and a table that documents entry and exit effects. During pause, render and menu input continue, while world simulation, timers, and enemy AI stop.