🏛️ Object-Oriented Programming

Writing Classes

Project Evidence Required
Create minimum 2 custom character classes extending base classes.
Assessment Method
Code review: Player.js, NPC.js, Enemy.js

What it is

A class in JavaScript is a blueprint for creating objects with shared state and behavior. ES6 introduced the class keyword, which provides a clean syntax for defining constructors, instance properties, and methods. Every object created from a class is called an instance.

Why it matters

In a game you often have many entities of the same type — multiple enemies, multiple platforms, multiple NPCs. Without classes you would copy-paste the same setup code dozens of times. Classes let you write the shared logic once and stamp out instances cheaply.

How GateGame implements it

In the Maze of Shadows sublevel, I worked with three custom classes — Player, Npc, and SplineBarrier — each extending a base engine class. Each class encapsulates its sprite data, animation frames, and behavior in one file. The GameLevelMazeSub class itself extends GameLevel, giving us a clean hierarchy from level down to individual entity. This satisfies the 2+ custom classes requirement with three concrete implementations.

Code Example

// Three custom classes instantiated in GameLevelMazeSub
{ class: Player, data: sprite_data_octopus },
{ class: Npc,    data: sprite_data_shadow  },
{ class: Npc,    data: sprite_data_lantern },
{ class: SplineBarrier, data: seg1 },

Key Takeaway

Classes turn repetitive setup into a reusable pattern. Three custom classes in this level → every new enemy is one small subclass away.