Back to Tools
Coding

Game Programming Patterns

By Robert Nystrom

Robert Nystrom’s game-code patterns, with a practical starting point in state machines.

guide
An original four-state diagram connects standing, jumping, ducking and diving with labelled input and landing transitions.
Original conceptual example inspired by the State chapter, not a reproduction of its diagram. Additional game rules may require different states or transitions. Original explanatory artwork prepared for GameSlash with AI assistance. Documentation is the factual source only; no source imagery reused. Not an official screenshot or gameplay capture. Concept source

Use it for: Character flags that contradict each other, or gameplay code that is hard to change safely.

Start: 1) Read State. 2) Draw standing, jumping, ducking and diving transitions. 3) Try an enum before introducing separate state classes.

Conflicting independent standing and jumping flags are contrasted with one active JUMPING state in a mutually exclusive state list.
Original data-model illustration. Separate independent dimensions can still use separate state machines when appropriate. Original explanatory artwork prepared for GameSlash with AI assistance. Documentation is the factual source only; no source imagery reused. Not an official screenshot or gameplay capture. Concept source

Try checking: Repeated jump presses in mid-air and releasing duck during a jump should not create contradictory states or graphics.

Limits: Examples omit details and teach concepts, not production-ready code or modern C++ style. Reading does not require building the book.

Source: State

Source: Introduction

View source