I'm trying to make a game where a skeleton moves in the direction of the player if he sees him, so when he is close enough and in the more and less same Y if possible. I need to complete this code to do it, but I can't figure out how. Does anyone have an idea?
int currentX = this.getX();
int currentY = this.getY();
int sight = 150;
List players = getWorld().getObjects(Player.class);
if (!players.isEmpty())
{
Actor player = (Actor)players.get(0);
int playerX = player.getX();
int playerY = player.getY();
int dir = 0;
if(playerX > currentX) /** && if Player is in sight --> 150px away in X (and only 10 away in Y if possible) */
{
setImage(walk.getCurrentImage());
move(speed);
dir++;
}
if(playerX < currentX) /** && if Player is in sight --> 150px away in X (and only 10 away in Y if possible) */
{
setImage(walkL.getCurrentImage());
move(-speed);
dir--;
}
}

