Exemplo n.º 1
0
  public static Timeline moveAlongPath(
      Path<GridPoint2> path, float stepDuration, Object target, int tweenType) {
    Timeline timeline = Timeline.createSequence();

    for (GridPoint2 point : path.getPoints()) {
      timeline = timeline.push(Tween.to(target, tweenType, stepDuration).target(point.x, point.y));
    }

    return timeline;
  }
Exemplo n.º 2
0
  @Override
  protected Timeline showAnimation() {
    this.levelStartAnimation = Timeline.createSequence();

    float y = (stage.getHeight() + this.levelImage.getHeight()) / 2f;
    Tween slideinTween =
        Tween.to(this.levelImage, ActorAccessor.POSITION_Y, 1f)
            .ease(TweenEquations.easeInOutQuint)
            .target(y);
    slideinTween.setCallbackTriggers(TweenCallback.COMPLETE);
    slideinTween.setCallback(
        new TweenCallback() {

          @Override
          public void onEvent(int arg0, BaseTween<?> arg1) {
            levelStartAnimation.pause();
            imageStartAnimationFinished = true;
            startScreenCloseAnimation();
          }
        });
    this.levelStartAnimation.push(slideinTween);

    this.levelStartAnimation.push(Tween.to(this.filter, ActorAccessor.ALPHA, 0.5f).target(0f));

    y = stage.getHeight() + levelImage.getHeight();
    Tween slideoutTween =
        Tween.to(this.levelImage, ActorAccessor.POSITION_Y, 0.5f)
            .ease(TweenEquations.easeInQuint)
            .target(y);
    slideoutTween.setCallbackTriggers(TweenCallback.COMPLETE);
    slideoutTween.setCallback(
        new TweenCallback() {

          @Override
          public void onEvent(int arg0, BaseTween<?> arg1) {
            levelImage.remove();
            filter.remove();
            MusicPlayer.getInstance().playNext();
            getGameEngine().startGamePlay();
          }
        });
    levelStartAnimation.push(slideoutTween);

    return this.levelStartAnimation;
  }
Exemplo n.º 3
0
  @Override
  public void show() {
    state = State.INITIALIZING;
    setBackground(Assets.bg);
    getBackgroundBounds().x = -100;
    getBackgroundBounds().y = -100;
    getBackgroundBounds().width = EatFishAndAI.WIDTH + 200;
    getBackgroundBounds().height = EatFishAndAI.HEIGHT + 200;

    spawner = new DummySpawner();
    spawner.setGameContext(getGameContext());

    gameNameLayout = new GlyphLayout();
    gameNameLayout.setText(Assets.font30, conf.gamename);

    // Preset predator ai
    // int offset = 100;
    // getGameContext().spawn(
    // new PredatorFish(EatFishAndAI.WIDTH - offset,
    // EatFishAndAI.HEIGHT - offset));
    // getGameContext().spawn(
    // new PredatorFish(EatFishAndAI.WIDTH - offset, offset));
    // getGameContext().spawn(
    // new PredatorFish(offset, EatFishAndAI.HEIGHT - offset));
    // getGameContext().spawn(new PredatorFish(offset, offset));
    List<AIFactory<?>> factories = conf.aiconf.getAIs();
    int count = factories.size(), radius = 150;
    float angle = (float) (2 * Math.PI / count);
    float angleOffset = (float) (Math.PI / 4);
    float randomOffset = (float) ((int) (Math.random() * 4) * Math.PI / 2);
    System.out.println(randomOffset);
    boolean newGame = conf.players.isEmpty();
    for (int i = 0; i < conf.aiconf.getAIs().size(); i++) {
      PlayerFish player;
      if (newGame) {
        player =
            new PlayerFish(
                (float)
                    (centerX
                        - PlayerFish.WIDTH / 2
                        + Math.cos(i * angle + angleOffset + randomOffset) * radius),
                (float)
                    (centerY
                        - PlayerFish.HEIGHT / 2
                        + Math.sin(i * angle + angleOffset + randomOffset) * radius));
        conf.players.add(player);
      } else {
        player = conf.players.get(i);
        player.killAI();
        player.setX(
            (float)
                (centerX
                    - PlayerFish.WIDTH / 2
                    + Math.cos(i * angle + angleOffset + randomOffset) * radius));
        player.setY(
            (float)
                (centerY
                    - PlayerFish.HEIGHT / 2
                    + Math.sin(i * angle + angleOffset + randomOffset) * radius));
        player.setVelocityX(0);
        player.setVelocityY(0);
        player.setMaxSpeed(PlayerFish.MAX_SPEED);
        player.setScale(PlayerFish.STARTING_SCALE);
        player.setAlive(true);
      }

      getGameContext().spawn(player);
      player.setGameContext(getGameContext());
      player.attachAI(factories.get(i).newInstance());
      player.start();
    }

    conf.playersAlive = new ArrayList<>(conf.players);

    getGameContext().spawn(new RoundScore(conf, playerListX, playerListY));

    CustomTextButton stopButton =
        new CustomTextButton(EatFishAndAI.WIDTH - CustomTextButton.WIDTH, 0, "STOP");

    stopButton.setButtonListener(
        new ButtonListener() {

          @Override
          public void handle(ButtonAction ba) {
            if (ba.type == TYPE.RELEASE) {
              game.setScreen(new MenuScreen((EatFishAndAI) game));
            }
          }
        });

    CustomTextButton killButton =
        new CustomTextButton(EatFishAndAI.WIDTH - 2 * CustomTextButton.WIDTH, 0, "KILL");

    killButton.setButtonListener(
        new ButtonListener() {

          @Override
          public void handle(ButtonAction ba) {
            if (ba.type == TYPE.RELEASE) {

              PlayerFish biggest = conf.playersAlive.get(0);
              for (PlayerFish o : conf.playersAlive) {
                if (o.getScale() > biggest.getScale()) {
                  biggest = o;
                }
              }

              while (conf.playersAlive.size() > 1) {
                int randomIndex = (int) (Math.random() * conf.playersAlive.size());
                PlayerFish fish = conf.playersAlive.get(randomIndex);
                if (fish.equals(biggest)) {
                  continue;
                }
                conf.playersAlive.remove(fish);
                fish.destroy();
              }
            }
          }
        });

    getGameContext().spawn(killButton);
    getGameContext().spawn(stopButton);

    state = State.STARTING;

    Timeline all = Timeline.createSequence();
    for (PlayerFish player : conf.playersAlive) {
      all.push(CommonTweens.zoomAtGameObject(player, getCamera(), 3.0f, 1.0f));
    }
    all.push(CommonTweens.zoomAtPoint(centerX, centerY, getCamera(), 1.0f, 1.0f));
    all.setCallback(
        new TweenCallback() {

          @Override
          public void onEvent(int type, BaseTween<?> source) {
            if (type == TweenCallback.COMPLETE) {
              state = State.PLAYING;
              getGameContext().setPaused(false);
            }
          }
        });
    GlobalTween.add(all);

    getGameContext().spawn(new OverallScore(conf, EatFishAndAI.WIDTH - 300, EatFishAndAI.HEIGHT));

    getGameContext().update(1);
    getGameContext().setPaused(true);
  }