package class8_1_SimplifiedTourists_BinaryIO_start; import javafx.geometry.Point2D; import javafx.scene.paint.Color; import javafx.scene.shape.Circle; public class Person extends MobileEntity { public static final int PERSON_MAX_SPEED = 2; private Goal goal; public Person(Goal goal) { super(); setName("You"); stepSize = new Point2D(0,0); this.goal = goal; } @Override protected void step() { Point2D direction = goal.getTarget().subtract(getLocation()); if(Math.hypot(direction.getX(), direction.getY()) < PERSON_MAX_SPEED) { // last step to goal stepSize = direction; } else { // approaching goal stepSize = direction.multiply(PERSON_MAX_SPEED / Math.hypot(direction.getX(), direction.getY())); } super.step(); } /** * The circular shape on the map that the person approaches. */ public static class Goal { public static final int RADIUS = 100; private final Circle personTarget; public Goal() { personTarget = new Circle(RADIUS); personTarget.setStroke(Color.GREEN); personTarget.setFill(Color.GREEN.deriveColor(1, 1, 1, 0.2)); personTarget.relocate(0, 0); } public Point2D getTarget() { return new Point2D(personTarget.getCenterX(),personTarget.getCenterY()).add(RADIUS, RADIUS); } } }