Beispiel #1
0
  @Override
  protected Label updateLabel(Player player, Type index, final String text) {
    super.updateLabel(player);
    final Map<Player, Table> labels = getLabelMap();
    final Label label = (Label) labels.get(player).getChildren().get(index.type);
    final EventListener first = label.getListeners().first();

    label.clearListeners();
    label.addListener(first);

    if (index == Type.PLAYER) label.addListener(getListener(player));

    final Runnable runnable =
        new Runnable() {
          @Override
          public void run() {
            label.setText(text);
          }
        };

    final SequenceAction sequence =
        Actions.sequence(
            Actions.fadeOut(getSpeed()), Actions.run(runnable), Actions.fadeIn(getSpeed()));
    label.addAction(sequence);

    return label;
  }
 public void showNotif(String text) {
   notifTxt.remove();
   notifTxt.setText(text);
   notifTxt.setPosition(512 - notifTxt.getWidth() / 2, 300 - notifTxt.getHeight() / 2);
   notifTxt.setAlignment(Align.center);
   GdxGame.ui_stage1.addActor(notifTxt);
   notifTxt.clearActions();
   notifTxt.addAction(sequence(alpha(1f), delay(1f), fadeOut(1f), removeActor()));
 }
Beispiel #3
0
  /**
   * 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();
                    }
                  }
                })));
  }
Beispiel #4
0
  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);
    }
  }
  public void setupGUI() {
    stage = new Stage();

    skin = new Skin(Gdx.files.internal("uiskin.json"));
    table = new Table(skin);
    // table.setBounds(0, 0, Gdx.graphics.getWidth(),
    // Gdx.graphics.getHeight());
    // table.setClip(true);

    Gdx.input.setInputProcessor(stage);

    // defaultStyle.over = skin.getDrawable("button.hover");

    TextButton fullScreenButton = new TextButton("Toglle Full Screen", skin, "default");
    fullScreenButton.addListener(
        new ClickListener() {
          @Override
          public void clicked(InputEvent event, float x, float y) {
            Config.fullscreen = !Config.fullscreen;
          }
        });

    // fullScreenButton.setFillParent(true);
    TextButton saveSettingsButton = new TextButton("Save settings", skin, "default");
    saveSettingsButton.addListener(
        new ClickListener() {
          @Override
          public void clicked(InputEvent event, float x, float y) {
            Config.reload();
            show();
          }
        });
    Container<TextButton> saveSettingContainer = new Container<TextButton>(saveSettingsButton);

    saveSettingContainer.padTop(Value.percentHeight(.6f, table));

    TextButton backButton = new TextButton("Go back", skin, "default");
    backButton.addListener(
        new ClickListener() {
          @Override
          public void clicked(InputEvent event, float x, float y) {
            Screens.setScreen(Screens.MAIN_MENU_SCREEN);
          }
        });

    VerticalGroup buttons1 = new VerticalGroup();
    buttons1.fill();
    buttons1.addActor(fullScreenButton);

    VerticalGroup buttons2 = new VerticalGroup();
    buttons2.fill();
    buttons2.addActor(saveSettingsButton);
    buttons2.addActor(backButton);

    // buttons.setPosition(Gdx.graphics.getWidth()/4,
    // Gdx.graphics.getHeight()/5);

    VerticalGroup resolution = new VerticalGroup();
    ButtonGroup<TextButton> buttonGroup = new ButtonGroup<>();
    buttonGroup.setMaxCheckCount(1);
    resolution.fill();

    transparentSkin = new Skin(new TextureAtlas("select.pack"));
    TextButtonStyle transparent = new TextButtonStyle();
    transparent.checked = transparentSkin.getDrawable("checked");
    transparent.up = transparentSkin.getDrawable("up");
    transparent.font = FontUtil.generateFont(Color.WHITE, 20);

    addResolutions(buttonGroup, transparent);

    for (TextButton b : buttonGroup.getButtons()) {
      resolution.addActor(b);
    }

    resolution.right();

    ScrollPane resolScroll = new ScrollPane(resolution);
    resolScroll.setHeight(700);

    Label fullScreenLabel = new Label("", skin);
    fullScreenLabel.addAction(
        Actions.forever(
            new Action() {
              @Override
              public boolean act(float delta) {
                if (Config.fullscreen) {
                  fullScreenLabel.setColor(Color.GREEN);
                  fullScreenLabel.setText("on");
                } else {
                  fullScreenLabel.setColor(Color.RED);
                  fullScreenLabel.setText("off");
                }
                return true;
              }
            }));

    table.setFillParent(true);
    Table left = new Table();
    left.add(buttons1).spaceBottom(Value.percentHeight(.6f, table));
    left.add(fullScreenLabel).top();
    left.row();
    // left.row();
    left.add(buttons2);
    // table.add(buttons1.left()).left();
    table.add(left).left().padLeft(Value.percentWidth(0.1f, table)).expandX();
    // table.add(fullScreenLabel).top().spaceRight(Value.percentWidth(.5f,
    // table));
    table.add(resolScroll).right().padRight(Value.percentWidth(0.1f, table));

    // table.row();
    // table.add(buttons2).bottom().left();
    // table.center();

    stage.addActor(table);

    if (Config.debug) table.setDebug(true);
  }
Beispiel #6
0
  @Override
  public void draw() {
    Gdx.gl.glClearColor(0, 0.2f, 1, 1);
    camera.position.interpolate(
        new Vector3(camera.position.x, camY, 0), 0.1f, Interpolation.pow2Out);
    camera.update();
    batch.setProjectionMatrix(camera.combined);

    if (!pause) world.step(1 / 60f, 8, 3);

    world.getBodies(bodies);
    batch.begin();
    for (i = 0; i < 5; i++) {
      if (backgrounds[i]
          .getBoundingRectangle()
          .overlaps(
              new Rectangle(
                  camera.position.x - camera.viewportWidth / 2,
                  camera.position.y - camera.viewportHeight / 2,
                  camera.viewportWidth,
                  camera.viewportHeight))) {
        backgrounds[i].draw(batch);
      }
    }
    traySprite.draw(batch);
    mpHandler.update(
        Gdx.graphics.getDeltaTime(), true, batch, tap, new Vector2(unprojected.x, unprojected.y));
    for (i = 0; i < bodies.size; i++) {
      scbd = bodies.get(i);
      if (scbd != tmpbd) {
        bodyY.add(scbd.getPosition().y);
      }
      if (scbd.getWorldCenter().y < -2
          || scbd.getWorldCenter().x < -1.3f
          || scbd.getWorldCenter().x > 6.5f) {
        mpHandler.removeFromBody(scbd);
        world.destroyBody(scbd);
        if (!gameOver) {
          if (score > MainClass.highScore) {
            newHighScoreSound.play(MainClass.sound);
          } else {
            gameOverSound.play(MainClass.sound);
          }
          gameOver = true;
          scoreLabel.addAction(new AlphaAction());
          muffinSource.remove();
          pauseButton.remove();
          gameOverDialog.show(this, score);
        }
      }
      if (scbd.getType() == BodyDef.BodyType.DynamicBody) {
        AdjustToBody(muffinSprite, muffinOrigin, scbd, 1.228f, 1);
        muffinSprite.draw(batch);
        if (scbd.isAwake()) {
          if (Math.abs(scbd.getLinearVelocity().len2()) > 10) {
            AdjustToBody(scaredmuffinface, muffinOrigin, scbd, 1.228f, 1);
            scaredmuffinface.draw(batch);
          } else {
            AdjustToBody(awakemuffinface, muffinOrigin, scbd, 1.228f, 1);
            awakemuffinface.draw(batch);
          }
        } else {
          AdjustToBody(normalmuffinface, muffinOrigin, scbd, 1.228f, 1);
          normalmuffinface.draw(batch);
        }
      }
    }
    batch.end();
    camY = 0;
    if (bodyY.size > 5) {
      bodyY.sort();
      for (i = bodyY.size - 3; i < bodyY.size; i++) {
        camY += bodyY.get(i);
      }
      camY /= 3;
      camY += 2;
    }
    if (camY < 4) camY = 4;
    if (drag) {
      tmpbd.setLinearVelocity(
          (unprojected.x - 0.5f - tmpbd.getPosition().x) * 20,
          (unprojected.y - 0.5f - tmpbd.getPosition().y) * 20);
    }
    super.draw();
    bodies.clear();
    bodyY.clear();
  }
Beispiel #7
0
  @Override
  public void start() {
    super.start();
    if (this.type == FinalStage.TYPE_GAME_OVER) {
      StageScreen.getInstance().getTracker().trackScreen("gameOverScreen");
    } else {
      StageScreen.getInstance().getTracker().trackScreen("gameWinScreen");
    }
    this.music = Manager.getInstance().get(musicFile, Music.class);
    this.music.setVolume(Settings.getInstance().getMusicVolume());
    this.music.play();

    TextureAtlas atlas = Manager.getInstance().get("img/menu.pack", TextureAtlas.class);
    LabelStyle headerStyle = new LabelStyle();
    headerStyle.font = Config.getInstance().headerFont;
    headerStyle.fontColor = Config.getInstance().textColor;

    String labelText = (type == FinalStage.TYPE_GAME_OVER) ? "game.over" : "game.win";
    Label text = new Label(Translator.getInstance().translate(labelText), headerStyle);
    text.setBounds(
        50, 150, Config.getInstance().gameWidth - 100, Config.getInstance().gameHeight - 150);
    text.setAlignment(Align.center);
    text.setWrap(true);
    text.getColor().a = 0;
    text.addAction(fadeIn(2f));
    this.addActor(text);

    AtlasRegion btnBg = atlas.findRegion("btn-bg");
    AtlasRegion btnBgTouched = atlas.findRegion("btn-bg-touched");
    Color btnColor = new Color(1, 1, 1, 1);
    Color btnColorTouched = new Color(0.5f, 0.5f, 0.5f, 1);

    TextButton newGame =
        new TextButton(
            btnBg,
            btnBgTouched,
            Translator.getInstance().translate("btn.new.game"),
            Config.getInstance().bigFont,
            btnColor,
            btnColorTouched);
    newGame.setHeight(btnHeight);
    newGame.setPosition(50, 50);
    newGame.addListener(
        new ClickListener() {
          @Override
          public void clicked(InputEvent event, float x, float y) {
            StageScreen.getInstance().setStage(new SlideStage(SlideStage.TYPE_INTRO));
          }
        });
    this.addActor(newGame);

    TextButton exit =
        new TextButton(
            btnBg,
            btnBgTouched,
            Translator.getInstance().translate("btn.exit"),
            Config.getInstance().bigFont,
            btnColor,
            btnColorTouched);
    exit.setHeight(btnHeight);
    exit.setPosition(Config.getInstance().gameWidth - exit.getWidth() - 50, 50);
    exit.addListener(
        new ClickListener() {
          @Override
          public void clicked(InputEvent event, float x, float y) {
            StageScreen.getInstance().setStage(new MenuStage());
          }
        });
    this.addActor(exit);
  }
Beispiel #8
0
  @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);
    }
  }