Пример #1
2
  public void startOpenAnimation(boolean finished) {

    TranslateTransition transition = new TranslateTransition();
    transition.setNode(this);
    transition.setDuration(Duration.millis(500));

    if (finished) {
      transition.setToX(0);
      transition.setOnFinished(
          ev -> {
            drawerOpen = false;
            actionBar.setDrawerOpen(false);
            oldX = 0;
            startX = 0;
          });
    } else {
      transition.setToX(getPrefWidth());
      transition.setOnFinished(
          ev -> {
            drawerOpen = true;
            actionBar.setDrawerOpen(true);
            oldX = 0;
            startX = 0;
          });
    }
    transition.play();
    animationFinished = false;
  }
Пример #2
0
  private void runProcessingAnimation(double duration) {
    timeline.setAutoReverse(true);
    timeline.setCycleCount(2);

    //        transitionRect = new TranslateTransition(Duration.millis(duration), rectangle);
    //        transitionCircle = new TranslateTransition(Duration.millis(duration), circle);
    transitionCircle.setDuration(Duration.millis(duration));
    transitionCircle.setNode(circle);
    transitionCircle.setAutoReverse(false);
    transitionCircle.setByX(150);
    transitionCircle.setFromX(0);

    transitionRect.setAutoReverse(false);
    transitionRect.setDuration(Duration.millis(duration));
    transitionRect.setNode(rectangle);
    transitionRect.setByX(150);
    transitionRect.setFromX(0);

    KeyValue keyValue = new KeyValue(imageViewTop.translateYProperty(), 90);
    KeyFrame keyFrame =
        new KeyFrame(
            Duration.millis(duration),
            (ActionEvent) -> {
              toggleHide(rectangle);
              transitionRect.play();
              transitionCircle.play();
              stackProducts(rectangle, imageViewRightStorage, this);
            },
            keyValue);

    timeline.getKeyFrames().clear();
    timeline.getKeyFrames().add(keyFrame);
    timeline.play();
  }
Пример #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 GameMenu() {

      VBox menu0 = new VBox(10);
      VBox menu1 = new VBox(10);
      VBox menu2 = new VBox(10);

      menu0.setTranslateX(100);
      menu0.setTranslateY(200);

      menu1.setTranslateX(100);
      menu1.setTranslateY(200);

      menu2.setTranslateX(100);
      menu2.setTranslateY(200);

      final int offset = 400;

      menu1.setTranslateX(offset);
      menu2.setTranslateX(offset);

      BlackjackMain.MenuButton btnNewGame = new BlackjackMain.MenuButton("NEW GAME");
      btnNewGame.setOnMouseClicked(
          event -> {
            FadeTransition ft = new FadeTransition(Duration.seconds(0.5), this);
            ft.setFromValue(1);
            ft.setToValue(0);
            ft.setOnFinished(evt -> setVisible(false));
            ft.play();
          });

      //			BlackjackMain.MenuButton btnResume = new BlackjackMain.MenuButton("RESUME");
      //			btnResume.setOnMouseClicked(event -> {
      //				FadeTransition ft = new FadeTransition(Duration.seconds(0.5), this);
      //				ft.setFromValue(1);
      //				ft.setToValue(0);
      //				ft.setOnFinished(evt -> setVisible(false));
      //				ft.play();
      //			});
      BlackjackMain.MenuButton btnOptions = new BlackjackMain.MenuButton("OPTIONS");
      btnOptions.setOnMouseClicked(
          event -> {
            getChildren().add(menu1);

            TranslateTransition tt = new TranslateTransition(Duration.seconds(0.25), menu0);
            tt.setToX(menu0.getTranslateX() - offset);

            TranslateTransition tt1 = new TranslateTransition(Duration.seconds(0.5), menu1);
            tt1.setToX(menu0.getTranslateX());

            tt.play();
            tt1.play();

            tt.setOnFinished(
                evt -> {
                  getChildren().remove(menu0);
                });
          });

      BlackjackMain.MenuButton btnExit = new BlackjackMain.MenuButton("EXIT");
      btnExit.setOnMouseClicked(
          event -> {
            System.exit(0);
          });

      BlackjackMain.MenuButton btnBack = new BlackjackMain.MenuButton("BACK");
      btnBack.setOnMouseClicked(
          event -> {
            getChildren().add(menu0);

            TranslateTransition tt = new TranslateTransition(Duration.seconds(0.25), menu1);
            tt.setToX(menu1.getTranslateX() + offset);

            TranslateTransition tt1 = new TranslateTransition(Duration.seconds(0.5), menu0);
            tt1.setToX(menu1.getTranslateX());

            tt.play();
            tt1.play();

            tt.setOnFinished(
                evt -> {
                  getChildren().remove(menu1);
                });
          });

      BlackjackMain.MenuButton btnSound = new BlackjackMain.MenuButton("SOUND");
      BlackjackMain.MenuButton btnVideo = new BlackjackMain.MenuButton("VIDEO");
      btnVideo.setOnMouseClicked(
          event -> {
            getChildren().add(menu2);

            TranslateTransition tt = new TranslateTransition(Duration.seconds(0.25), menu1);
            tt.setToX(menu1.getTranslateX() - offset);

            TranslateTransition tt1 = new TranslateTransition(Duration.seconds(0.5), menu2);
            tt1.setToX(menu1.getTranslateX());

            tt.play();
            tt1.play();

            tt.setOnFinished(
                evt -> {
                  getChildren().remove(menu1);
                });
          });

      BlackjackMain.MenuButton btnLowRes = new BlackjackMain.MenuButton("640x480");
      btnLowRes.setOnMouseClicked(
          event -> {
            windowWidth = 640;
            windowHeight = 480;
            /*stage.setHeight(windowHeight);
            stage.setWidth(windowWidth);
            */

          });

      BlackjackMain.MenuButton btnHighRes = new BlackjackMain.MenuButton("800x600");
      btnHighRes.setOnMouseClicked(
          event -> {
            windowWidth = 800;
            windowHeight = 600;
          });
      BlackjackMain.MenuButton btnBack2 = new BlackjackMain.MenuButton("BACK");
      btnBack2.setOnMouseClicked(
          event -> {
            getChildren().add(menu1);

            TranslateTransition tt = new TranslateTransition(Duration.seconds(0.25), menu2);
            tt.setToX(menu2.getTranslateX() + offset);

            TranslateTransition tt1 = new TranslateTransition(Duration.seconds(0.5), menu1);
            tt1.setToX(menu2.getTranslateX());

            tt.play();
            tt1.play();

            tt.setOnFinished(
                evt -> {
                  getChildren().remove(menu2);
                });
          });

      menu0.getChildren().addAll(btnNewGame, btnOptions, btnExit);
      menu1.getChildren().addAll(btnBack, btnSound, btnVideo);
      menu2.getChildren().addAll(btnBack2, btnLowRes, btnHighRes);

      Rectangle bg = new Rectangle(windowWidth, windowHeight);
      bg.setFill(Color.GREY);
      bg.setOpacity(0.8);

      getChildren().addAll(bg, menu0);
    }