slimes can now get aggro and follow you (and stop following you if you ran away)
This commit is contained in:
@@ -334,5 +334,46 @@ public class Entity {
|
||||
}
|
||||
} else onPath = false;
|
||||
}
|
||||
public void followPlayer(int goalCol, int goalRow) {
|
||||
int startCol = (worldX + solidArea.x) / panel.tileSize;
|
||||
int startRow = (worldY + solidArea.y) / panel.tileSize;
|
||||
|
||||
panel.pFinder.setNodes(startCol, startRow, goalCol, goalRow);
|
||||
|
||||
if (panel.pFinder.search()) {
|
||||
int nextCol = panel.pFinder.pathList.getFirst().col;
|
||||
int nextRow = panel.pFinder.pathList.getFirst().row;
|
||||
|
||||
int enLeftX = worldX + solidArea.x;
|
||||
int enTopY = worldY + solidArea.y;
|
||||
|
||||
int targetX = nextCol * panel.tileSize;
|
||||
int targetY = nextRow * panel.tileSize;
|
||||
|
||||
// UP
|
||||
if (nextRow < startRow) {
|
||||
if (enLeftX < targetX) direction = Direction.RIGHT;
|
||||
else if (enLeftX > targetX) direction = Direction.LEFT;
|
||||
else direction = Direction.UP;
|
||||
}
|
||||
// DOWN
|
||||
else if (nextRow > startRow) {
|
||||
if (enLeftX < targetX) direction = Direction.RIGHT;
|
||||
else if (enLeftX > targetX) direction = Direction.LEFT;
|
||||
else direction = Direction.DOWN;
|
||||
|
||||
}
|
||||
else if (nextCol < startCol) { // DOWN LEFT
|
||||
if (enTopY < targetY) direction = Direction.DOWN;
|
||||
else if (enTopY > targetY) direction = Direction.UP;
|
||||
else direction = Direction.LEFT;
|
||||
}
|
||||
else if (nextCol > startCol) { // RIGHT
|
||||
if (enTopY < targetY) direction = Direction.DOWN;
|
||||
else if (enTopY > targetY) direction = Direction.UP;
|
||||
else direction = Direction.RIGHT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user