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(); }
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); }
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; }