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());
   }
 }
 public boolean checkCollision(Actor actor) {
   int actorX = actor.toPixel(actor.getX());
   int actorY = actor.toPixel(actor.getY());
   int dx = actorX - this.x;
   int dy = actorY - this.y;
   int dist = (int) Math.sqrt((double) (dx * dx + dy * dy));
   return dist <= this.r;
 }
示例#3
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
   }
 }