/** * Get one component of the distance to the ScrollingActor. * * @param component You can choose which component you want. It has to be eighter 'x' or 'y'. * @return The component of the distance between the both objects. */ public double getDistanceToScrollingActor(char component) throws IllegalArgumentException { if (component == 'x') { 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 getExactX() - actor.getExactX(); } } else if (component == 'y') { 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 getExactY() - actor.getExactY(); } } else { throw new IllegalArgumentException("component (" + component + ") must be either 'x' or 'y'"); } return 0; }
/** * 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; }
/** * Get the location of the starting point (the world coordinates (0|0)). * * @return The starting point of the scrolling world. */ public java.awt.Point getStartingPoint() { 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 null; } int x = actor.getX() + getWorld().getTotalXMovement(); int y = actor.getY() + getWorld().getTotalYMovement(); return new Point(x, y); } return null; }