Open melanke opened 10 years ago
implementation: it will be a plugin of CascadeCanvas, an adapter of https://github.com/qiao/PathFinding.js
to createObstaclesMap we need to read the list of obstacles we need to know what obstacle is the top-left, and what is the bottom-right to save in x, y, w, h of the map the map will represent only this space (with a margin of 1 tile to each side) the tile size will be the one in the params or 16x16 for each obstacle: we read the x, y, w, h and put a marker in an matrix of tiles
to pathFind we need to read the map if the origin or destiny is out the box of the map we increment the empty map tiles save this x, y, w, h of the path ask qiao/PathFinding to make the path and save it
to walkThePath we need only to make the element to move to the positions of the path and if walkThePath is called again we need to abort the first and make the second one
Generate a obstacle map with the obstacle elements
default tile W and H is 16x16, the tile size is important to define the size of the elements that will walk the path generate the map the less possible, only when the level changes
find the path with your map, the origin and destination of the path
make the element walk that path
and we will have a default speed
example:
OR, if you will use the path only once
example2:
OR, if you need only one map simultaniously
we will store the last map in a singleton, so you dont have to worry carrying it
example3: