Entity Class
Represents an entity in the game. Usually a character or enemy. Manages state (position, health, stats, etc) Occupies a single game map tile.
Constructor
Entity
-
game
-
type
Parameters:
-
game
Game- Game instance this obj is attached to.
-
type
String- Type of entity. When created this object is merged with the value of Entity.Types[type].
Item Index
Methods
bump
-
entity
Handles the behavior of a player or other entity attempting to move into the tile coord this entity is currently occupying.
Returns:
true if bumping this entity completes the action of the bumping entity.
canMoveThrough
-
x
-
y
Checks if an entity can move through a map tile. Convenience method for this.game.canMoveThrough()
Parameters:
-
x
Number- The tile map x coord to check if this entity can move to.
-
y
Number- The tile map y coord to check if this entity can move to.
Returns:
canMoveTo
-
x
-
y
Checks if an entity can move through and into a map tile and that tile is un-occupied. Convenience method for this.game.entityCanMoveTo()
Parameters:
-
x
Number- The tile map x coord to check if this entity can move to.
-
y
Number- The tile map y coord to check if this entity can move to.
Returns:
canSeeThrough
-
x
-
y
Checks if a map tile can be seen through. Convenience method for this.game.entityCanSeeThrough()
Parameters:
-
x
Number- The x map tile coord to check.
-
y
Number- The y map tile coord to check.
Returns:
getTileDrawData
()
TileDrawData
Returns as tileData
object used by Renderer
objects to draw tiles.
Returns:
init
-
game
-
type
Called when the entity is first created. Intended to be assigned by Entity.Types.
Parameters:
-
game
Game- Game instance this obj is attached to.
-
type
String- Type of entity. When created this object is merged with the value of Entity.Types[type].
moveTo
-
x
-
y
Changes the position of this entity on the map. Convenience method for this.game.entityMoveTo() this.canMoveTo() and/or this.canMoveThrough() should always be checked before calling this.moveTo()
Parameters:
-
x
Number- The tile map x coord to move to.
-
y
Number- The tile map y coord to move to.
update
()
Called after a player action has been resolved. Resolves this entities turn.
Properties
bgColor
String | Bool
The background color the character displayed when rendering this entity. Not rendered if false.
char
String
The character displayed when rendering this entity.
color
String | Bool
The color of the character displayed when rendering this entity. Not rendered if false.
dead
Bool
Determines if this entity has been killed and needs to be removed.
name
String
Name used when referencing or describing this entity. Used in console messages.
type
String
The type of entity this is. When created this object is merged with the value of Entity.Types[type].
x
Number
The x map tile coord of this entity.
y
Number
The y map tile coord of this entity.