API Documentation

Grid:

Object that creates a grid overlay over the world space.

Methods:

Grid(xCells, yCells):

Parameters
Name Type Description
xCells int width of the grid in cell units
yCells int height of the grid in cell units

Creates a new grid with the total number of GridSpaces being xCells * yCells

setPosition(x, y)

Name Type Description
x float world coordinate unit on the x axis
y float world coordinate unit on the y axis

Sets the center of the grid to be at position x, y

setSize(x, y)

Name Type Description
x float world coordinate unit on the x axis that represents width
y float float : world coordinate unit on the y axis that represents height

Sets the size of the grid

setWidth(x)

Name Type Description
x float world coordinate unit on the x axis that represents width

Sets the width of the grid

setHeight(y)

Name Type Description
y float world coordinate unit on the y axis that represents height

Sets the height of the grid

getCellCount()

Returns the number of cells on the x axis and the y axis in array form of [numXCells, numYCells]

addStatic(object)

Name Type Description
Object gameObject Object that is being added to the grid

Adds a non moving object to the grid

removeStatic(object)

Name Type Description
Object gameObject Object that is being removed from the grid

Removes the obstacle from the grid

search(start, end)

Name Type Description
start vec2[int, int] Starting location of the search
end vec2[int, int] Ending location of the search

Searches for a path from start to end. Returns path of grid cells or empty array if no path foud

Draw()

Draws the grid lines if enabled

Path:

Path(grid, xform)

Name Type Description
grid Grid Grid that the path will search through
xform Transform Transfor of the object to me moved

Creates the path finding object for an object

setSpeed(speed)

Name Type Description
speed int Speed to set the object to

Sets the speed of the object to be moved

findPath(start, end)

Name Type Description
start vec2[int, int] Starting location of the search
end vec2[int, int] Ending location of the search

Searches and stores a path from start to end. Draws path lines

findMultiPath(start, waypoints)

Name Type Description
start vec2[int, int] Starting location of the search
waypoints array of vec2[int, int] Positions to search through

Searches and stores a path from start through every vec2 in waypoints.

findPathLines(start, end)

Name Type Description
start vec2[int, int] Starting location of the search
end vec2[int, int] Ending location of the search

Searches for a path from start to end and only draws path lines.

update()

Updates the transform of the object to be moved. If not called the transform won't update

draw()

Draws the lines to represent the current path of the object

SceneFileParser:

parseWalls(type, walls, mGrid)

Name Type Description
Type String is the file extension (Must be json to work)
Walls gameObjectSet where the walls will be added to for access
mGrid Grid where the walls are added as obstacles for pathfinding

All Walls in json will be parsed

For a wall to be parsed it must be in form

“Walls”: [
{
"Color": [0, 1, 0.75, 1],
"Pos": [100, 70.3571428571],
"Width": 5,
"Height": 80
},
{
"Color": [0, 1, 0.75, 1],
"Pos": [50, 80.3571428571],
"Width": 5,
"Height": 100
}
]