Created
September 8, 2012 05:23
-
-
Save pxpc2/3672053 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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