OOP is the way I learned to stop writing one giant script and start thinking in things. Every character, enemy, and item in my game is its own object — with its own data and its own behavior — and they all share traits through a family tree of classes.
Click any class to read about it. The path it inherits from will light up.
GameObject
Character
Player
Guard

Pick a class above to see its properties.

  1. Writing Classes. A class is a blueprint or template used to create objects. It defines the initial state (properties like health or position) and the behaviors (methods like move or attack) that all objects created from that blueprint will have. It allows you to organize your code into logical, reusable structures.
  2. Methods & Parameters. Methods are functions that live inside a class and represent the actions an object can take. Parameters are the placeholders that allow you to pass specific information into those methods. For example, a jump(height) method uses the height parameter to determine exactly how high that specific jump should be.
  3. Instantiation & Objects. Instantiation is the act of creating a living "copy" of a class in your game's memory. While the class is just the blueprint, the Object is the actual house built from it. You can instantiate five different "Enemy" objects from one "Enemy" class, and each can have its own unique health and position during gameplay.
  4. Method Overriding. This occurs when a Child class provides a specific implementation of a method that is already defined in its Parent class. For example, if the Parent Enemy has a generic attack() method, the Child Boss can "override" it to perform a much more powerful special attack instead of the default one.
  5. Constructor Chaining. The constructor is a special method that runs automatically when an object is created. Chaining involves using the super() keyword to ensure that the Parent's constructor runs before the Child's constructor logic. This ensures the object is properly set up with all basic "Parent" traits before the "Child" adds its unique features.
Click a pillar to switch tabs.

Encapsulation

A class keeps its data and methods together as one unit, so the rest of the code can't reach in and change things by accident. Each object holds onto its own state.

this.type = "Guard";
this.isHostile = true;

Inheritance

A new class can build on top of an existing one. When I write class Pirate extends Character, my Pirate already knows how to move, fall, and render — it gets all of that from Character. I only have to write what makes a Pirate different.

class Guard extends Character { ... }

Polymorphism

Several classes can share the same method name and each respond in their own way. Every character has a handleCollision(), but a Pirate handles it differently — by reacting when the Player gets too close.

handleCollision(other, direction) {
    if (other instanceof Player) {
        if (this.distanceTo(other) < 50) {
            this.reaction("hostile");
        }
    }
}

Abstraction

When I call super.update(), all of the parent's physics, animation, and movement run in one line, and I don't have to think about how any of it works. I just add what's unique to my class on top.

update() {
    super.update();        // parent logic runs here
    this.checkProximity(); // pirate-specific behavior
}
Concept
Keyword
What it gives you
Encapsulation
this.
Self-contained objects
Inheritance
extends
Reusable parent logic
Polymorphism
method override
Custom behavior per class
Abstraction
super()
Simplified interface to complex logic
  • extends is the keyword a child class uses to reuse a parent's properties and methods.
  • A class is a blueprint; an object is a real instance built from that blueprint.
  • When a child class replaces a parent's method with its own version, that's polymorphism.
  • super() runs the parent's constructor first so the child inherits its setup before adding its own.