API Docs for:
Show:

Map Class

Extends Array2d
Defined in: src/map.js:4

Manages map Tiles. Depends on Array2d (array-2d.js).

Constructor

Map

(
  • game
)

Defined in src/map.js:4

Parameters:

  • game Game
    • Game instance this obj is attached to.

Methods

canMoveThroughTile

(
  • x
  • y
)
Bool

Defined in src/map.js:56

Checks if a map tile can be moved through.

Parameters:

  • x Number
    • The x map tile coord to check.
  • y Number
    • The y map tile coord to check.

Returns:

Bool:

canSeeThroughTile

(
  • x
  • y
)
Bool

Defined in src/map.js:44

Checks if a map tile can be seen through.

Parameters:

  • x Number
    • The x map tile coord to check.
  • y Number
    • The y map tile coord to check.

Returns:

Bool:

copy

() Array2d

Inherited from Array2d: src/array-2d.js:437

Creates a copy of this Array2d. Shallow copies values.

Returns:

each

(
  • func
  • [context]
)
Array2d

Inherited from Array2d: src/array-2d.js:455

Loops over each coord value.

Parameters:

  • func Function
    • A function to call on each coord value. (function(value, x, y){})
  • [context] Object optional
    • Context to call the function with (func.call(context, val, x, y))

Returns:

filter

(
  • filter
  • [withCoords=false]
)
Array

Inherited from Array2d: src/array-2d.js:408

Retrieves an array of the filtered values.

Parameters:

  • filter Function
    • A function to determine if a value is to be included in results (returns true). (function(value, x, y){ return true;})
  • [withCoords=false] Bool optional
    • If true the returned array will include the coords of each value ([{x: 0, y: 0, value: 1}, ...])

Returns:

Array:

An array of coord values matched by the filter function.

get

(
  • x
  • y
)
Mixed

Inherited from Array2d: src/array-2d.js:89

Gets a value from given coords.

Parameters:

  • x Number
    • Map tile x coord of the value being retrieved.
  • y Number
    • Map tile y coord of the value being retrieved.

Returns:

Mixed:

getAdjacent

(
  • x
  • y
  • [settings]
)
Array

Inherited from Array2d: src/array-2d.js:113

Retrieves an array of values of adjacent coords.

Parameters:

  • x Number
    • Map tile x coord to get adjacent values of.
  • y Number
    • Map tile y coord to get adjacent values of.
  • [settings] Object optional

    -

    • [withCoords=false] Bool optional
      • If true the returned array will include the coords of each value ([{x: 0, y: 0, value: 1}, ...])
    • [withDiagonals=true] Bool optional
      • If true diagonals will be included.
    • [filter=false] Function optional
      • A function to filter the values returned (function(value, x, y){ return true;})

Returns:

Array:

An array of adjacent coord values.

getLineThrough

(
  • x0
  • y0
  • x1
  • y1
  • [condition=false]
  • [withCoords=false]
)
Array

Inherited from Array2d: src/array-2d.js:258

Retrieves an array of values of coords along a line starting at point 0 and crossing point 1 until it hits the edge of the 2d array or a coord value returning true when passed to the condtion function.

Parameters:

  • x0 Number
    • Map tile x coord of start.
  • y0 Number
    • Map tile y coord of start.
  • x1 Number
    • Map tile x coord of crossing.
  • y1 Number
    • Map tile y coord of crossing.
  • [condition=false] Function optional
    • A function to determine when to end the line. A coord value returning true when passed to the function will end the line. (function(value, x, y){ return true;})
  • [withCoords=false] Bool optional
    • If true the returned array will include the coords of each value ([{x: 0, y: 0, value: 1}, ...])

Returns:

Array:

An array of coord values.

getNearest

(
  • tileX
  • tileY
  • [settings]
)
Array

Inherited from Array2d: src/array-2d.js:313

Retrieves an array of the nearest coord values meeting checked requirements. If multiple coord values were matched at the same nearest distance, the returned array will contain multiple matched coord values. Used for projecting path of ranged attacks, pushed entities, ect.

