Pause, menus and game states
The plumbing that makes a prototype feel like a game.
Add proper state handling to my game: <paste the loop> States: menu, playing, paused, game over. One `mode` field, and both update and draw switch on it. - Pause on Escape and on the window losing focus — a tab switch must not run the game invisibly. - Paused freezes update but keeps drawing, with an overlay. - Game over shows the score and restarts without a page reload. - Restart resets state cleanly. Tell me what has to be reset that's easy to miss — timers, event listeners, spawned entities. Menu and game over must be keyboard and touch navigable, not click-only.
Pausing on blur is the one people forget. A player who alt-tabs for two minutes should not come back to a dead character.