Exemple #1
0
 /**
  * Sets the movement rates of the character towards another character.
  *
  * @param player the character to move towards
  */
 public void moveTowards(Character player) {
   if (Math.abs(player.getPos().getX() - this.getPos().getX())
       > Math.abs(player.getPos().getY() - this.getPos().getY())) {
     if (player.getPos().getX() > getPos().getX()) {
       setdx(1);
     } else if (player.getPos().getX() < getPos().getX()) {
       setdx(-1);
     } else {
       setdx(0);
     }
   } else {
     if (player.getPos().getY() > getPos().getY()) {
       setdy(1);
     } else if (player.getPos().getY() < getPos().getY()) {
       setdy(-1);
     } else {
       setdy(0);
     }
   }
 }
Exemple #2
0
 /** Sets the movment rates of the character to 0. */
 public void stop() {
   setdx(0);
   setdy(0);
 }