コード例 #1
0
ファイル: GameScreen.java プロジェクト: falvarez/rectball
  /**
   * Create a countdown in the screen lasting for the amount of seconds given. When the countdown
   * reaches 0, the code provided in the runnable will be executed as a callback.
   *
   * @param seconds how many seconds should the countdown be displayed.
   */
  private void countdown(final int seconds, final Runnable after) {
    // Since this is a recursive function, avoid the case where you pass
    // a number of seconds that might trigger an infinite loop.
    if (seconds <= 0) {
      return;
    }

    // Create the label that will contain this number
    String number = Integer.toString(seconds);
    final Label label = new Label(number, game.getSkin(), "monospace");
    label.setFontScale(5f);
    label.setSize(150, 150);
    label.setAlignment(Align.center);
    label.setPosition(
        (getStage().getWidth() - label.getWidth()) / 2,
        (getStage().getHeight() - label.getHeight()) / 2);

    // Add the label to the stage and play a sound to notify the user.
    getStage().addActor(label);
    game.player.playSound(SoundCode.SELECT);

    label.addAction(
        Actions.sequence(
            Actions.parallel(Actions.moveBy(0, 80, 1f)),

            // After the animation, decide. If the countdown hasn't finished
            // yet, run another countdown with 1 second less.
            Actions.run(
                new Runnable() {
                  @Override
                  public void run() {
                    label.remove();
                    if (seconds > 1) {
                      countdown(seconds - 1, after);
                    } else {
                      after.run();
                    }
                  }
                })));
  }
コード例 #2
0
ファイル: GameScreen.java プロジェクト: falvarez/rectball
  private void showPartialScore(int score, Bounds bounds, boolean special) {
    // Calculate the center of the region.
    BallActor bottomLeftBall = board.getBall(bounds.minX, bounds.minY);
    BallActor upperRightBall = board.getBall(bounds.maxX, bounds.maxY);

    float minX = bottomLeftBall.getX();
    float maxX = upperRightBall.getX() + upperRightBall.getWidth();
    float minY = bottomLeftBall.getY();
    float maxY = upperRightBall.getY() + upperRightBall.getHeight();
    float centerX = (minX + maxX) / 2;
    float centerY = (minY + maxY) / 2;

    Label label = new Label("+" + score, game.getSkin(), "monospace");
    label.setFontScale(5f);
    label.setSize(140, 70);
    label.setAlignment(Align.center);
    label.setPosition(centerX - label.getWidth() / 2, centerY - label.getHeight() / 2);
    label.addAction(Actions.sequence(Actions.moveBy(0, 80, 0.5f), Actions.removeActor()));
    getStage().addActor(label);

    if (special) {
      label.setColor(Color.CYAN);
    }
  }
