class Actor: Entity

Entities in the game, including the player, enemies, and items. Actors are composed of Components that define their state and behavior. For example, an actor may have a Sight component that determines their field of vision, explored tiles, and other related aspects.

level: Level?

The level the actor is on.

__new(self: Actor)

Constructor for an actor. Initializes and copies the actor’s fields from its prototype.

initialize(self: Actor): Component[]

Creates the components for the actor. Override this.

staticmethod fromComponents(components: Component[]): (actor: Actor)

Initializes an actor from a list of components.

Parameters:

components (Component[]) – A list of components to give to the new actor.

Returns:

actor (Actor) – The new actor.

getActions(self: Actor): (totalActions: Action[])

Get a list of actions that the actor can perform.

Returns:

totalActions (Action[]) – A table of all actions.

getPosition(self: Actor, out?: Vector2): (position?: Vector2)

Returns the current position of the actor

Parameters:

out? (Vector2) – An optional out parameter. A new Vector2 will be allocated in its absence.

Returns:

position? (Vector2) – Returns a copy of the actor’s current position.

expectPosition(self: Actor, out?: Vector2): (position: Vector2)

Returns the current position of the actor, erroring if it doesn’t have one.

Parameters:

out? (Vector2) – An optional out parameter.

Returns:

position (Vector2) – The actor’s current position.

getRange(
    self: Actor,
    actor: Actor,
    type?: "4way" | "8way" | "chebyshev" | "euclidean" | "manhattan"
): (range: number)

Get the range from this actor to another actor. Expects position on both actors and errors otherwise.

Parameters:
  • actor (Actor) – The other actor to get the range to.

  • type? ("4way" | "8way" | "chebyshev" | "euclidean" | "manhattan") – Optional distance type.

Returns:

range (number) – The calculated range.

getRangeVec(
    self: Actor,
    vector: Vector2,
    type?: "4way" | "8way" | "chebyshev" | "euclidean" | "manhattan"
): (range: number)

Get the range from this actor to a given vector.

Parameters:
  • vector (Vector2) – The vector to get the range to.

  • type? ("4way" | "8way" | "chebyshev" | "euclidean" | "manhattan") – The type of range calculation to use.

Returns:

range (number) – The calculated range.