Here I will post all of the code that I am using for a movement system for my skeleton. PlayerChar is the player, and "skelly" is the world.
This is in the skeleton's class.
This is in the "skelly" class.
public void act()
{
directionCheck();
move();
healthCheck();
attack();
deadCheck();
}
public void directionCheck()
{
if (player.getX() > this.getX())
{
directionX = (1);
}
if (player.getX() < this.getX())
{
directionX = (2);
}
if (player.getY() > this.getY())
{
directionY = (1);
}
if (player.getY() < this.getY())
{
directionY = (2);
}
}public class skelly extends World
{
public PlayerChar thePlayer;
public Skeleton skeleton1;
/**
* Constructor for objects of class skelly.
*
*/
public skelly()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
skeleton1 = new Skeleton();
addObject(skeleton1, 300, 200);
thePlayer = new PlayerChar();
addObject(thePlayer, 5, 5);
}
public PlayerChar getPlayer()
{
return thePlayer;
}
}



