Sonolus Wiki

02. Archetypes and Entities

In this chapter, we will go over the concept of archetypes and entities.

Archetypes

Archetypes are abstractions of entities, defined by engine.

In this guide, our engine will have four archetypes: Initialization, Input Manager, Stage, and Note. Initialization archetype is responsible for initializing the level; Input Manager is responsible for managing player inputs; Stage archetype is responsible for managing interactions and rendering of the stage; lastly, Note archetype is responsible for managing interactions and rendering of notes.

Note that an archetype represents an abstraction of such entities. For example, there may be 100 notes in a level, and they may differ in ways such as spawning and requiring player to hit at different times, however they are all instances of the same Note archetype.

In object oriented programming, an archetype would be a class.

Using Sonolus.js, an archetype is represented by a JS class, for example the Stage class that comes with the project template:

export class Stage extends Archetype {
    spawnOrder() {
        return 1
    }

    shouldSpawn() {
        return entityInfos.get(0).state === EntityState.Despawned
    }

    updateParallel() {
        debug.log(time.now)
    }
}
export class Stage extends Archetype {
    spawnOrder() {
        return 1
    }

    shouldSpawn() {
        return entityInfos.get(0).state === EntityState.Despawned
    }

    updateParallel() {
        debug.log(time.now)
    }
}

Entities

Entities are instances of archetypes, defined by level.

Multiple levels may use the same engine, and different gameplay is achieved by defining different entities. For example, one level may have one entity of Initialization archetype, one entity of Stage archetype, 50 entities of Note archetype; another level may have mostly the same, except 100 entities of Note archetype.

In object oriented programming, an entity would be an instance of a class.

The main purpose of Sonolus.js is for engine scripting, not for creating levels. In this guide we will have a test level prepared to test out the engine, but it is not the focus of the guide.