From 8bbaec639b70b419a46cbf866dabd03977691e45 Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Thu, 21 Feb 2019 17:16:36 -0800 Subject: [PATCH] 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 --- core/src/gdx/diablo/entity/Entity.java | 10 ++++++++++ core/src/gdx/diablo/screen/GameScreen.java | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/core/src/gdx/diablo/entity/Entity.java b/core/src/gdx/diablo/entity/Entity.java index f85db534..67a41f2d 100644 --- a/core/src/gdx/diablo/entity/Entity.java +++ b/core/src/gdx/diablo/entity/Entity.java @@ -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); diff --git a/core/src/gdx/diablo/screen/GameScreen.java b/core/src/gdx/diablo/screen/GameScreen.java index b3a7b5dd..0088420b 100644 --- a/core/src/gdx/diablo/screen/GameScreen.java +++ b/core/src/gdx/diablo/screen/GameScreen.java @@ -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)) {