🎮 Input / Output

GameEnv Configuration

Project Evidence Required
Set canvas size, difficulty levels, game settings.
Assessment Method
Code review: GameEnv.create() and GameSetup.js

What it is

GameEnv is the engine’s central configuration object. It holds the canvas reference, dimensions, gravity, difficulty settings, and a debug flag. Every game object holds a reference to it via the gameEnv parameter passed through super().

Why it matters

Centralizing configuration means one edit changes the whole game’s behavior. Without a central env, every class would need its own copy of constants like canvas width, and changing the difficulty would require touching dozens of files.

How GateGame implements it

The GameLevelMazeSub constructor receives gameEnv and forwards it to super(gameEnv) so the base level can bind it. Every entity in this.classes receives the same gameEnv when instantiated. Inside entities, code like this.gameEnv.canvas.width reads the live canvas size, so layouts scale automatically if the canvas is resized.

Code Example

class GameLevelMazeSub extends GameLevel {
  constructor(gameEnv) {
    super(gameEnv);                  // forward gameEnv to base
    const width  = gameEnv.canvas.width;   // read canvas dims
    const height = gameEnv.canvas.height;
    // ... use width/height in spline() calls
  }
}

Key Takeaway

One env object, threaded through every constructor via super(data, gameEnv), gives the whole game a single source of truth for configuration.