Noah2610 / deathfloor

Work-in-progress Mega Man inspired game.
MIT License
2 stars 0 forks source link

Entity Lifecycle #27

Closed Noah2610 closed 4 years ago

Noah2610 commented 4 years ago

Introduce a Lifecycle component for entities. Instead of having event actions such as OnSpawn and OnDeath, tie those into an entity's lifecycle.

enum Lifecycle {
    Initial,
    Spawn,
    Alive,
    Death,
    Despawn,
}

Brief lifecycle state descriptions

Initial

he default / initial state; ASAP it should switch to Spawn.

Spawn

It would stay in Spawn for at least 1 frame, before switching to Alive. Can be prolonged.

Alive

The entity will remain in Alive, until its Health drops to 0; then switches to Death. If the entity has no Health component, then it will stay alive forever (for now).

Death

Remain in Death for at least 1 frame, then switch to Despawn. Can be prolonged.

Despawn

When in Despawn, the entity should be deleted.

Prolonging a lifecycle state

Spawn and Death states can be prolonged for one or more frames. By calling a method (Lifecycle::prolong?) on the component.

Events/actions tie-in

Instead of having event actions such as OnSpawn or OnDeath, have an action such as Lifecycle, which takes a lifecycle state as its unnamed field and runs the action for each frame that the specified state is active.

Example config

events: {
    Lifecycle(Spawn): Echo("Hello World!"),
    Lifecycle(Alive): Echo("Still alive..."), // called every frame while Alive
    Lifecycle(Death): Echo("Farewell cruel world."),
},