# new Grid(gridW, gridH, gridX, gridY, tileW, tileH)
Represents a Grid object.
Parameters:
Name | Type | Description |
---|---|---|
gridW |
number | The width of the grid in number of tiles. |
gridH |
number | The height of the grid in number of tiles. |
gridX |
number | The x coordinate of the center of the grid in WC. |
gridY |
number | The y coordinate of the center of the grid in WC. |
tileW |
number | The width of each tile in WC. |
tileH |
number | The height of each tile in WC. |
Members
# (static, readonly) eDirection :array
Enum for Directional values.
Type:
- array
Methods
# addObjectToGrid(obj) → {number}
Adds an object to the Grid system. Movement & positioning of this object are then
controlled through the Grid object itself.
Parameters:
Name | Type | Description |
---|---|---|
obj |
Renderable | The object to be added. MUST have an associated Xform, else the function will error. |
- Source:
Returns:
The ID to use to retrieve this object in the grid to perform future functions on it. -1 If object
couldn't be added.
- Type
- number
# addRangeWalls(x1, y1, x2, y2, direction)
Add walls to a given range of tiles of a single specified direction.
If given range is invalid, the function will round the given range to the nearest valid range.
Parameters:
Name | Type | Description |
---|---|---|
x1 |
number | The x coordinate in the Grid index of the beginning Tile in the range. |
y1 |
number | The y coordinate in the Grid index of the beginning Tile in the range. |
x2 |
number | The x coordinate in the Grid index of the last Tile in the range. |
y2 |
number | The y coordinate in the Grid index of the last Tile in the range. |
direction |
Direction | The direction of the walls being placed. |
- Source:
# addTileWall(x, y, direction) → {boolean}
Add a wall of given direction to the Tile at the given index.
Parameters:
Name | Type | Description |
---|---|---|
x |
number | The x coordinate of the tile in the Grid index coordinate system. |
y |
number | The y coordinate of the tile in the Grid index coordinate system. |
direction |
The desired direction to add a wall in. |
- Source:
Returns:
True if the wall was successfully added, false otherwise.
- Type
- boolean
# addWall(x, y) → {boolean}
Adds a wall of the given direction to the tile at the index shown. Also adds a wall to
the tile the wall resides next to, so that the wall cannot be passed through in either direction.
Parameters:
Name | Type | Description |
---|---|---|
x |
number | The x coordinate of the desired Grid index coordinate. |
y |
number | The y coordinate of the desired Grid index coordinate. |
Returns:
True if the wall was able to be added, false otherwise.
- Type
- boolean
# addWallRange(x1, y1, x2, y2, direction)
Add walls to a given range of tiles of a single specified direction.
If given range is invalid, the function will round the given range to the nearest valid range.
NOTE: This function also adds a corresponding wall in the opposite direction to the tile on
the other side of the given wall.
Parameters:
Name | Type | Description |
---|---|---|
x1 |
number | The x coordinate in the Grid index of the beginning Tile in the range. |
y1 |
number | The y coordinate in the Grid index of the beginning Tile in the range. |
x2 |
number | The x coordinate in the Grid index of the last Tile in the range. |
y2 |
number | The y coordinate in the Grid index of the last Tile in the range. |
direction |
Direction | The direction of the walls being placed. |
- Source:
# AStarSearch(start, finish) → {array}
Runs an A* Search algorithm given two Grid index positions within the grid to find the optimal
path between them. Considers moving into collidable tiles & through walls as invalid moves.
Parameters:
Name | Type | Description |
---|---|---|
start |
- | |
finish |
- |
Returns:
An array of sequential moves to get to the desired position. Will be empty if
a path was not found.
- Type
- array
# changeObjectPosition(id, x, y) → {boolean}
Attempts to move the specified object from its current tile position to a given
tile index. Does not check for any collision in the tiles between the current tile
and the desired tile to move to, only checks the desired tile collision property.
Parameters:
Name | Type | Description |
---|---|---|
id |
number | The id of the object to move. |
x |
number | The x coordinate of the Grid index to move to. |
y |
number | The y coordinate of the Grid index to move to. |
- Source:
Returns:
True if the move was successful, false otherwise.
- Type
- boolean
# draw(cam)
Draws all tiles within the grid.
Parameters:
Name | Type | Description |
---|---|---|
cam |
Camera | The camera object to draw the grid to. |
# editRangeCollision(x1, y1, x2, y2, toSet)
Change the collision property of a given range of Tiles within the Grid system.
If given range is invalid, the function will round the given range to the nearest valid range.
Parameters:
Name | Type | Description |
---|---|---|
x1 |
number | The x coordinate in the Grid index of the beginning Tile in the range. |
y1 |
number | The y coordinate in the Grid index of the beginning Tile in the range. |
x2 |
number | The x coordinate in the Grid index of the last Tile in the range. |
y2 |
number | The y coordinate in the Grid index of the last Tile in the range. |
toSet |
String | The value either enabling or disabling the collision of the desired tiles in the range. |
- Source:
# editRangeTexture(x1, y1, x2, y2, texture)
Change the texture of a given range of Tiles within the Grid system. If given range is invalid, the function
will round the given range to the nearest valid range.
Parameters:
Name | Type | Description |
---|---|---|
x1 |
number | The x coordinate in the Grid index of the beginning Tile in the range. |
y1 |
number | The y coordinate in the Grid index of the beginning Tile in the range. |
x2 |
number | The x coordinate in the Grid index of the last Tile in the range. |
y2 |
number | The y coordinate in the Grid index of the last Tile in the range. |
texture |
String | The filepath to the texture to set the tiles to display. Assumes texture is already loaded. |
- Source:
# editRangeVisible(x1, y1, x2, y2, toSet)
Change the visibility property of a given range of Tiles within the Grid system.
If given range is invalid, the function will round the given range to the nearest valid range.
Parameters:
Name | Type | Description |
---|---|---|
x1 |
number | The x coordinate in the Grid index of the beginning Tile in the range. |
y1 |
number | The y coordinate in the Grid index of the beginning Tile in the range. |
x2 |
number | The x coordinate in the Grid index of the last Tile in the range. |
y2 |
number | The y coordinate in the Grid index of the last Tile in the range. |
toSet |
String | The value either enabling or disabling the visibility of the desired tiles in the range. |
- Source:
# editTileCollision(x, y, toSet) → {boolean}
Change the collision property of the Tile at the given index.
Parameters:
Name | Type | Description |
---|---|---|
x |
number | The x coordinate of the tile in the Grid index coordinate system. |
y |
number | The y coordinate of the tile in the Grid index coordinate system. |
toSet |
boolean | The value either enabling or disabling the collision of the desired tile. |
- Source:
Returns:
True if the collision was successfully set, false otherwise.
- Type
- boolean
# editTileTexture(x, y, texture) → {boolean}
Change the texture displayed by the Tile at the given index.
Parameters:
Name | Type | Description |
---|---|---|
x |
number | The x coordinate of the tile in the Grid index coordinate system. |
y |
number | The y coordinate of the tile in the Grid index coordinate system. |
texture |
String | The filepath to the texture to set the tile to display. Assumes texture is already loaded. |
- Source:
Returns:
True if the texture was successfully set, false otherwise.
- Type
- boolean
# editTileVisible(x, y, toSet) → {boolean}
Change the visibility property of the Tile at the given index.
Parameters:
Name | Type | Description |
---|---|---|
x |
number | The x coordinate of the tile in the Grid index coordinate system. |
y |
number | The y coordinate of the tile in the Grid index coordinate system. |
toSet |
boolean | The value either enabling or disabling the visibility of the desired tile. |
- Source:
Returns:
True if the visibility was successfully set, false otherwise.
- Type
- boolean
# getIDPosition(id) → {array}
Gets the Grid index position of the specified object.
Parameters:
Name | Type | Description |
---|---|---|
id |
number | The id of the object to get the index position of. |
- Source:
Returns:
The x & y coordinates in the Grid index of the object, [-1, -1] if object was not found.
- Type
- array
# getNeighbors(curr) → {array}
A function used for grabbing the given position's neighboring tiles, based off of valid
movement from the given tile.
Parameters:
Name | Type | Description |
---|---|---|
curr |
array | short for current position |
Returns:
containing neighboring tiles that can be reached from the given position
- Type
- array
# getTileAtIndex(x, y) → {Tile}
Gets the tile corresponding to the given index coordinate.
Parameters:
Name | Type | Description |
---|---|---|
x |
number | The x coordinate of the desired Grid index coordinate. |
y |
number | The y coordinate of the desired Grid index coordinate. |
Returns:
The tile object corresponding to the given index. Returns null if given invalid index.
- Type
- Tile
# getTileAtWC(x, y) → {array}
Gets the index of the tile at the given WC.
Parameters:
Name | Type | Description |
---|---|---|
x |
number | The x coordinate of the given WC position. |
y |
number | The y coordinate of the given WC position. |
Returns:
The Grid index coordinate of the corresponding tile, [-1, -1] if given WC is not in the Grid.
- Type
- array
# getTileHeight() → {number}
Get the current height of tiles within the Grid in WC.
Returns:
The height of all tiles in WC.
- Type
- number
# getTileWidth() → {number}
Get the current width of tiles within the Grid in WC.
Returns:
The width of all tiles in WC.
- Type
- number
# isWCValidInGrid(x, y) → {boolean}
Checks to see if a given WC is contained within the grid object.
Parameters:
Name | Type | Description |
---|---|---|
x |
number | The x coordinate of the given WC position. |
y |
number | The y coordinate of the given WC position. |
Returns:
True if given WC position lies within the Grid, false otherwise.
- Type
- boolean
# manhattanDistance(pos1, pos2) → {number}
Manhattan distance heuristic for A* search.
Parameters:
Name | Type | Description |
---|---|---|
pos1 |
array | A position |
pos2 |
array | A different position |
Returns:
Manhattan distance heuristic result
- Type
- number
# moveObjectPositionDir(id, direction) → {boolean}
Moves the object specified by the given ID one space in the given direction. Considers collision
property and current walls of the tile to move into.
Parameters:
Name | Type | Description |
---|---|---|
id |
number | The id of the object to move. |
direction |
Direction | The direction to move the object one tile space. |
- Source:
Returns:
True if move was successful, false otherwise.
- Type
- boolean
# readySearch()
Helper function for A* search that resets data from any previous searches performed.
# removeObjectFromGrid(id) → {boolean}
Removes the desired object from Grid system control. This does not remove the object from the
world.
Parameters:
Name | Type | Description |
---|---|---|
id |
number | The id of an object currently existing in the grid. |
- Source:
Returns:
True if the object corresponding to id was removed, false otherwise.
- Type
- boolean
# removeTileWall(x, y, direction) → {boolean}
Remove a wall of given direction from the Tile at the given index.
Parameters:
Name | Type | Description |
---|---|---|
x |
number | The x coordinate of the tile in the Grid index coordinate system. |
y |
number | The y coordinate of the tile in the Grid index coordinate system. |
direction |
The desired direction to remove a wall from. |
- Source:
Returns:
True if the wall was successfully removed, false otherwise.
- Type
- boolean
# removeWallRange(x1, y1, x2, y2, direction)
removes walls from a given range of tiles of a single specified direction.
If given range is invalid, the function will round the given range to the nearest valid range.
NOTE: This function also removes any corresponding walls in the opposite direction to the tile on
the other side of the given wall.
Parameters:
Name | Type | Description |
---|---|---|
x1 |
number | The x coordinate in the Grid index of the beginning Tile in the range. |
y1 |
number | The y coordinate in the Grid index of the beginning Tile in the range. |
x2 |
number | The x coordinate in the Grid index of the last Tile in the range. |
y2 |
number | The y coordinate in the Grid index of the last Tile in the range. |
direction |
Direction | The direction of the walls being removed. |
- Source:
# setVisualizeEdges(bool)
Sets all the visualize edge states of the tiles within the grid to given boolean value.
Parameters:
Name | Type | Description |
---|---|---|
bool |
boolean | State to set the visualization of the edges of tiles to. |