Code of the Day
AdvancedGame Design Patterns

Lab: game design patterns

Apply the observer pattern, component architecture, and spatial hashing to realistic game design decisions.

Lab · optionalGame DevAdvanced10 min
Recommended first
By the end of this lesson you will be able to:
  • Choose between observer, polling, and direct coupling for event handling
  • Decide when to use component architecture over inheritance
  • Recognise when spatial hashing is the right optimisation for collision

Optional scenario lab. Design patterns are judgment calls — knowing the pattern is only half the job. Practice recognising which one fits a situation and why.

Scenarios: game design patterns

  1. 1.
    A player picks up a coin. The score UI, the sound system, and the achievement system all need to react. You don't want the player object to know about any of them directly. Best approach?
  2. 2.
    You have Player, Enemy, and NPC entities that all need health, but only Player needs input handling and only Enemy needs AI. Using inheritance, GameObjectLivingThingPlayer quickly becomes tangled. Better approach?
  3. 3.
    Spatial hashing is worth implementing for any game that has collision detection, regardless of entity count.
  4. 4.
    In a spatial hash, you set the cell size much smaller than your largest entity. What problem does this cause?
  5. 5.
    Your game's UI needs to update every time the player's HP changes. HP changes happen in the physics update, in the damage system, and via power-ups. Which pattern fits best?

The pattern-selection habit: observer when many systems react to one event; components when entities need mix-and-match capabilities; spatial hashing when brute-force collision becomes the bottleneck. A pattern applied where it doesn't fit costs more than it saves.

Finished reading? Mark it complete to track your progress.