コード例 #3
0
  @Override
  public synchronized void run() {
    Texture rawImg = resources.get("images/bullet1.jpg", Texture.class);
    TextureRegion bimg;
    Enemy e;
    Bullet b;
    checkTime(1000);
    // first five
    e =
        PowerElf.newPowerElf(
            (World.CAMERA_WIDTH - Butterfly.WIDTH) / 2f - PowerElf.WIDTH,
            World.CAMERA_HEIGHT,
            resources,
            world,
            60);
    e.addAction(
        Actions.sequence(
            Actions.moveBy(0, -16f, 1), Actions.moveBy(0, 0, 3f), Actions.moveBy(0, 32f, 2)));
    bimg = new TextureRegion(rawImg, 32, 248, 8, 8);
    b = Bullet.newEnemyBullet(0, 0, 0.5f, 0.5f, 0.25f, bimg, world);
    e.setShootPattern(new AllRangeShoot(6, 1, 2f, e, b, 0.2f, 12));
    world.addEnemy(e);
    e =
        PointElf.newPointElf(
            (World.CAMERA_WIDTH + Butterfly.WIDTH) / 2f, World.CAMERA_HEIGHT, resources, world, 60);
    e.addAction(
        Actions.sequence(
            Actions.moveBy(0, -16f, 1), Actions.moveBy(0, 0, 3f), Actions.moveBy(0, 32f, 2)));
    e.setShootPattern(new AllRangeShoot(6, 1, 2f, e, b, 0.2f, 12));
    world.addEnemy(e);
    e =
        Butterfly.newButterfly(
            (World.CAMERA_WIDTH - Butterfly.WIDTH) / 2f,
            World.CAMERA_HEIGHT,
            resources,
            world,
            100);
    e.addAction(
        Actions.sequence(
            Actions.moveBy(0, -16f, 1), Actions.moveBy(0, 0, 3f), Actions.moveBy(0, 32f, 2)));
    bimg = new TextureRegion(rawImg, 32, 16, 16, 16);
    b = Bullet.newEnemyBullet(0, 0, 1f, 1f, 0.4f, bimg, world);
    b.setRotation(-90);
    b.setOrigin(b.getWidth() / 2f, b.getHeight() / 2f);
    e.setShootPattern(new AllRangeShoot(6, 1, 2, e, b, 0.2f, 36));
    world.addEnemy(e);
    checkTime(1000 >> 3);
    e =
        PowerElf.newPowerElf(
            (World.CAMERA_WIDTH - Butterfly.WIDTH) / 2f - PowerElf.WIDTH,
            World.CAMERA_HEIGHT,
            resources,
            world,
            60);
    e.addAction(
        Actions.sequence(
            Actions.moveBy(0, -14f, 14f / 16f),
            Actions.moveBy(0, 0, 3f),
            Actions.moveBy(0, 32f, 2)));
    bimg = new TextureRegion(rawImg, 32, 248, 8, 8);
    b = Bullet.newEnemyBullet(0, 0, 0.5f, 0.5f, 0.25f, bimg, world);
    e.setShootPattern(new AllRangeShoot(6, 1, 2f, e, b, 0.2f, 12));
    world.addEnemy(e);
    e =
        PointElf.newPointElf(
            (World.CAMERA_WIDTH + Butterfly.WIDTH) / 2f, World.CAMERA_HEIGHT, resources, world, 60);
    e.addAction(
        Actions.sequence(
            Actions.moveBy(0, -14f, 14f / 16f),
            Actions.moveBy(0, 0, 3f),
            Actions.moveBy(0, 32f, 2)));
    e.setShootPattern(new AllRangeShoot(6, 1, 2f, e, b, 0.2f, 12));
    world.addEnemy(e);

    // yinyangyu
    checkTime(6500);
    bimg = new TextureRegion(rawImg, 64, 208, 32, 32);
    b = Bullet.newEnemyBullet(0, 0, 2f, 2f, 0.8f, bimg, world);
    b.setRotation(-90);
    for (int i = 0; i < 5; ++i) {
      checkTime(500);
      e = PointYinyangyu.newPointYinyangyu(0, World.CAMERA_HEIGHT * 0.9f, resources, world, 50);
      e.setOrigin(0, -10);
      e.addAction(
          Actions.sequence(
              Actions.moveBy(15, 0, 1),
              Actions.repeat(2, Actions.rotateBy(-360, 4f)),
              Actions.moveBy(30, 0, 2)));
      e.setShootPattern(new AimShoot(300, 0.5f, 2, e, b, 1, 9, 0.4f));
      world.addEnemy(e);
      checkTime(500);
      e =
          PowerYinyangyu.newPowerYinyangyu(
              World.CAMERA_WIDTH, World.CAMERA_HEIGHT * 0.9f, resources, world, 50);
      e.setOrigin(0, -10);
      e.addAction(
          Actions.sequence(
              Actions.moveBy(-15, 0, 1),
              Actions.repeat(2, Actions.rotateBy(360, 4f)),
              Actions.moveBy(-30, 0, 2)));
      e.setShootPattern(new AimShoot(300, 0.5f, 2, e, b, 1, 9, 0.4f));
      world.addEnemy(e);
    }

    // elf
    checkTime(6500);
    bimg = new TextureRegion(rawImg, 208, 64, 16, 16);
    b = Bullet.newEnemyBullet(0, 0, 1, 1, 0.25f, bimg, world);
    b.setRotation(-90);
    for (int i = 0; i < 6; ++i) {
      checkTime(2000);
      for (int j = 0; j < 6; ++j) {
        e =
            PowerElf.newPowerElf(
                ((j << 1) + 1) * PowerElf.WIDTH, World.CAMERA_HEIGHT, resources, world, 40);
        e.addAction(
            Actions.repeat(
                RepeatAction.FOREVER,
                Actions.sequence(
                    Actions.moveBy(0, -2, 0.5f),
                    Actions.moveBy(2, 0, 0.5f),
                    Actions.moveBy(0, -2, 0.5f),
                    Actions.moveBy(-2, 0, 0.5f))));
        e.setShootPattern(new OneShoot(2, 0, 1f, e, b, 0.3f, -90));
        world.addEnemy(e);
      }
      checkTime(2000);
      for (int j = 0; j < 6; ++j) {
        e =
            PointElf.newPointElf(
                World.CAMERA_WIDTH - PointElf.WIDTH * ((j + 1) << 1),
                World.CAMERA_HEIGHT,
                resources,
                world,
                40);
        e.addAction(
            Actions.repeat(
                RepeatAction.FOREVER,
                Actions.sequence(
                    Actions.moveBy(0, -2, 0.5f),
                    Actions.moveBy(-2, 0, 0.5f),
                    Actions.moveBy(0, -2, 0.5f),
                    Actions.moveBy(2, 0, 0.5f))));
        e.setShootPattern(new OneShoot(2, 0, 1f, e, b, 0.3f, -90));
        world.addEnemy(e);
      }
    }

    // nue elf
    checkTime(24000);
    for (int i = 0; i < 4; ++i) {
      if (i % 2 == 0) {
        bimg = new TextureRegion(rawImg, 96, 96, 16, 16);
        b = Bullet.newEnemyBullet(0, 0, 1, 1, 0.25f, bimg, world);
        for (int j = 0; j < 10; ++j) {
          checkTime(300);
          e =
              PointElf.newPointElf(
                  World.CAMERA_WIDTH, World.CAMERA_HEIGHT * 0.8f, resources, world, 40);
          e.setOrigin(-20, 20);
          e.addAction(Actions.sequence(Actions.rotateBy(-180, 10), Actions.moveBy(100, 100)));
          final int n = i + 1;
          e.setShootPattern(
              new ShootPattern(10, 3 - j * 0.3f, 30, e, b, 0.4f) {
                @Override
                public void shoot() {
                  Bullet toShoot;
                  float deltaDeg = 360f / n;
                  float startDeg = parent.getRotation() - 90;
                  for (int k = 0; k < n; ++k) {
                    float deg = startDeg + k * deltaDeg;
                    toShoot = getBullet();
                    toShoot.setPosition(parent.getCheckX(), parent.getCheckY());
                    toShoot.setOrigin(toShoot.getWidth() / 2f, toShoot.getHeight() / 2f);
                    toShoot.setRotation(deg - 90);
                    toShoot.addAction(
                        Actions.repeat(
                            RepeatAction.FOREVER,
                            Actions.moveBy(
                                speed * MathUtils.cosDeg(deg), speed * MathUtils.sinDeg(deg))));
                    world.addEnemyBullet(toShoot);
                  }
                }
              });
          world.addEnemy(e);
        }
      } else {
        bimg = new TextureRegion(rawImg, 32, 96, 16, 16);
        b = Bullet.newEnemyBullet(0, 0, 1, 1, 0.25f, bimg, world);
        for (int j = 0; j < 10; ++j) {
          checkTime(300);
          e =
              PowerElf.newPowerElf(
                  -PowerElf.WIDTH, World.CAMERA_HEIGHT * 0.8f, resources, world, 60);
          e.setOrigin(20, 20);
          e.addAction(Actions.sequence(Actions.rotateBy(180, 10), Actions.moveBy(100, 100)));
          final int n = i + 1;
          e.setShootPattern(
              new ShootPattern(10, 3 - j * 0.3f, 30, e, b, 0.4f) {
                @Override
                public void shoot() {
                  Bullet toShoot;
                  float deltaDeg = 360f / n;
                  float startDeg = parent.getRotation() + 90;
                  for (int k = 0; k < n; ++k) {
                    float deg = startDeg + k * deltaDeg;
                    toShoot = getBullet();
                    toShoot.setPosition(parent.getCheckX(), parent.getCheckY());
                    toShoot.setOrigin(toShoot.getWidth() / 2f, toShoot.getHeight() / 2f);
                    toShoot.setRotation(deg - 90);
                    toShoot.addAction(
                        Actions.repeat(
                            RepeatAction.FOREVER,
                            Actions.moveBy(
                                speed * MathUtils.cosDeg(deg), speed * MathUtils.sinDeg(deg))));
                    world.addEnemyBullet(toShoot);
                  }
                }
              });
          world.addEnemy(e);
        }
      }
    }
  }
