🏛️ Object-Oriented Programming

Instantiation & Objects

Project Evidence Required
Instantiate game objects in GameLevel configuration.
Assessment Method
Code review: GameLevel setup objects

What it is

Instantiation is the act of creating a real, running instance from a class blueprint — done via the new keyword. Object literals ({ key: value, ... }) are JavaScript’s most compact way to bundle configuration data, and they’re what we pass to constructors to customize each instance.

Why it matters

A class is just a blueprint until something instantiates it. In game development, instantiation is where the abstract becomes concrete — where a Player class definition becomes the actual octopus on screen. Doing it via object literals (data-driven design) means designers can change the game by editing data instead of code.

How GateGame implements it

In GameLevelMazeSub, I built a this.classes array of object literals. Each entry pairs a class with its data: { class: Player, data: sprite_data_octopus }. The engine walks this array and instantiates each entry at level load. To add a new enemy, I append one more object literal — no engine changes required.

Code Example

this.classes = [
  { class: GameEnvBackground, data: image_data_cave   },
  { class: Player,            data: sprite_data_octopus },
  { class: SplineBarrier,     data: seg1               },
  { class: SplineBarrier,     data: seg2               },
  { class: Coin,              data: sprite_data_coin   },
  { class: Npc,               data: sprite_data_shadow },
  { class: Npc,               data: sprite_data_warden },
];

Key Takeaway

Object literals + an array of {class, data} pairs = a level you can redesign by editing data, not engine code.