diff --git a/core/src/gdx/diablo/map/Map.java b/core/src/gdx/diablo/map/Map.java index 9751a070..25317fe5 100644 --- a/core/src/gdx/diablo/map/Map.java +++ b/core/src/gdx/diablo/map/Map.java @@ -272,6 +272,10 @@ public class Map implements Disposable { } } + static int round(float i) { + return MathUtils.round(i); + } + // TODO: maybe replace with R-tree? // https://en.wikipedia.org/wiki/R-tree Array zones = new Array<>(); IntMap dt1s; diff --git a/core/src/gdx/diablo/map/MapGraph.java b/core/src/gdx/diablo/map/MapGraph.java index 36b65fee..7da4789e 100644 --- a/core/src/gdx/diablo/map/MapGraph.java +++ b/core/src/gdx/diablo/map/MapGraph.java @@ -14,6 +14,7 @@ import com.badlogic.gdx.ai.pfa.indexed.IndexedGraph; import com.badlogic.gdx.ai.utils.Collision; import com.badlogic.gdx.ai.utils.Ray; import com.badlogic.gdx.ai.utils.RaycastCollisionDetector; +import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.utils.Array; @@ -67,8 +68,12 @@ public class MapGraph implements IndexedGraph { public boolean searchNodePath(PathFinder pathFinder, Vector3 src, Vector3 dst, GraphPath path) { path.clear(); if (dst == null) return false; - Map.Zone zone = map.getZone((int) dst.x, (int) dst.y); - if (zone != null && zone.flags((int) dst.x, (int) dst.y) != 0) { + //Map.Zone zone = map.getZone((int) dst.x, (int) dst.y); + //if (zone != null && zone.flags((int) dst.x, (int) dst.y) != 0) { + int x = Map.round(dst.x); + int y = Map.round(dst.y); + Map.Zone zone = map.getZone(x, y); + if (zone != null && zone.flags(x, y) != 0) { return false; } @@ -158,7 +163,8 @@ public class MapGraph implements IndexedGraph { } Point2(Vector3 src) { - this((int) src.x, (int) src.y); + //this((int) src.x, (int) src.y); + this(Map.round(src.x), Map.round(src.y)); } @Override @@ -167,7 +173,8 @@ public class MapGraph implements IndexedGraph { } static int hash(Vector3 src) { - return hash((int) src.x, (int) src.y); + //return hash((int) src.x, (int) src.y); + return hash(Map.round(src.x), Map.round(src.y)); } static int hash(int x, int y) { diff --git a/core/src/gdx/diablo/map/MapRenderer.java b/core/src/gdx/diablo/map/MapRenderer.java index 204fb2e0..88bec9df 100644 --- a/core/src/gdx/diablo/map/MapRenderer.java +++ b/core/src/gdx/diablo/map/MapRenderer.java @@ -263,8 +263,8 @@ public class MapRenderer { Vector3 pos = src.position(); if (pos.epsilonEquals(currentPos) && !force) return; currentPos.set(pos); - this.x = (int) pos.x; - this.y = (int) pos.y; + this.x = Map.round(pos.x);//(int) pos.x; + this.y = Map.round(pos.y);//(int) pos.y; spx = (x * Tile.SUBTILE_WIDTH50) - (y * Tile.SUBTILE_WIDTH50); spy = -(x * Tile.SUBTILE_HEIGHT50) - (y * Tile.SUBTILE_HEIGHT50); float spxf = (pos.x * Tile.SUBTILE_WIDTH50) - (pos.y * Tile.SUBTILE_WIDTH50);