示例#1
2
 @Override
 public void handle(MouseEvent t) {
   // move circle back to origin
   TranslateTransition move =
       new TranslateTransition(new Duration(200), (Circle) (t.getSource()));
   move.setToX(translateX);
   move.setToY(translateY);
   move.playFromStart();
 }
示例#2
0
 public Step move(double newX, double newY) {
   TranslateTransition transition = new TranslateTransition();
   transition.setNode(group);
   transition.setToX(newX - xCenter);
   transition.setToY(newY - yCenter);
   transition.setDuration(Duration.millis(1000d));
   return new TransitionStep(transition);
 }
示例#3
0
  /**
   * Defines the characteristics of a <i>TranslateTransition</i>. Each call results in ONE segment
   * of motion. When that segment is finished, it "chains" another call to <i>startMotion()</i>
   * (which is NOT recursion)! The initial call is made by the managing <i>Army</i> object;
   * subsequent calls are made through the "chaining" process described here.
   *
   * @param engageInCombat TODO
   */
  public void startMotion(boolean engageInCombat) {
    Army opposingArmy = armyAllegiance.getOpposingArmy();
    Actor opponent =
        opposingArmy.findNearestOpponent(
            this); // could legitimately return a null: 1) no one is visible 2) no Actors in
                   // opposing army

    Point2D newLocation;
    if (opponent != null) {
      System.out.printf(
          "ToMove:[%.1f:%.1f] Opponent:[%.1f:%.1f]\n",
          getAvatar().getTranslateX(),
          getAvatar().getTranslateY(),
          opponent.getAvatar().getTranslateX(),
          opponent.getAvatar().getTranslateX());
      double DISTANCE_FOR_BATTLE = 50.0;
      if (engageInCombat && distanceTo(opponent) < DISTANCE_FOR_BATTLE) {
        double h1, h2, h3, h4; // debug code
        h1 = this.getHealth();
        h2 = opponent.getHealth();

        combatRound(opponent);
        h3 = this.getHealth();
        h4 = opponent.getHealth();
        h4 = h4;
        if (this.getHealth() <= 0.0) {
          armyAllegiance.removeNowDeadActor(this);
        }
        if (opponent.getHealth() <= 0.0) {
          opponent.armyAllegiance.removeNowDeadActor(opponent);
        }
      } // end if (combat)
      newLocation = findNewLocation(opponent);
    } else // end if (test for null opponent)
    newLocation = meander(); // null opponent means we wander around close to our current location

    if (tt.getStatus()
        != Animation.Status.RUNNING) { // if NOT yet RUNNING, start . . . otherwise, do nothing.
      // tt.setToX(Math.random()*getAvatar().getScene().getWidth());
      // tt.setToY(Math.random()*getAvatar().getScene().getHeight());
      tt.setToX(validateCoordinate(newLocation).getX());
      tt.setToY(validateCoordinate(newLocation).getY());
      tt.setDuration(
          Duration.seconds(MAX_SPEED / (getSpeed() * (armyAllegiance.getSpeedControllerValue()))));
      tt.setOnFinished(event -> startMotion(true)); // NOT RECURSION!!!!
      tt
          .play(); // give assembled object to the render engine (of course, play() is an
                   // object-oriented method which has access to "this" inside, and it can use
                   // "this" to give to the render engine.
    }
  } // end startMotion()