コード例 #4
0
  private void rebuildStage() {
    buttonPause = new JellyButton(Assets.instance.gameElements.pause);
    buttonPause.setMyScaleSize(1.3f, 1.3f);
    buttonPause.setPosition(8, Const.GAME_HEIGHT - buttonPause.getHeight() - 8);
    buttonPause.addTouchListener(
        new RunnableAction() {
          public void run() {
            pauseUi.showWindow(true);
          }
        },
        null);

    buttonReplay = new JellyButton(Assets.instance.gameElements.replay);
    buttonReplay.setMyScaleSize(1.3f, 1.3f);
    buttonReplay.setPosition(8, Const.GAME_HEIGHT - 2 * buttonReplay.getHeight() - 15);
    buttonReplay.addTouchListener(
        new RunnableAction() {
          public void run() {
            winnerUi.showWindow(true);
            winnerUi.setTime(110);
          }
        },
        null);

    Label.LabelStyle labelStyle = new Label.LabelStyle(Assets.instance.fonts.freezers, Color.WHITE);
    gameTime = new Label("0:00", labelStyle);
    gameTime.setAlignment(Align.left);
    gameTime.setPosition(Const.GAME_WIDTH - 135, Const.GAME_HEIGHT - 60);
    gameTime.setWrap(true);
    gameTime.setWidth(350f);

    star = new Image(Assets.instance.gameElements.star);
    star.setScale(0.3f);
    star.setOrigin(star.getWidth() / 2, star.getHeight() / 2);
    star.addAction(Actions.alpha(0f));
    star1 = new Image(Assets.instance.gameElements.star);
    star1.setScale(0.3f);
    star1.setPosition(Const.GAME_WIDTH - 60, Const.GAME_HEIGHT - 92);
    star2 = new Image(Assets.instance.gameElements.star);
    star2.setScale(0.3f);
    star2.setPosition(star1.getX() - 40, Const.GAME_HEIGHT - 92);
    star3 = new Image(Assets.instance.gameElements.star);
    star3.setScale(0.3f);
    star3.setPosition(star2.getX() - 40, Const.GAME_HEIGHT - 92);

    Label.LabelStyle labelStyle2 =
        new Label.LabelStyle(Assets.instance.fonts.freezers, Color.WHITE);
    freezes = new Label("0", labelStyle2);
    freezes.setText(String.valueOf(LevelData.freezers));
    freezes.setAlignment(Align.right);
    freezes.setPosition(Const.GAME_WIDTH - 200, Const.GAME_HEIGHT - 170);
    freezes.setWrap(true);
    freezes.setWidth(100f);

    freezeFon = new Image(Assets.instance.gameElements.freezeBuyFon);
    freezeFon.setPosition(
        Const.GAME_WIDTH - 158, Const.GAME_HEIGHT - buttonReplay.getHeight() - 107);
    freezeFon.setScale(0.6f);

    buttonBuyFreeze = new JellyButton(Assets.instance.gameElements.freezeBuy);
    buttonBuyFreeze.setMyScaleSize(1.6f, 1.6f);
    buttonBuyFreeze.setPosition(
        Const.GAME_WIDTH - buttonBuyFreeze.getWidth() - 15,
        Const.GAME_HEIGHT - buttonReplay.getHeight() - 100);
    buttonBuyFreeze.addTouchListener(
        new RunnableAction() {
          public void run() {
            marketUi.showWindow(true);
          }
        },
        null);

    imgFreeze = new Image(Assets.instance.gameElements.freeze);
    imgFreeze.setOrigin(imgFreeze.getWidth() / 2, imgFreeze.getHeight() / 2);
    imgFreeze.setScale(0.7f);
    imgFreeze.setPosition(freezeFon.getX() - 17, freezeFon.getY() - 25);
    imgFreeze.addAction(Actions.alpha(0f));

    if (addHelp) {
      float delay = 5f;
      if (GamePreferences.instance.isSensorXYZ) {
        delay = 4f;
        helpNavigate = new Image(Assets.instance.menuElements.navigate_tel);
        helpNavigate.setOrigin(helpNavigate.getWidth() / 2, helpNavigate.getHeight() / 2);
        helpNavigate.setScale(0.7f);
        helpNavigate.setPosition(
            Const.GAME_WIDTH - helpNavigate.getWidth() - 25, Const.GAME_HEIGHT - 500);
        helpNavigate.addAction(
            sequence(
                Actions.alpha(0f),
                Actions.delay(2f),
                new RunnableAction() {
                  public void run() {
                    gameState = GameState.PAUSE;
                  }
                },
                Actions.alpha(1f, 0.5f),
                Actions.rotateBy(15f, 0.4f, Interpolation.fade),
                Actions.rotateBy(-30f, 0.8f, Interpolation.fade),
                Actions.rotateBy(25f, 0.7f, Interpolation.fade),
                Actions.alpha(0f, 0.4f)));
      } else {
        helpNavigate = new Image(Assets.instance.menuElements.navigate_finger);
        helpNavigate.setOrigin(helpNavigate.getWidth() / 2, helpNavigate.getHeight() / 2);
        helpNavigate.setScale(0.7f);
        helpNavigate.setPosition(
            Const.GAME_WIDTH - helpNavigate.getWidth() - 25, Const.GAME_HEIGHT - 500);
        helpNavigate.addAction(
            sequence(
                Actions.alpha(0f),
                Actions.delay(2f),
                new RunnableAction() {
                  public void run() {
                    gameState = GameState.PAUSE;
                  }
                },
                Actions.alpha(1f, 0.5f),
                Actions.moveBy(-150f, 0, 0.7f, Interpolation.fade),
                Actions.moveBy(80f, 0, 0.7f, Interpolation.fade),
                Actions.moveBy(0, 150f, 0.7f, Interpolation.fade),
                Actions.moveBy(0, -200f, 0.7f, Interpolation.linear),
                Actions.alpha(0f, 0.4f)));
      }
      helpFreeze = new Image(Assets.instance.menuElements.navigate_finger);
      helpFreeze.setOrigin(helpFreeze.getWidth() / 2, helpFreeze.getHeight() / 2);
      helpFreeze.setScale(-0.7f, 0.7f);
      helpFreeze.setPosition(helpFreeze.getWidth() + 35, Const.GAME_HEIGHT - 500);
      helpFreeze.addAction(
          sequence(
              Actions.alpha(0f),
              Actions.delay(delay),
              Actions.alpha(1f, 0.5f),
              Actions.moveBy(
                  LevelData.posX - helpFreeze.getX() + 20,
                  LevelData.posY - helpFreeze.getY() - helpFreeze.getHeight() - 28,
                  0.7f,
                  Interpolation.fade),
              new RunnableAction() {
                public void run() {
                  setAnimation(animFreezeOn);
                }
              },
              Actions.alpha(0f, 0.2f)));
    }

    if (addHelp) {
      stage.addActor(helpNavigate);
      stage.addActor(helpFreeze);
    }
    stage.addActor(buttonPause);
    stage.addActor(buttonReplay);
    stage.addActor(gameTime);
    stage.addActor(freezeFon);
    stage.addActor(freezes);
    stage.addActor(buttonBuyFreeze);
    stage.addActor(star1);
    stage.addActor(star2);
    stage.addActor(star3);
    stage.addActor(star);
    stage.addActor(imgFreeze);
    stage.addActor(levelBuilder);
    stage.addActor(winnerUi);
    stage.addActor(marketUi);
    stage.addActor(pauseUi);
  }
