Reference Source Test
public class | source

Entities

Entities in the game:

  • Character - parent class for:
    • Mob - game controlled npc or monster that can move around the map
    • Npc - game controlled entity that always stays in one location
    • Player - a user in the game
  • Chest - open to reveal an item
  • Item - weapons, health, magic, armor
  • Projectile - entities that can be thrown (magic, weapons, arrows, mob attacks)

Constructor Summary

Public Constructor
public

constructor(instance: Game)

Default constructor

Member Summary

Public Members
public

Keeps track of entities that need to be cleaned up

public

An array of an entity type instances

public

The instance of the game

public

An array of game grid maps

public

An instance of the game renderer

public

An array of sprites

Method Summary

Public Methods
public

addEntity(entity: Chest | NPC | Item | Mob | Projectile | Player): *

Add a new entity to the map grid

public

clearPlayers(exception: {id: Number, type: String}): *

Removes players from the game map, will only work for entities of type player

public

create(info: {id: Number, type: 'chest'|'npc'|'item'|'mob'|'projectile'|'player'}): *

Create a new entity

public

Check to see if an entity with this ID exists or not

public

forEachEntity(callback: Function): *

Apply a callback for every entity in the array

public

forEachEntityAround(x: Number, y: Number, radius: Number, callback: Function): *

Apply a callback for every entity in the radius of an area on the map grid as long as the radius is not out of bounds in the grid

public

Returns the entity object based off the ID if it exists, otherwise returns null

public

getAll(): *

Return all entities

public

Return all the sprites with the given name

public

Checks whether or not this entity ID is a player

public

Load the entities in the game for the current game map

public

Register this entity on the grid twice

public

registerPosition(entity: Chest | NPC | Item | Mob | Player): *

Figure out which part of the grid to add an entity to

public

removeItem(item: *): *

Remove an item from the game

public

Remove this entity from the game map

public

update(): *

Update the sprites

Public Constructors

public constructor(instance: Game) source

Default constructor

Params:

NameTypeAttributeDescription
instance Game

of the game

Public Members

public decrepit: Chest | NPC | Item | Mob | Projectile | Player source

Keeps track of entities that need to be cleaned up

public entities: Chest | NPC | Item | Mob | Projectile | Player source

An array of an entity type instances

public game: Game source

The instance of the game

public grids: Grids source

An array of game grid maps

public renderer: Renderer source

An instance of the game renderer

public sprites: Sprites source

An array of sprites

Public Methods

public addEntity(entity: Chest | NPC | Item | Mob | Projectile | Player): * source

Add a new entity to the map grid

Params:

NameTypeAttributeDescription
entity Chest | NPC | Item | Mob | Projectile | Player

the entity to add to the game

Return:

*

null

public clearPlayers(exception: {id: Number, type: String}): * source

Removes players from the game map, will only work for entities of type player

Params:

NameTypeAttributeDescription
exception {id: Number, type: String}

entitys (players) to keep on the game map

Return:

*

null

public create(info: {id: Number, type: 'chest'|'npc'|'item'|'mob'|'projectile'|'player'}): * source

Create a new entity

Params:

NameTypeAttributeDescription
info {id: Number, type: 'chest'|'npc'|'item'|'mob'|'projectile'|'player'}

information about the entity we need to create

Return:

*

null

public exists(id: Number): Boolean source

Check to see if an entity with this ID exists or not

Params:

NameTypeAttributeDescription
id Number

the id of the entity

Return:

Boolean

true if it exists, otherwise false

public forEachEntity(callback: Function): * source

Apply a callback for every entity in the array

Params:

NameTypeAttributeDescription
callback Function

the function to apply, the entity is passed into it

Return:

*

null

public forEachEntityAround(x: Number, y: Number, radius: Number, callback: Function): * source

Apply a callback for every entity in the radius of an area on the map grid as long as the radius is not out of bounds in the grid

Params:

NameTypeAttributeDescription
x Number

the x coordinate center of the circle radius

y Number

the y coordinate center of the circle radius

radius Number

the the distance to spread out from the center of the circle point

callback Function

the function to apply, the entity is passed into it

Return:

*

null

public get(id: Number): Chest | NPC | Item | Mob | Projectile | Player | null source

Returns the entity object based off the ID if it exists, otherwise returns null

Params:

NameTypeAttributeDescription
id Number

the id of the entity

Return:

Chest | NPC | Item | Mob | Projectile | Player | null

public getAll(): * source

Return all entities

Return:

*

public getSprite(name: String): Chest | NPC | Item | Mob | Projectile | Player source

Return all the sprites with the given name

Params:

NameTypeAttributeDescription
name String

the name of the sprite

Return:

Chest | NPC | Item | Mob | Projectile | Player

public isPlayer(id: Number): Boolean source

Checks whether or not this entity ID is a player

Params:

NameTypeAttributeDescription
id Number

the id of the entity

Return:

Boolean

public loadEntities(): * source

Load the entities in the game for the current game map

Return:

*

null

public registerDuality(entity: Chest | NPC | Item | Mob | Projectile | Player): * source

Register this entity on the grid twice

Params:

NameTypeAttributeDescription
entity Chest | NPC | Item | Mob | Projectile | Player

the entity to add to the game map again

Return:

*

null

public registerPosition(entity: Chest | NPC | Item | Mob | Player): * source

Figure out which part of the grid to add an entity to

Params:

NameTypeAttributeDescription
entity Chest | NPC | Item | Mob | Player

an entity in the game

Return:

*

null

public removeItem(item: *): * source

Remove an item from the game

Params:

NameTypeAttributeDescription
item *

the item to remove from the map grid

Return:

*

null

public unregisterPosition(entity: Chest | NPC | Item | Mob | Projectile | Player): * source

Remove this entity from the game map

Params:

NameTypeAttributeDescription
entity Chest | NPC | Item | Mob | Projectile | Player

the entity to remove from the grid

Return:

*

null

public update(): * source

Update the sprites

Return:

*

null