示例#4
0
 public void readyToGoAnimation() {
   // Sync progress bar slides out ...
   TranslateTransition leave = new TranslateTransition(Duration.millis(600), syncBox);
   leave.setByY(80.0);
   // Buttons slide in and clickable address appears simultaneously.
   TranslateTransition arrive = new TranslateTransition(Duration.millis(600), controlsBox);
   arrive.setToY(0.0);
   FadeTransition reveal = new FadeTransition(Duration.millis(500), addressControl);
   reveal.setToValue(1.0);
   ParallelTransition group = new ParallelTransition(arrive, reveal);
   // Slide out happens then slide in/fade happens.
   SequentialTransition both = new SequentialTransition(leave, group);
   both.setCycleCount(1);
   both.setInterpolator(Interpolator.EASE_BOTH);
   both.play();
 }
  private SequentialTransition createTransition(
      final Point2D pntStartPoint, final Point2D pntEndPoint, ImageView imView) {

    imView =
        new ImageView(
            new Image(getClass().getResourceAsStream("/res/img/b1fh.png"), 75, 75, true, true));

    imView.setX(pntStartPoint.getX());
    imView.setY(pntStartPoint.getY() - 30);

    APMainScreen.getChildren().add(imView);

    TranslateTransition translateTransition = new TranslateTransition(Duration.millis(300), imView);
    translateTransition.setFromX(0);
    translateTransition.setToX(pntEndPoint.getX() - pntStartPoint.getX());
    translateTransition.setFromY(0);
    translateTransition.setToY(pntEndPoint.getY() - pntStartPoint.getY());

    translateTransition.setCycleCount(1);
    translateTransition.setAutoReverse(false);

    int rnd = randInt(1, 3);

    RotateTransition rotateTransition = new RotateTransition(Duration.millis(150), imView);
    rotateTransition.setByAngle(90F);
    rotateTransition.setCycleCount(rnd);
    rotateTransition.setAutoReverse(false);

    ParallelTransition parallelTransition = new ParallelTransition();
    parallelTransition.getChildren().addAll(translateTransition, rotateTransition);

    SequentialTransition seqTrans = new SequentialTransition();
    seqTrans.getChildren().addAll(parallelTransition);

    final ImageView ivRemove = imView;
    seqTrans.setOnFinished(
        new EventHandler<ActionEvent>() {

          @Override
          public void handle(ActionEvent arg0) {
            APMainScreen.getChildren().remove(ivRemove);
          }
        });

    return seqTrans;
  }
