private JPSNode[] getJPSNeighbours(JPSNode current, List<IObstacle> obsList) { double x = current.getX(); double y = current.getY(); LinkedList<JPSNode> nodes = new LinkedList<JPSNode>(); JPSNode parent = current.came_from; if (parent != null) { // determines whether to prune neighbors JPSNode norm = normalizeDirection(x, y, parent.getX(), parent.getY()); double dx = norm.getX() * coordinateScaling; double dy = norm.getY() * coordinateScaling; JPSNode temp = new JPSNode(current); if (((int) dx & (int) dy) != 0) { // diagonal direction // check straight directions in the direction of the diagonal move if (walkable(temp.setPosition(x, y + dy))) nodes.add(new JPSNode(temp)); if (walkable(temp.setPosition(x + dx, y))) nodes.add(new JPSNode(temp)); if (walkable(temp.setPosition(x + dx, y + dy))) nodes.add(new JPSNode(temp)); // forced neighbor checks if (!walkable(temp.setPosition(x - dx, y))) nodes.add(new JPSNode(temp.shift(0, dy))); if (!walkable(temp.setPosition(x, y - dy))) nodes.add(new JPSNode(temp.shift(dx, 0))); } else { // straight direction if (walkable(temp.setPosition(x + dx, y + dy))) { nodes.add(new JPSNode(temp)); // forced neighbor checks if (!walkable(temp.setPosition(x + dy, y + dx))) nodes.add(new JPSNode(temp.shift(dx, dy))); if (!walkable(temp.setPosition(x - dy, y - dx))) nodes.add(new JPSNode(temp.shift(dx, dy))); } } } else { // no parent, return all that aren't blocked JPSNode[] ns = new JPSNode[] { new JPSNode(x, y - coordinateScaling), new JPSNode(x + coordinateScaling, y - coordinateScaling), new JPSNode(x + coordinateScaling, y), new JPSNode(x + coordinateScaling, y + coordinateScaling), new JPSNode(x, y + coordinateScaling), new JPSNode(x - coordinateScaling, y + coordinateScaling), new JPSNode(x - coordinateScaling, y), new JPSNode(x - coordinateScaling, y - coordinateScaling) }; for (int i = 0; i < ns.length; i++) { if (walkable(ns[i])) nodes.add(ns[i]); } } return nodes.toArray(new JPSNode[nodes.size()]); }