Jumper is a pathfinding library designed for grid-based games.
It is written in pure Lua and offers a wide range of search algorithms, implemented through a common interface for a convenient use.
Jumper aims to be fast, lightweight, with a focus on being easy-to-use.
Screenshot of a Demo using Kadoba's ATL(map rendering) and Jumper for pathfinding purposes.
A simple example showing how to use Jumper (v1.8.1)
Code: Select all
-- Usage Example
-- First, set a collision map
local map = {
{0,1,0,1,0},
{0,1,0,1,0},
{0,1,1,1,0},
{0,0,0,0,0},
}
-- Value for walkable tiles
local walkable = 0
-- Library setup
local Grid = require ("jumper.grid") -- The grid class
local Pathfinder = require ("jumper.pathfinder") -- The pathfinder lass
-- Creates a grid object
local grid = Grid(map)
-- Creates a pathfinder object using Jump Point Search
local myFinder = Pathfinder(grid, 'JPS', walkable)
-- Define start and goal locations coordinates
local startx, starty = 1,1
local endx, endy = 5,1
-- Calculates the path, and its length
local path, length = myFinder:getPath(startx, starty, endx, endy)
if path then
print(('Path found! Length: %.2f'):format(length))
for node, count in path:iter() do
print(('Step: %d - x: %d - y: %d'):format(count, node.x, node.y))
end
end
--> Output:
--> Path found! Length: 8.83
--> Step: 1 - x: 1 - y: 1
--> Step: 2 - x: 1 - y: 3
--> Step: 3 - x: 2 - y: 4
--> Step: 4 - x: 4 - y: 4
--> Step: 5 - x: 5 - y: 3
--> Step: 6 - x: 5 - y: 1
Demos (with Löve and other frameworks): Jumper-Examples
Benchmak console test app: Jumper-Benchmark
Wiki (Löve2d wiki): Jumper