Parameters:

  • tileX Number
    • Map tile x coord of the center of the radius.
  • tileY Number
    • Map tile x coord of the center of the radius.
  • [settings] Object optional

    -

    • [maxRadius=1] Number optional
      • Maxium search radius from given coord.
    • [filter=false] Function optional
      • A function to determine when the desired coord value is matched. A coord value returning true when passed to the function would be added to the list of results. (function(value, x, y){ return true;}) If no check function is provided any tile with a truthy value will be matched.
    • [withCoords=false] Bool optional
      • If true the returned array will include the coords of each value ([{x: 0, y: 0, value: 1}, ...])

Returns:

Array:

An array of coord values within a square radius of the given coords.

getWithinSquareRadius

(
  • x
  • y
  • [settings]
)
Array

Inherited from Array2d: src/array-2d.js:194

Retrieves an array of values of coords within a given radius.

Parameters:

  • x Number
    • Map tile x coord at the center of the radius.
  • y Number
    • Map tile x coord at the center of the radius.
  • [settings] Object optional

    -

    • [radius=1] Number optional
      • Radius of the area to retrieve tiles from.
    • [filter=false] Function optional
      • A function to filter the values returned (function(value, x, y){ return true;})
    • [withCoords=false] Bool optional
      • If true the returned array will include the coords of each value ([{x: 0, y: 0, value: 1}, ...])
    • [includeTarget=false] Bool optional
      • If true the value of the coordinates given will be included in the returned array.

Returns:

Array:

An array of coord values within a square radius of the given coords.

loadTilesFromArrayString

(
  • mapData
  • charToType
  • [defaultTileType]
)

Defined in src/map.js:68

Loads Tile data from an array of strings

Parameters:

  • mapData Array
    • The array of strings to load.
  • charToType Object
    • An object mapping string characters to Tile types (see Tile.Types[type]).
  • [defaultTileType] String optional
    • The tile type to use if a character is not in charToType. This is used to allow characters representing entites or non-tile objects to be included in the mapData.

Example:

       // 'P' will be ignored and a floor tile will be placed at that position
       var mapData = [
           '####',
           '#..#',
           '#.P#',
           '####',
       ],

       charToType = {
           '#': 'wall',
           '.': 'floor'
       },
       defaultTileType = 'floor';

       map.loadTilesFromArrayString(mapData, charToType, defaultTileType);

remove

(
  • x
  • y
)

Inherited from Array2d: src/array-2d.js:103

Removes a value from given coords.

Parameters:

  • x Number
    • Map tile x coord of the value being removed.
  • y Number
    • Map tile y coord of the value being removed.

reset

(
  • width
  • height
)

Inherited from Array2d: src/array-2d.js:42

Resets the 2d array, clearing all data and initializing with this.width and this.height.

Parameters:

  • width Number
    • The new width.
  • height Number
    • The new height.

set

(
  • x
  • y
  • tile
)
Tile

Inherited from Array2d but overwritten in src/map.js:25

Sets a value at given coords.

Parameters:

  • x Number
    • Position on the x axis of the value being set.
  • y Number
    • Position on the y axis of the value being set.
  • tile Tile | String
    • The Tile being set at given coords. If Tile is a string a new tile will be created using the string as the Tile Type (see Tile.Types[type]).

Returns:

Tile:

the tile added

setSize

(
  • width
  • height
)

Inherited from Array2d: src/array-2d.js:55

Updates the size of this Array2d without destroying data.

Parameters:

  • width Number
    • The new width.
  • height Number
    • The new height.

Properties

data

Array

Inherited from Array2d: src/array-2d.js:35

2d Array data

game

Game

Defined in src/map.js:18

Game instance this obj is attached to.

height

Number

Inherited from Array2d: src/array-2d.js:28

Height of the 2d Array.

width

Number

Inherited from Array2d: src/array-2d.js:21

Width of the 2d Array.