// Pathfind! With A* private Vector2 pathfindMove(Hero unit) { Vector2 d = unit.getDestination(); Vector2 p = unit.getPosition(); Pathfinder pathfinder = new Pathfinder(world.getLevel()); Node result = pathfinder.getPath(p, d); if (result == null) return null; while (result.getParent() != null && result.getParent().getParent() != null) { result = result.getParent(); } return result.getPosition(); }
// input events public void moveHeroTo(Vector2 destination) { Tile t = world.getLevel().getTile((int) destination.x, (int) destination.y); if (t == null || !t.getType().equals(Tile.Type.COLLIDABLE)) { hero.setDestination(destination); } }