So I'm currently developing a 2D top down view java game. I have a mob called "Mutant" that currently does nothing. It generates a random number and depending on that number moves a few pixels in that direction. I"m trying to figure out how to make the mutant follow the player's x & y coordinates when the player comes near.
Here is what my mutant does currently:
int xa = 0;
int ya = 0;
move = generator.nextInt(50) + 1;
if(move == (50))
ya = (random.nextInt(3) - 1) * random.nextInt(2);
if (!hasCollided(xa, ya))
if(move == 40)
ya = (random.nextInt(3) - 1) * random.nextInt(2);
if (!hasCollided(xa, ya))
if(move == 30)
xa = (random.nextInt(3) - 1) * random.nextInt(2);
if (!hasCollided(xa, ya))
if(move == 20)
xa = (random.nextInt(3) - 1) * random.nextInt(2);
if (!hasCollided(xa, ya))
if(xa != 0 || ya != 0) {
move(xa, ya);
isMoving = true;
} else {
isMoving = false;
}
Does anyone know how to make the mob simulate hostility towards the player? I haven't implemented a health system yet, I've only worked on the mob's A.I.