🔁 Control Structures

Conditionals

Project Evidence Required
Implement collision detection and state transitions.
Assessment Method
Code review: if/else, nested conditions

What it is

Conditionals — if, else if, else — branch program execution based on whether an expression evaluates to truthy or falsy. They’re the most fundamental control structure in any imperative language.

Why it matters

Every decision the game makes is a conditional. Did the player land on a platform or fall through? Is the NPC in dialogue range? Is the level complete? Each is an if. Without conditionals, the game has no choices, no reactions, no logic.

How GateGame implements it

Conditionals run constantly throughout Maze of Shadows. They check whether the player has collided with a SplineBarrier, whether dialogue is currently open, whether the Exit Warden’s collision triggers the level-transition prompt, and which button (Step Through vs Not yet) the player clicked.

Code Example

// Conditional inside the level-iteration loop
for (const obj of this.classes) {
  if (obj.class === Npc) {           // class match
    if (obj.data.interact) {         // method exists
      obj.data.interact();           // safe to call
    }
  }
}

Key Takeaway

Conditionals are the moments the game makes a choice. Every interactive game is, structurally, a tree of ifs.