Description

reate a virtual grid and the location of an entity in the grid and properties of a cell

Usage

Constructor

  • rows {Integer}

    Number of rows

  • cols {Integer}

    Number of columns

Example

In ready method

var entity = Class.New("Entity", [stage]),
    pos = entity.position(),
    grid = Class.New("Grid", [10, 5]);

grid.setCellSize(32, 32);

console.log(grid.getCellByPos(pos.x, pos.y)); // {col: 0, row: 0}

Methods

setPropertyCell

Assign properties to the cells (two-dimensional arrays) 1. Abscissa 2. 0rdered

getPropertyByCell

Gets the properties of a cell

setPropertyByCell

`(>= 1.3.0)` Change a value in a cell

getPropertyByPos

Obtain the properties of a cell according to positions

testCell

Test cell lines which coincide with the lines of the polygons of the entity [ [ { points: { x: 5, y: 5 }, sides: 2 } ], ] `sides` sends lines of polygons of the entity which coincide with the grid lines. 0 corresponds to the first line from the first point of the polygon. The number of lines is equal to the order (n) of the polygon - 1.

getEntityCells

Obtain the cells where the entity. Return this object (example) : { cells: [{ col: 1, row: 1 }] }

getCellByPos

Retrieve the column and row in the grid according to the positions. Returns this object : {col: , row: }

setCellSize

Set the size of a cell

getRows

Get the number of rows

getCols

Get the number of columns

getNbCell

Get the total number of cell (rows * columns)

passableCell

`(>= 1.3.0`) Test tiles passable in an area. The array must contain only the value 0 or 1. Useful to know the movement of an entity as a part in a game of chess - 0 : passable - 1 : not passable Returns the columns and rows in grid passable

pathfinding

`(>= 1.3.0)` Find the shortest path. Using the library [Pathfinding.js](https://github.com/qiao/PathFinding.js). The array must contain only the value 0 or 1. Useful to know the movement of an entity as a part in a game of chess - 0 : passable - 1 : not passable > Before, Insert the script `pathfinding-browser.js` in header > Attention ! The matrix is different that matrix of the library. The columns are the rows and rows are the columns. Returns the columns and rows of path. If no arguments, returns the `PF.Grid`. You can use the API library. var matrix = [ [0, 0, 0, 1, 0], [1, 0, 0, 0, 1], [0, 0, 1, 0, 0], ]; var grid = Class.New("Grid", [matrix]); var pf_grid = grid.pathfinding(); pf_grid.setWalkableAt(1, 2, false);

Discussion