/** * 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 } }
/** * 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; } } } }
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()); } }
/** * Set the players location if possible. * * @param x The new x location of the actor. * @param y The new y location of the actor. */ public void setLocation(double x, double y) { if (ScrollingWorld.WORLD_WIDTH != 0) { if (getDistanceToScrollingActor('x') - getWorld().getTotalXMovement() > ScrollingWorld.WORLD_WIDTH / 2) { x = getStartingPoint().getX() + ScrollingWorld.WORLD_WIDTH / 2; } else if (getDistanceToScrollingActor('x') - getWorld().getTotalXMovement() < -ScrollingWorld.WORLD_WIDTH / 2) { x = getStartingPoint().getX() - ScrollingWorld.WORLD_WIDTH / 2; } } if (ScrollingWorld.WORLD_HEIGHT != 0) { if (getDistanceToScrollingActor('y') - getWorld().getTotalYMovement() > ScrollingWorld.WORLD_HEIGHT / 2) { y = getStartingPoint().getY() + ScrollingWorld.WORLD_HEIGHT / 2; } else if (getDistanceToScrollingActor('y') - getWorld().getTotalYMovement() < -ScrollingWorld.WORLD_HEIGHT / 2) { y = getStartingPoint().getY() - ScrollingWorld.WORLD_HEIGHT / 2; } } exactX = x; exactY = y; super.setLocation((int) x, (int) y); }