Add fix for ghosts getting stuck, Fixes #1
This commit is contained in:
parent
8f13d9295c
commit
933f696fe8
@ -102,7 +102,35 @@ public class Ghost extends MovableEntity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getNextDirection() != null) {
|
Direction nextDirection = getNextDirection();
|
||||||
|
|
||||||
|
if (!canMove) {
|
||||||
|
// we're stuck somewhere, let's change directions to a new valid direction
|
||||||
|
|
||||||
|
// check if we already have a nextDirection which will get us unstuck
|
||||||
|
if (nextDirection != null) {
|
||||||
|
Vector2 adjacent = nextDirection.getVector().add(pos);
|
||||||
|
LevelTile adjTile = state.level.getTile(adjacent);
|
||||||
|
if (adjTile != null && adjTile.isPassable()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Direction dir : GHOST_ORDER) {
|
||||||
|
if (dir.isOpposite(currDirection) || dir == currDirection) {
|
||||||
|
// don't just turn around or keep going our current direction (since we'll continue being stuck)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Vector2 adjacent = dir.getVector().add(pos);
|
||||||
|
LevelTile adjTile = state.level.getTile(adjacent);
|
||||||
|
if (adjTile != null && adjTile.isPassable()) {
|
||||||
|
setNextDirection(dir);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nextDirection != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,8 +146,8 @@ public class Ghost extends MovableEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Vector2 ahead = new Vector2((int) pos.x, (int) pos.y).add(currDirection.getVector());
|
Vector2 ahead = new Vector2((int) pos.x, (int) pos.y).add(currDirection.getVector());
|
||||||
|
|
||||||
float shortest = Float.MAX_VALUE;
|
float shortest = Float.MAX_VALUE;
|
||||||
Direction nextDirection = null;
|
|
||||||
|
|
||||||
for (Direction dir : GHOST_ORDER) {
|
for (Direction dir : GHOST_ORDER) {
|
||||||
if (dir.isOpposite(currDirection)) {
|
if (dir.isOpposite(currDirection)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user