Added max steps parameter to path generation

Added max steps parameter to path generation to avoid some behavior on Android with 1 unit walls
Android movement should be reimplemented as raycasting to help with moving near walls
This commit is contained in:
Collin Smith 2019-02-21 17:16:36 -08:00
parent bc4f1f83b8
commit 8bbaec639b
2 changed files with 11 additions and 1 deletions

View File

@ -233,8 +233,18 @@ public class Entity {
}
public void setPath(Map map, Vector3 dst) {
setPath(map, dst, -1);
}
public void setPath(Map map, Vector3 dst, int maxSteps) {
boolean success = map.findPath(position, dst, path);
if (!success) return;
if (maxSteps != -1 && path.getCount() > maxSteps) {
path.clear();
targets = Collections.emptyIterator();
return;
}
if (DEBUG_PATH) Gdx.app.debug(TAG, "path=" + path);
map.smoothPath(path);
targets = new Array.ArrayIterator<>(path.nodes);

View File

@ -371,7 +371,7 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
float rad = MathUtils.atan2(y, x);
x = Direction.getOffX(rad);
y = Direction.getOffY(rad);
player.setPath(map, new Vector3(x, y, 0).add(player.position()));
player.setPath(map, new Vector3(x, y, 0).add(player.position()), 3);
}
} else {
if (Gdx.input.isButtonPressed(Input.Buttons.LEFT)) {