The algorithm is designed for 2.5 dimensional games where obstacles are mapped to rectangular cells. Your smallest collidable object will occupy one cell. Movement is 4-directional for quick implementation but is easily converted to n-directional by expanding on moveStack_neighbours()
. The purpose of this format is to allow us to respect the orthogonal (graphic) representation of the game while facilitating movement and dynamic pathfinding on different planes.
With get_moveStack()
, we can assign a stack of waypoints to a given instance. We only need to figure out:
- When we want to read in the next waypoint
- How we're getting to the x and y stored in that waypoint
Once we're ready to read in a waypoint, simply pop the moveStack assigned to a given instance:
waypoint = ds_stack_pop(moveStack)
Then access the x and y keys:
xNext = waypoint[? moveX]
yNext = waypoint[? moveY]
Initializes the pathfinding algorithm and assigns a stack of waypoints to a given instance.
-
col (int)
- The relative starting column of the instance we're moving.
col = 0
would mean starting in the leftmost column of our moving grid. We can useget_grid(instance.x)
to quickly get a relative column.
- The relative starting column of the instance we're moving.
-
row (int)
- The relative starting row of the instance we're moving.
row = 0
would mean starting in the topmost row of our moving grid. We can useget_grid(instance.y)
to quickly get a relative row.
- The relative starting row of the instance we're moving.
-
colGoto (int)
- The relative row of the distination.
colGoto = 0
would be the leftmost column considered by the pathfinder. We can useget_grid(x)
from this library to convert any x to a relative column. For example, we can easily assign a column with the mouse simply usingget_grid(mouse_x)
to figure out the relative column for us.
- The relative row of the distination.
-
rowGoto (int)
- The relative row of the distination.
rowGoto = 0
would be the topmost row considered by the pathfinder. We can useget_grid(y)
from this library to convert any y to a relative row. For example, we can easily assign a row for following another instance simply usingget_grid(ally.y)
to figure out the relative row for us.
- The relative row of the distination.
-
grid (mp_grid)
- ID of some mp_grid
-
grid_originX = absolute x coordinate of origin of the grid
-
grid_originY = absolute y coordinate of origin of the grid
- Allows for dynamic pathfinding and optimizing memory
-
grid_cellWidth = width of columns in the grid
-
grid_cellHeight = height of rows in the grid