s-kania
s-kania/def-windward-jps/def_windward_jps
Find paths on 2D grids with Jump Point Search.
- GitHub: s-kania/def-windward-jps — pinned to
v1.1.0- Pick a release from s-kania/def-windward-jps releases and add its Source code (zip) URL (or a packaged
.zipasset, if the library ships one) togame.projectunder[project]dependencies, then Fetch Libraries in the Defold editor. - Run
bunx @defold-typescript/cli resolveto materialize its types. - Import it under a namespace alias of your choice:
import * as def_windward_jps from "def_windward_jps"
- Pick a release from s-kania/def-windward-jps releases and add its Source code (zip) URL (or a packaged
Functions
create_grid(width: number, height: number, walls: Point[]): Grid
Creates a grid to find paths on.
Parameters
width:number— Number of cells horizontally.height:number— Number of cells vertically.walls:Point[]— Blocked cells, such as[[10, 12], [11, 12]]. ⚠️ 1-based; passed todef_windward_jpsunchanged.
Returns
Grid— The new grid.
Types
type Point = [ x: number, y: number ]
type Heuristic = "octile" | "manhattan" | "euclidean"
Grid
Grid.find_path(start: Point, goal: Point, heuristic?: Heuristic): LuaMultiReturn<[ Point[], undefined ] | [ undefined, string ]>
Finds a path between two cells. A start or goal that is outside the
grid or blocked, or a goal that cannot be reached, fails with an error
message instead of a path, so check path before reading it.
Parameters
start:Point— Cell to start from. ⚠️ 1-based; passed todef_windward_jpsunchanged.goal:Point— Cell to reach. ⚠️ 1-based; passed todef_windward_jpsunchanged.heuristic?:Heuristic— Distance estimate to search with. Default is"octile".
Returns
LuaMultiReturn<[ Point[], undefined ] | [ undefined, string ]>—path, the cells from start to goal, andnil; ornilandmessage, why the search failed. ⚠️pathis 1-based; passed todef_windward_jpsunchanged.
Grid.is_walkable(point: Point): boolean
Whether a cell is inside the grid and not blocked. Use it to check a cell before searching from or to it.
Parameters
point:Point— Cell to check. ⚠️ 1-based; passed todef_windward_jpsunchanged.
Returns
boolean—trueif the cell can be walked through.