示例#6
0
  // for shots created with the space bar, trigonometry is
  // used to find the angle that the user's mouse was to the
  // origin and to extend the shot past the user's click to
  // the edge of the screen.
  private void initializeShot() {

    double miniHypot;
    double largeHypot;
    double edgePoint;
    double distance;
    TranslateTransition translate;

    // four different quadrants of the screen mean that the angles
    // must be processed four different ways, and that the
    // transitions must be added to the shots in four different ways.
    // the algebra is different in each if statement; the first is
    // commented as an example

    // if the click was on the left of Earth
    if (_mouse.getXCoord() < Constants.ORIGIN) {
      // if the click was above Earth
      if (_mouse.getYCoord() <= Constants.ORIGIN) {
        // get the distance of the mini hypoteneuse made with the click
        miniHypot =
            Math.sqrt(
                Math.pow((Constants.ORIGIN - _mouse.getXCoord()), 2)
                    + Math.pow((Constants.ORIGIN - _mouse.getYCoord()), 2));
        // extend that distance to the edge of the screen
        largeHypot = ((Constants.ORIGIN / (Constants.ORIGIN - _mouse.getXCoord())) * miniHypot);
        // calculate the y point based on that distance
        edgePoint = Math.sqrt(Math.pow(largeHypot, 2) - Math.pow(Constants.ORIGIN, 2));

        // get the distance between the new point and the origin
        distance = (Math.sqrt(Math.pow(-Constants.ORIGIN, 2) + Math.pow((-edgePoint), 2)));

        // create a translation with a constant rate for almost all angles
        translate =
            new TranslateTransition(
                Duration.millis(
                    Constants.SHOT_RATE_CONSTANT
                        * ((distance % Constants.SHOT_RATE_UPPER_BOUND)
                            + Constants.SHOT_RATE_LOWER_BOUND)));
        // send the shot all the way to the left
        translate.setToX(-Constants.ORIGIN);
        // send the shot up to the right point
        translate.setToY(-edgePoint);
      } else {
        miniHypot =
            Math.sqrt(
                Math.pow((Constants.ORIGIN - _mouse.getXCoord()), 2)
                    + Math.pow((_mouse.getYCoord() - Constants.ORIGIN), 2));
        largeHypot = ((Constants.ORIGIN / (Constants.ORIGIN - _mouse.getXCoord())) * miniHypot);
        edgePoint = Math.sqrt(Math.pow(largeHypot, 2) - Math.pow(Constants.ORIGIN, 2));

        distance = (Math.sqrt(Math.pow(-Constants.ORIGIN, 2) + Math.pow((edgePoint), 2)));

        translate =
            new TranslateTransition(
                Duration.millis(
                    Constants.SHOT_RATE_CONSTANT
                        * ((distance % Constants.SHOT_RATE_UPPER_BOUND)
                            + Constants.SHOT_RATE_LOWER_BOUND)));
        translate.setToX(-Constants.ORIGIN);
        translate.setToY(edgePoint);
      }
    } else if (_mouse.getXCoord() > Constants.ORIGIN) {
      if (_mouse.getYCoord() <= Constants.ORIGIN) {
        miniHypot =
            Math.sqrt(
                Math.pow((_mouse.getXCoord() - Constants.ORIGIN), 2)
                    + Math.pow((Constants.ORIGIN - _mouse.getYCoord()), 2));
        largeHypot =
            (((_scene.getWidth() - Constants.ORIGIN) / (_mouse.getXCoord() - Constants.ORIGIN))
                * miniHypot);
        edgePoint =
            Math.sqrt(
                Math.pow(largeHypot, 2) - Math.pow((_scene.getWidth() - Constants.ORIGIN), 2));

        distance =
            (Math.sqrt(
                Math.pow((_scene.getWidth() - Constants.ORIGIN), 2) + Math.pow((-edgePoint), 2)));

        translate =
            new TranslateTransition(
                Duration.millis(
                    Constants.SHOT_RATE_CONSTANT
                        * ((distance % Constants.SHOT_RATE_UPPER_BOUND)
                            + Constants.SHOT_RATE_LOWER_BOUND)));
        translate.setToX(_scene.getWidth() - Constants.ORIGIN);
        translate.setToY(-edgePoint);
      } else {
        miniHypot =
            Math.sqrt(
                Math.pow((_mouse.getXCoord() - Constants.ORIGIN), 2)
                    + Math.pow((_mouse.getYCoord() - Constants.ORIGIN), 2));
        largeHypot =
            (((_scene.getWidth() - Constants.ORIGIN) / (_mouse.getXCoord() - Constants.ORIGIN))
                * miniHypot);
        edgePoint =
            Math.sqrt(
                Math.pow(largeHypot, 2) - Math.pow((_scene.getWidth() - Constants.ORIGIN), 2));

        distance =
            (Math.sqrt(
                Math.pow((_scene.getWidth() - Constants.ORIGIN), 2) + Math.pow((edgePoint), 2)));

        translate =
            new TranslateTransition(
                Duration.millis(
                    Constants.SHOT_RATE_CONSTANT
                        * ((distance % Constants.SHOT_RATE_UPPER_BOUND)
                            + Constants.SHOT_RATE_LOWER_BOUND)));
        translate.setToX(_scene.getWidth() - Constants.ORIGIN);
        translate.setToY(edgePoint);
      }
    }
    // the case if the X coordinate of the mouse is equal to the origin
    // prevents a divide by zero error by substituting in a fake edgepoint calculation
    else {
      if (_mouse.getYCoord() <= Constants.ORIGIN) {
        edgePoint =
            Math.sqrt(Math.pow(Constants.DIVIDE_BY_ZERO_CATCH, 2) - Math.pow(Constants.ORIGIN, 2));

        distance = (Math.sqrt(Math.pow(-Constants.ORIGIN, 2) + Math.pow((edgePoint), 2)));

        translate =
            new TranslateTransition(
                Duration.millis(
                    Constants.SHOT_RATE_CONSTANT
                        * ((distance % Constants.SHOT_RATE_UPPER_BOUND)
                            + Constants.SHOT_RATE_LOWER_BOUND)));
        translate.setToX(-Constants.ORIGIN);
        translate.setToY(-edgePoint);
      } else {
        edgePoint =
            Math.sqrt(Math.pow(Constants.DIVIDE_BY_ZERO_CATCH, 2) - Math.pow(Constants.ORIGIN, 2));

        distance = (Math.sqrt(Math.pow(-Constants.ORIGIN, 2) + Math.pow((edgePoint), 2)));

        translate =
            new TranslateTransition(
                Duration.millis(
                    Constants.SHOT_RATE_CONSTANT
                        * ((distance % Constants.SHOT_RATE_UPPER_BOUND)
                            + Constants.SHOT_RATE_LOWER_BOUND)));
        translate.setToX(-Constants.ORIGIN);
        translate.setToY(edgePoint);
      }
    }

    ArrayList<Transition> animations = new ArrayList<Transition>();
    animations.add(translate);

    this.setAnimations(animations);
  }