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;
|
} 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,8 +35,24 @@ public class GreenSlimeMON extends Entity {
|
|||||||
getImage();
|
getImage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update() {
|
||||||
|
super.update();
|
||||||
|
int dx = Math.abs(worldX - panel.player.worldX);
|
||||||
|
int dy = Math.abs(worldY - panel.player.worldY);
|
||||||
|
int dTile = (dx+dy)/panel.tileSize;
|
||||||
|
if(!onPath && dTile < 5) if(new Random().nextInt(100)+1 > 50) onPath = true;
|
||||||
|
if(onPath && dTile > 20) onPath = false;
|
||||||
|
}
|
||||||
|
|
||||||
// INTERACTION
|
// INTERACTION
|
||||||
public void setAction() {
|
public void setAction() {
|
||||||
|
|
||||||
|
if(onPath) {
|
||||||
|
searchPath((panel.player.worldX+panel.player.solidArea.x)/panel.tileSize, (panel.player.worldY+panel.player.solidArea.y)/panel.tileSize);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
actionLock++;
|
actionLock++;
|
||||||
|
|
||||||
if(actionLock == 120) { //lock action for x frames
|
if(actionLock == 120) { //lock action for x frames
|
||||||
@@ -57,7 +73,7 @@ public class GreenSlimeMON extends Entity {
|
|||||||
}
|
}
|
||||||
public void damageReaction() {
|
public void damageReaction() {
|
||||||
actionLock = 0;
|
actionLock = 0;
|
||||||
direction = panel.player.direction;
|
onPath = true;
|
||||||
}
|
}
|
||||||
public void checkDrop() {
|
public void checkDrop() {
|
||||||
int i = new Random().nextInt(100)+1;
|
int i = new Random().nextInt(100)+1;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import de.miaurizius.jgame2d.core.GamePanel;
|
|||||||
import de.miaurizius.jgame2d.core.enums.EntityType;
|
import de.miaurizius.jgame2d.core.enums.EntityType;
|
||||||
import de.miaurizius.jgame2d.entity.Entity;
|
import de.miaurizius.jgame2d.entity.Entity;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class OldManNPC extends Entity {
|
public class OldManNPC extends Entity {
|
||||||
|
|||||||
Reference in New Issue
Block a user