• Stars
    star
    1,870
  • Rank 24,794 (Top 0.5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 12 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An asynchronous A* pathfinding API written in Javascript.

HTML5/Javascript Pathfinding Library

Click here for a demonstration

Installation

  • Web: Find the minified file in the /bin directory
  • node.js: npm install easystarjs
  • Phaser: see Phaser Plugin
  • Bower: bower install easystarjs

Description

easystar.js is an asynchronous A* pathfinding API written in Javascript for use in your HTML5 games and interactive projects. The goal of this project is to make it easy and fast to implement performance conscious pathfinding.

Features

  • Calculates asynchronously for better overall performance
  • Simple API
  • Small. ~7kb
  • Use it with any existing Javascript Framework
  • TypeScript support

API

Main Methods

var easystar = new EasyStar.js();
easystar.setGrid(twoDimensionalArray);
easystar.setAcceptableTiles(arrayOfAcceptableTiles);
easystar.findPath(startX, startY, endX, endY, callback);
easystar.calculate();

Additional Features

easystar.setIterationsPerCalculation(someValue);
easystar.avoidAdditionalPoint(x, y);
easystar.enableDiagonals();
easystar.enableCornerCutting();
easystar.setAdditionalPointCost(x, y, cost);
easystar.setTileCost(tileType, multiplicativeCost);
easystar.enableSync();
easystar.setDirectionalCondition(x, y, [EasyStar.TOP, EasyStar.LEFT]); // only accessible from the top and left
var instanceId = easystar.findPath(startX, startY, endX, endY, callback);
// ...
easystar.cancelPath(instanceId);

Usage

First create EasyStar.

// for web
var easystar = new EasyStar.js();

// for node.js
var easystarjs = require('easystarjs');
var easystar = new easystarjs.js();

Create a grid, or tilemap. You may have made this with a level editor, or procedurally. Let's keep it simple for this example.

var grid = [[0,0,1,0,0],
            [0,0,1,0,0],
            [0,0,1,0,0],
            [0,0,1,0,0],
            [0,0,0,0,0]];

Set our grid.

easystar.setGrid(grid);

Set tiles which are "walkable".

easystar.setAcceptableTiles([0]);

Find a path.

easystar.findPath(0, 0, 4, 0, function( path ) {
	if (path === null) {
		alert("Path was not found.");
	} else {
		alert("Path was found. The first Point is " + path[0].x + " " + path[0].y);
	}
});

EasyStar will not yet start calculating my path.

In order for EasyStar to actually start calculating, I must call the calculate() method.

You should call easystar.calculate() on a ticker, or setInterval.

If you have a large grid, then it is possible that these calculations could slow down the browser. For this reason, it might be a good idea to give EasyStar a smaller iterationsPerCalculation value via

easystar.setIterationsPerCalculation(1000);

It may take longer for you to find a path this way, but you won't completely halt your game trying to find one. The only thing left to do now is to calculate the path.

easystar.calculate();

License

easystar.js is licensed under the MIT license. You may use it for commercial use.

Running the demo locally

In order to run the demo you will need node.js, and npm installed.

git clone https://github.com/prettymuchbryce/easystarjs.git

cd easystarjs/demo

npm install

node app.js

Open your browser to 127.0.0.1:3000 to see the example.

Testing

npm run test

Support

If you have any questions, comments, or suggestions please open an issue.

More Repositories

1

http-status-codes

Constants enumerating the HTTP status codes. All status codes defined in RFC1945 (HTTP/1.0, RFC2616 (HTTP/1.1), and RFC2518 (WebDAV) are supported.
TypeScript
929
star
2

hellobitcoin

A collection of simple programs which can generate bitcoin wallets, create and sign transactions, and send transactions over the bitcoin network.
Go
247
star
3

kademlia

Go implementation of a Kademlia distributed hash table
Go
146
star
4

abidecoder

Kotlin and Java library for decoding data params and events from ethereum transactions
Kotlin
12
star
5

easystaras3

Asynchronous A* made simple in AS3.
ActionScript
9
star
6

blockchainparser

A blockchain parser written in go
Go
8
star
7

roguelikeboard

roguelikeboard.jsx is a simple react.js component for rendering ASCII inspired roguelike boards on the web
JavaScript
8
star
8

imp

Interfaces in JavaScript.
JavaScript
7
star
9

receiver

A simple and configurable deployment tool for github projects.
JavaScript
3
star
10

gridregions

A helper library based heavily on HPA* for tile-based game development
JavaScript
2
star
11

templ

An easier way to create and save language-agnostic project templates in OSX.
Ruby
2
star
12

saveplz.com

Saveplz is a RESTful open API for storing JSON data
Ruby
2
star
13

rugburn

A fast configuration-based caching web scraper written in Go
Go
2
star
14

deltadb

A proof-of-concept time-series database
Go
2
star
15

moremodernwebapptemplate

A more modern web app template
JavaScript
1
star
16

goeasystar

An A* pathfinding library written in Go.
Go
1
star
17

omeglevscleverbot

Omegle vs Cleverbot is a simple ruby program that pipes output from an omegle conversation, to cleverbot, and back.
Ruby
1
star
18

ingestr

Ingestr is a Go microservice that consumes Ethereum blocks for enqueing into SNS and storage in S3
Go
1
star
19

flashio

Reliable TCP socket connectivity from Flash to node.js
ActionScript
1
star
20

typescript-gamedev-template

Typescript Game Dev Template
JavaScript
1
star
21

typescript-nodejs-starter

A simple starter project for Typescript/node.js
JavaScript
1
star
22

blackjack

A simple API which allows a user to play blackjack against a dealer.
JavaScript
1
star
23

scriptcodes

All Bitcoin Script opcodes. For use in your bitcoin-related go projects.
Go
1
star