我知道这是一个经常被问到的问题。我也坚持下去并寻求一些帮助。
我确实有一个小应用程序,怪物应该在角色上工作。它是基于网格的,所以它可以从左到右走。我确实有一个数组,地图的所有阻塞区域都在其中。我需要得到的只是下一步到达角色(从左到右)。例如,如果他们在树上走来走去,那就太好了。(数组内部的简单 -1 )
是否有任何简单的解决方案或者我是否需要实现 A*(我试过但我完全坚持这个)
我只是盯着这个:
@Override
public Status getNextMove(int posX, int posY) {
if (checkIfAggroRange(posX, posY)) {
if (checkIfBeside(posX, posY))
//turn to the character
return getIdleStatus(posX, posY);
else
//here id like to add the algo and get the value
} else {
return moveRnd();
}
}
private boolean checkIfAggroRange(int posX, int posY) {
return Math.abs(this.screen.character.mapPos.x - posX) <= range
&& Math.abs(this.screen.character.mapPos.y - posY) <= range;
}
private boolean checkIfBeside(int posX, int posY) {
return (Math.abs(this.screen.character.mapPos.x - posX) <= 1 && Math
.abs(this.screen.character.mapPos.y - posY) <= 1);
}
当它们在怪物的范围内时,它确实已经开始仇恨,并且还将怪物转向角色,以便它可以击中角色。
我确实得到了简单的地图screen.map.maparray
(int[xsize][ysize])
。xpos/ypos
是数组内部的 pos。
如果您需要有关它的更多信息,请告诉我。