예제 #1
0
 public void followHuman() {
   int dist = 400;
   Actor kill = null;
   if (!getObjectsInRange(dist, Player.class).isEmpty()) {
     for (Object obj : getObjectsInRange(dist, Player.class)) {
       Actor guy = (Actor) obj;
       int guyDist = (int) Math.hypot(guy.getX() - getX(), guy.getY() - getY());
       if (kill == null || guyDist < dist) {
         kill = guy;
         dist = guyDist;
       }
     }
     turnTowards(kill.getX(), kill.getY());
   }
 }
예제 #2
0
 /**
  * If a target exist, status would appear above the target until the count down duration is 0. If
  * target is removed the status is removed as well.
  */
 public void act() {
   if (target != null) // if a target is assigned to a status
   {
     if (target.getWorld() != null) {
       setLocation(target.getX(), target.getY() - OFFSET); // offset myImage above the actor
       update(1); // update the image with the actual countdown(not controlled by keyboard)
     } else removeStatus(); // remove status along with actor
   }
 }
예제 #3
0
 /**
  * Method climbRope
  *
  * @param num Amount to move. Positive for up, negative for down.
  */
 public void climbRope(int num) {
   Actor rope = getOneIntersectingObject(Rope.class);
   if (rope != null) {
     curSpeed = 0; // Prevents player from flying off rope from momentum
     onRope = true;
     if (num > 0
         && (rope.getY() - rope.getImage().getHeight() / 2) - getY()
             < -30) { // Only allows up movement if the player is under the top of the rope
       setLocation(getX(), getY() - num);
     }
     // If the player moves down the rope, off the length of the rope, the player
     // is considered off the rope
     else if (num < 0) {
       setLocation(getX(), getY() - num);
       if (getY() - (rope.getY() + rope.getImage().getHeight() / 2) > 0) {
         onRope = false;
       }
     }
   }
 }