Пример #1
0
 public void handleAds() {
   if (grid.isPaused() && !showingAd) {
     if (adsController.isWifiConnected()) adsController.showBannerAd();
     showingAd = true;
   } else if (grid.isGameOver() && !showingAd) {
     if (adsController.isWifiConnected()) adsController.showBannerAd();
     showingAd = true;
   } else if (!grid.isPaused() && !grid.isGameOver() && showingAd) {
     adsController.hideBannerAd();
     showingAd = false;
   }
 }
Пример #2
0
  public void render(SpriteBatch sb) {
    grid.render(sb);
    redCounter.draw(sb);
    blueCounter.draw(sb);
    scoreCounter(sb);
    highScoreCounter(sb);
    if (grid.isGameOver()) {
      backGroundFade.draw(sb);
      gameOverOverlay.draw(sb);
      restartButton.render(sb);
    }

    if (grid.isPaused()) {
      backGroundFade.draw(sb);
      menuButton.render(sb);
      restartButton.render(sb);
      unpauseButton.render(sb);
    }
  }
Пример #3
0
  public GameState(TitleState title) {
    this.title = title;
    this.title.reset();
    prefs = Gdx.app.getPreferences("highscore");
    adsController = MainGame.adsController;
    restartButton = new RestartButton(MainGame.WIDTH / 2 - 78, MainGame.HEIGHT / 2 - 100);
    menuButton = new MenuButton(MainGame.WIDTH / 2 - 125, MainGame.HEIGHT / 2);
    unpauseButton = new UnpauseButton(MainGame.WIDTH / 2 - 78, MainGame.HEIGHT / 2 + 100);
    highScore = prefs.getInteger("highscore", 0);

    gameOverOverlay = new Sprite(new Texture(Gdx.files.internal("gui/gameoverlay.png")));
    gameOverOverlay.setPosition(0, MainGame.HEIGHT / 2 - (gameOverOverlay.getHeight() / 2));

    backGroundFade = new Sprite(new Texture(Gdx.files.internal("gui/bgfade.png")));
    backGroundFade.setPosition(0, 0);
    backGroundFade.setSize(MainGame.WIDTH, MainGame.HEIGHT);
    backGroundFade.setAlpha(0.6f);

    grid = new Grid(15, 15, 390, 390, prefs);

    parameter.size = 20;
    parameter.shadowColor = new Color(0, 0, 0, 1f);
    parameter.shadowOffsetX = 1;
    parameter.shadowOffsetY = 1;
    score = grid.getScore();
    scoreFont = generator.generateFont(parameter);
    highscoreFont = generator.generateFont(parameter);
    redCounter = new Sprite(new Texture(Gdx.files.internal("gui/score/scorecounter.png")));
    redCounter.setSize(144, 26.4f);
    redCounter.setPosition(18, MainGame.HEIGHT - redCounter.getHeight() - 260);

    blueCounter = new Sprite(new Texture(Gdx.files.internal("gui/score/highscorecounter.png")));
    blueCounter.setSize(144, 26.4f);
    blueCounter.setPosition(
        MainGame.WIDTH - blueCounter.getWidth() - 18,
        MainGame.HEIGHT - blueCounter.getHeight() - 260);

    scoreFont.setColor(Color.WHITE);
    scoreFont.setFixedWidthGlyphs("0123456789");
    highscoreFont.setFixedWidthGlyphs("0123456789");
    grid.setPaused(false);
  }
Пример #4
0
  public void saveState() {
    System.out.println("SAVE");
    hasFlushed = false;
    int currentHighScore = prefs.getInteger("highscore");
    prefs.clear();
    for (int i = 0; i < grid.getBlocks().size; i++) {
      prefs.putFloat("x" + i, grid.getBlocks().get(i).getX());
      prefs.putFloat("y" + i, grid.getBlocks().get(i).getY());
      prefs.putFloat("val" + i, grid.getBlocks().get(i).getValue());
    }

    prefs.putInteger("score", grid.getScore());

    if (highScore >= currentHighScore) {
      prefs.putInteger("highscore", highScore);
    } else {
      prefs.putInteger("highscore", currentHighScore);
    }
    prefs.flush();
    hasFlushed = true;
  }
Пример #5
0
  public void update() {
    if (!grid.isPaused()) {
      grid.update();
    }

    score = grid.getScore();
    if (score >= highScore) {
      highScore = score;
    }

    if (grid.isGameOver()) {
      hasFlushed = true;
    } else if (!grid.isGameOver() && hasFlushed) {
      hasFlushed = false;
    }

    if (Gdx.input.justTouched()
        && ScreenManager.getCurrentScreen()
            .inputManager
            .getIntersecting(restartButton.getHitbox())) {
      if (grid.isGameOver()) {
        grid.restart();
        saveState();
      }
    }

    if (Gdx.input.justTouched() && grid.isPaused()) {
      if (ScreenManager.getCurrentScreen().inputManager.getIntersecting(menuButton.getHitbox())) {
        grid.newRound();
        grid.endRound();
        grid.setPaused(false);
        saveState();
        ScreenManager.setScreen(new TitleScreen(title));

      } else if (ScreenManager.getCurrentScreen()
          .inputManager
          .getIntersecting(unpauseButton.getHitbox())) {
        grid.setPaused(false);
      } else if (ScreenManager.getCurrentScreen()
          .inputManager
          .getIntersecting(restartButton.getHitbox())) {
        grid.restart();
        grid.setPaused(false);
        saveState();
      }
    }
    handleAds();
  }