コード例 #5
0
ファイル: GameScreen.java プロジェクト: falvarez/rectball
  @Override
  public void onSelectionSucceeded(final List<BallActor> selection) {
    // Extract the data from the selection.
    List<Ball> balls = new ArrayList<>();
    for (BallActor selectedBall : selection) balls.add(selectedBall.getBall());
    final Bounds bounds = Bounds.fromBallList(balls);

    // Change the colors of the selected region.
    board.addAction(
        Actions.sequence(
            board.hideRegion(bounds),
            Actions.run(
                new Runnable() {
                  @Override
                  public void run() {
                    for (BallActor selectedBall : selection) {
                      selectedBall.setColor(Color.WHITE);
                    }
                    generate(bounds);
                    // Reset the cheat
                    game.getState().setCheatSeen(false);
                    game.getState().setWiggledBounds(null);
                  }
                })));

    // Give some score to the user.
    ScoreCalculator calculator = new ScoreCalculator(game.getState().getBoard(), bounds);
    int givenScore = calculator.calculate();
    game.getState().addScore(givenScore);
    score.giveScore(givenScore);

    // Put information about this combination in the stats.
    int rows = bounds.maxY - bounds.minY + 1;
    int cols = bounds.maxX - bounds.minX + 1;
    String size = Math.max(rows, cols) + "x" + Math.min(rows, cols);
    game.statistics.getSizesData().incrementValue(size);

    BallColor color = board.getBall(bounds.minX, bounds.minY).getBall().getColor();
    game.statistics.getColorData().incrementValue(color.toString().toLowerCase());
    game.statistics.getTotalData().incrementValue("balls", rows * cols);
    game.statistics.getTotalData().incrementValue("combinations");

    // Now, display the score to the user. If the combination is a
    // PERFECT combination, just display PERFECT.
    int boardSize = game.getState().getBoard().getSize() - 1;
    if (bounds.equals(new Bounds(0, 0, boardSize, boardSize))) {
      // Give score
      Label label = new Label("PERFECT", game.getSkin(), "monospace");
      label.setX((getStage().getViewport().getWorldWidth() - label.getWidth()) / 2);
      label.setY((getStage().getViewport().getWorldHeight() - label.getHeight()) / 2);
      label.setFontScale(3);
      label.setAlignment(Align.center);
      label.addAction(Actions.sequence(Actions.moveBy(0, 80, 0.5f), Actions.removeActor()));
      getStage().addActor(label);
      game.player.playSound(SoundCode.PERFECT);

      // Give time
      float givenTime = Constants.SECONDS - timer.getSeconds();
      timer.giveTime(givenTime, 4f);
    } else {
      // Was special?
      boolean special = givenScore != rows * cols;
      // Give score
      showPartialScore(givenScore, bounds, special);
      game.player.playSound(SoundCode.SUCCESS);

      // Give time
      float givenTime = 4f;
      timer.giveTime(givenTime, 0.25f);
    }
  }
コード例 #6
0
 public Allied enter() {
   clearActions();
   addAction(Actions.moveBy(0, posY + getHeight(), .8f));
   return this;
 }