API Docs for:
Show:

MultiObjectManager Class

Manages a list of object and their tile positions. Multiple objects can be at a given tile map coord. Handles adding, removing, moving objects within the game.

Constructor

MultiObjectManager

(
  • game
  • ObjectConstructor
  • [width]
  • [height]
)

Parameters:

  • game Game
    • Game instance this MultiObjectManager is attached to.
  • ObjectConstructor Object
    • Object constructor used to create new objects with this.add().
  • [width] Number optional
    • Width of current map in tiles.
  • [height] Number optional
    • Height of current map in tiles.

Methods

add

(
  • x
  • y
  • obj
)
Object

Adds an object to the manager at given map tile coord. Multiple objects can be added to the same coord.

Parameters:

  • x Number
    • Map tile coord x.
  • y Number
    • Map tile coord y.
  • obj Object | String
    • The Object being set at given coords. If obj is a string a new Object will be created using this.makeNewObjectFromType(obj).

Returns:

Object:

The added object.

get

(
  • x
  • y
  • [filter]
)
Array

Retrieves all objects at given map tile coord.

Parameters:

  • x Number
    • The tile map x coord.
  • y Number
    • The tile map y coord.
  • [filter] Function optional
    • A function to filter the array of objects returned function(object){ return true }.

Returns:

Array:

getAdjacent

(
  • x
  • y
  • [settings]
)
Array

Same as this.map.getAdjacent, but merges all results into on flat array.

Parameters:

  • x Number
    • Map tile x coord.
  • y Number
    • Map tile y coord;
  • [settings] Object optional

Returns:

Array:

getFirst

(
  • x
  • y
  • [filter]
)
Object

Retrieves the first object in array at given map tile coord.

Parameters:

  • x Number
    • The tile map x coord.
  • y Number
    • The tile map y coord.
  • [filter] Function optional
    • A function to filter the object returned at this map tile coord function(object){ return true }. The first object in the array the filter matches is returned.

Returns:

Object:

getLast

(
  • x
  • y
  • [filter]
)
Object

Retrieves the last object in array at given map tile coord.

Parameters:

  • x Number
    • The tile map x coord.
  • y Number
    • The tile map y coord.
  • [filter] Function optional
    • A function to filter the object returned at this map tile coord function(object){ return true }. The last object in the array the filter matches is returned.

Returns:

Object:

loadEntitiesFromArrayString

(
  • mapData
  • charToType
  • [defaultType]
)

Loads Obj data from an array of strings.

Parameters:

  • mapData Array
    • The array of strings to load.
  • charToType Object
    • An object mapping string characters to Obj types (see Obj.Types[type]). Characters in mapData not in charToType are ignored.
  • [defaultType] String optional
    • If set, all characters in mapData not found in charToType will be replaced by an object with defaultType.

Example:

       var mapData = [
           '####',
           '#..#',
           '#.Z#',
           '####',
       ],
       charToType = {
           'Z': 'zombie'
       };

       entityManager.loadTilesFromArrayString(mapData, charToType);

makeNewObjectFromType

(
  • type
)
Object

Creates a new object instance.

Parameters:

  • type String
    • The type to make the object

Returns:

Object:

move

(
  • x
  • y
  • object
)

Changes the position of an entity already added to this entityManager.

Parameters:

  • x Number
    • The new map tile coordinate position of the entity on the x axis.
  • y Number
    • The new map tile coordinate position of the entity on the y axis.
  • object Obj
    • The objectity to be removed.

remove

(
  • obj
)

Removes an entity from the manager.

Parameters:

  • obj Obj
    • The objity to be removed.

removeAt

(
  • x
  • y
  • [filter]
)

Remove all objects from given location.

Parameters:

  • x Number
    • Tile map x coord.
  • y Number
    • Tile map y coord.
  • [filter] Function optional
    • A function to filter the objects removed function(object){ return true }.

reset

()

Resets this entityManager.

setSize

(
  • width
  • height
)

Sets the size of the map to manage objects within.

Parameters:

  • width Number
    • Width of current map in tiles.
  • height Number
    • Height of current map in tiles.

update

(
  • [excludeObject]
)

Calls the object.update() method on all objects. Removes object.dead == true objects. Typically called after a player has resolved their actions. Not all object managers need to upade the objects they manage.

Parameters:

  • [excludeObject] Object optional
    • excludeObject will be skipped if found in this.objects.

Properties

game

Game

Game instance this obj is attached to.

map

Array2d

Array2d containing all objects by their current map tile coord

objects

Array

Array containing all objects.