Skip to content

Instantly share code, notes, and snippets.

@pxpc2
Created September 8, 2012 05:23
Show Gist options
  • Select an option

  • Save pxpc2/3672053 to your computer and use it in GitHub Desktop.

Select an option

Save pxpc2/3672053 to your computer and use it in GitHub Desktop.
public ArrayList<Tile> walkableTiles = new ArrayList<Tile>();
public ArrayList<Tile> blockedTiles = new ArrayList<Tile>();
public void fill(Tile init) {
for (Tile t : Util.getSurrounding(init)) {
if (Util.canReach(t)) {
walkableTiles.add(t);
fill(t);
} else {
blockedTiles.add(t);
}
}
}
public Area getCurrentRoom(Tile init) {
fill(init);
if (!walkableTiles.isEmpty()) {
return new Area(walkableTiles.toArray(new Tile[walkableTiles.size()]));
} else {
return new Area(new Tile(0,0,0));
}
}
public LinkedList<Tile> findPath(SceneObject obj, Tile myTile) {
LinkedList<Tile> tiles = new LinkedList<Tile>();
if (!getCurrentRoom(myTile).getTileArray()[0].equals(new Tile(0,0,0)) &&
getCurrentRoom(myTile).contains(obj)) {
Tile dest = obj.getLocation();
for (Tile tile : walkableTiles) {
Tile lowest = dest;
double low = 99999;
for (Tile t : Util.getSurrounding(tile)) {
if (t.distance(obj) < low) {
low = t.distance(obj);
lowest = t;
}
}
if (!lowest.equals(dest))
tiles.add(lowest);
}
}
return (tiles.isEmpty()? null : tiles);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment