Пример #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());
   }
 }
 /**
  * Get the distance to the ScrollingActor.
  *
  * @return The distance between this object and the ScrollingActor.
  */
 public double getDistanceToScrollingActor() {
   List<ScrollingActor> actors = getWorld().getObjects(ScrollingActor.class);
   if (actors != null && !actors.isEmpty()) {
     ScrollingActor actor = null;
     for (ScrollingActor scrollingActor : actors) {
       if (scrollingActor.isScrollingCenter()) {
         actor = scrollingActor;
       }
     }
     if (actor == null) {
       System.err.println("No scrollingActor in the world.");
       return 0;
     }
     return Math.hypot(getExactX() - actor.getExactX(), getExactY() - actor.getExactY());
   }
   return 0;
 }