Disabled path finder movement (new branch)

Disabled path finder movement on this branch
Bug fixes to path finder along with distance limiter
Incorporated persistent path into MapViewer/Entity
This commit is contained in:
Collin Smith 2019-02-18 14:25:55 -08:00
parent 5cc2aa55c6
commit 46423e10f7
5 changed files with 26 additions and 10 deletions

View File

@ -228,7 +228,7 @@ public class Entity {
return path;
}
public void updatePath(Map map) {
public void updatePath(Map map, Vector3 target) {
map.path(position, target, path);
}
@ -410,6 +410,17 @@ public class Entity {
int x = Direction.getOffX(angle);
int y = Direction.getOffY(angle);
position.add(x, y, 0);
//if (position.epsilonEquals(target) || target.equals(Vector3.Zero)) {
// if (path.getCount() > 0) {
// Point2 point = path.get(0);
// target.set(point.x, point.y, 0);
// } else {
// setMode("NU");
// }
//}
//position.lerp(target, 1f);
//position.set(target);
return true;
}

View File

@ -15,13 +15,14 @@ public class MapPather {
}
public boolean path(Vector3 src, Vector3 dst, GraphPath<Point2> path) {
if (src.dst(dst) > 25f) return false;
return path(new Point2(src), new Point2(dst), path);
}
public boolean path(Point2 src, Point2 dst, GraphPath<Point2> path) {
path.clear();
Map.Zone zone = map.getZone(dst.x, dst.y);
if (zone.flags(dst.x, dst.y) != 0) return false;
if (zone == null || zone.flags(dst.x, dst.y) != 0) return false;
BinaryHeap<Point2> closedSet = new BinaryHeap<>();
BinaryHeap<Point2> openSet = new BinaryHeap<>();

View File

@ -3,8 +3,8 @@ package gdx.diablo.map;
import com.badlogic.gdx.math.Vector3;
public class Point2 extends BinaryHeap.Node {
final int x;
final int y;
public final int x;
public final int y;
final int hash;
Point2(int x, int y, float cost) {

View File

@ -386,10 +386,13 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
if (Gdx.input.isButtonPressed(Input.Buttons.LEFT)) {
// FIXME: should block click events on UI panels, bugged right now
//Actor hit = stage.hit(Gdx.input.getX(), Gdx.input.getY(), true);
//if (hit == null) {
//if (hit != null) {
Vector3 coords = mapRenderer.getCursor();
player.target().set(coords);
player.updatePath(map);
//player.target().set(coords);
//player.updatePath(map, coords);
//if (player.path().getCount() > 0) {
// player.setMode("RN");
//}
//} else {
// System.out.println(hit);
//}

View File

@ -6,6 +6,7 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.ai.pfa.DefaultGraphPath;
import com.badlogic.gdx.ai.pfa.GraphPath;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
@ -76,7 +77,7 @@ public class MapViewer extends ApplicationAdapter {
Vector3 src;
Vector3 dst;
GraphPath<Point2> path;
GraphPath<Point2> path = new DefaultGraphPath<>();
boolean drawCrosshair;
boolean drawGrid;
@ -172,7 +173,7 @@ public class MapViewer extends ApplicationAdapter {
//System.out.println(new Vector2(dstX, dstY).dst(srcX, srcY));
System.out.println(src.dst(dst));
path = map.path(src, dst);
map.path(src, dst, path);
break;
}
return true;
@ -375,7 +376,7 @@ public class MapViewer extends ApplicationAdapter {
mapRenderer.renderDebug(shapes);
if (src != null && dst != null) {
//mapRenderer.renderDebugPath(shapes, src, dst);
if (path != null) mapRenderer.renderDebugPath2(shapes, path);
mapRenderer.renderDebugPath2(shapes, path);
float srcX = +(src.x * Tile.SUBTILE_WIDTH50) - (src.y * Tile.SUBTILE_WIDTH50);
float srcY = -(src.x * Tile.SUBTILE_HEIGHT50) - (src.y * Tile.SUBTILE_HEIGHT50);
float dstX = +(dst.x * Tile.SUBTILE_WIDTH50) - (dst.y * Tile.SUBTILE_WIDTH50);