diff --git a/core/src/de/samdev/colorrunner/CRGame.java b/core/src/de/samdev/colorrunner/CRGame.java index 04b8c75..310091c 100644 --- a/core/src/de/samdev/colorrunner/CRGame.java +++ b/core/src/de/samdev/colorrunner/CRGame.java @@ -2,6 +2,7 @@ package de.samdev.colorrunner; import com.badlogic.gdx.Game; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Preferences; import com.badlogic.gdx.assets.AssetManager; import com.badlogic.gdx.audio.Music; @@ -10,6 +11,7 @@ import de.samdev.colorrunner.screens.menu.SplashScreen; public class CRGame extends Game { public final static boolean DEBUG = false; public static AssetManager manager; + @Override public void create() { @@ -22,6 +24,10 @@ public class CRGame extends Game { manager.load("sound/menusound.mp3", Music.class); manager.finishLoading(); + Preferences endlessGameInfos = Gdx.app.getPreferences("endlessGameInfos"); + endlessGameInfos.putInteger("lastBest", 0); + endlessGameInfos.flush(); + setScreen(new SplashScreen()); } diff --git a/core/src/de/samdev/colorrunner/game/world/CRGameWorld.java b/core/src/de/samdev/colorrunner/game/world/CRGameWorld.java index 0ff9621..5d616b7 100644 --- a/core/src/de/samdev/colorrunner/game/world/CRGameWorld.java +++ b/core/src/de/samdev/colorrunner/game/world/CRGameWorld.java @@ -12,13 +12,16 @@ import java.util.List; import de.samdev.colorrunner.CRGame; import de.samdev.colorrunner.game.world.entities.CRGameEntity; import de.samdev.colorrunner.game.world.entities.gameentities.PlayerEntity; +import de.samdev.colorrunner.game.world.map.provider.EndlessMapProvider; import de.samdev.colorrunner.game.world.map.provider.MapProvider; import de.samdev.colorrunner.input.GameInputListener; import de.samdev.colorrunner.screens.gameScreen.GameScreen; +import de.samdev.colorrunner.screens.menu.EndlessGameMenu; import de.samdev.colorrunner.screens.menu.MainMenu; public class CRGameWorld implements GameInputListener { private Preferences prefs = Gdx.app.getPreferences("settings"); + private Preferences endlessGameInfos = Gdx.app.getPreferences("endlessGameInfos"); public PlayerEntity player; public List entities; @@ -70,7 +73,10 @@ public class CRGameWorld implements GameInputListener { } if(player.getPosition().y < - 10) { - ((Game) Gdx.app.getApplicationListener()).setScreen(new MainMenu()); + checkHighscore(); + setTries(); + setLastBest(); + CRGame.Inst().setScreen(new GameScreen(new EndlessMapProvider(System.currentTimeMillis()))); music.stop(); } @@ -102,4 +108,27 @@ public class CRGameWorld implements GameInputListener { public void reset() { reinitialize(); } + + private void checkHighscore(){ + int highscore = endlessGameInfos.getInteger("Highscore", 0); + if(highscore < scoreMeter){ + endlessGameInfos.putInteger("Highscore", scoreMeter); + } + endlessGameInfos.flush(); + } + private void setTries(){ + int tries = endlessGameInfos.getInteger("Tries", 0); + tries++; + endlessGameInfos.putInteger("Tries", tries); + endlessGameInfos.flush(); + } + private void setLastBest(){ + int lastBest = endlessGameInfos.getInteger("lastBest", 0); + if(lastBest < scoreMeter){ + endlessGameInfos.putInteger("lastBest", scoreMeter); + } + endlessGameInfos.flush(); + } + + } diff --git a/core/src/de/samdev/colorrunner/screens/menu/EndlessGameMenu.java b/core/src/de/samdev/colorrunner/screens/menu/EndlessGameMenu.java new file mode 100644 index 0000000..9e8c48a --- /dev/null +++ b/core/src/de/samdev/colorrunner/screens/menu/EndlessGameMenu.java @@ -0,0 +1,132 @@ +package de.samdev.colorrunner.screens.menu; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Preferences; +import com.badlogic.gdx.Screen; +import com.badlogic.gdx.audio.Music; +import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.OrthographicCamera; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.graphics.g2d.TextureAtlas; +import com.badlogic.gdx.scenes.scene2d.InputEvent; +import com.badlogic.gdx.scenes.scene2d.Stage; +import com.badlogic.gdx.scenes.scene2d.ui.Label; +import com.badlogic.gdx.scenes.scene2d.ui.Skin; +import com.badlogic.gdx.scenes.scene2d.ui.Table; +import com.badlogic.gdx.scenes.scene2d.ui.TextButton; +import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; + + +import de.samdev.colorrunner.CRGame; +import de.samdev.colorrunner.game.world.map.provider.EndlessMapProvider; +import de.samdev.colorrunner.screens.gameScreen.GameScreen; + +/** + * Created by benza on 16.04.2017. + */ + +public class EndlessGameMenu implements Screen { + + private OrthographicCamera cam = new OrthographicCamera(); + private Texture background = new Texture("images/background2.jpg"); + private Music music; + private Preferences endlessGameInfos = Gdx.app.getPreferences("endlessGameInfos"); + + private Stage stage = new Stage(); + private Table table = new Table(); + + private Skin skin = new Skin(Gdx.files.internal("skins/menuSkin.json"), + new TextureAtlas(Gdx.files.internal("skins/menuSkin.pack"))); + + private int highScore = endlessGameInfos.getInteger("Highscore", 0); + private int lastBest = endlessGameInfos.getInteger("lastBest", 0); + private int tries = endlessGameInfos.getInteger("Tries", 0); + + private TextButton buttonPlay = new TextButton("Play", skin); + private TextButton buttonBack = new TextButton("Back", skin); + private Label labelTitle = new Label("Endless Game", skin); + private Label labelHighscore = new Label("Highscore: " + highScore, skin); + private Label labelLastBest = new Label("LastRounds: " + lastBest, skin); + private Label labelTries = new Label("Tries: " + tries, skin); + + + + public EndlessGameMenu(Music music) { + this.music = music; + } + + @Override + public void show() { + buttonPlay.addListener(new ClickListener(){ + @Override + public void clicked(InputEvent event, float x, float y){ + CRGame.Inst().setScreen(new GameScreen(new EndlessMapProvider(System.currentTimeMillis()))); + music.stop(); + } + }); + + buttonBack.addListener(new ClickListener(){ + @Override + public void clicked(InputEvent event, float x, float y){ + CRGame.Inst().setScreen(new MainMenu()); + } + }); + + table.add(labelTitle).padBottom(40).row(); + table.add(labelHighscore).padBottom(20).row(); + table.add(labelLastBest).padBottom(20).row(); + table.add(labelTries).padBottom(20).row(); + table.add(buttonPlay).size((int)((double)Gdx.graphics.getWidth() / 2.0D),80).padBottom(20).row(); + table.add(buttonBack).size((int)((double)Gdx.graphics.getWidth() / 2.0D),80).padBottom(20).row(); + + table.setFillParent(true); + stage.addActor(table); + + Gdx.input.setInputProcessor(stage); + } + + @Override + public void render(float delta) { + Gdx.gl.glClearColor(0, 0, 0, 1); + Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + + cam.setToOrtho(false, (float)Gdx.graphics.getWidth() / 2.0F, (float)Gdx.graphics.getHeight() / 2.0F); + + SpriteBatch sb = new SpriteBatch(); + sb.setProjectionMatrix(cam.combined); + sb.begin(); + sb.draw(background, 0, 0); + sb.end(); + + stage.act(); + + stage.draw(); + } + + @Override + public void resize(int width, int height) { + + } + + @Override + public void pause() { + + } + + @Override + public void resume() { + + } + + @Override + public void hide() { + + } + + @Override + public void dispose() { + stage.dispose(); + skin.dispose(); + } +} diff --git a/core/src/de/samdev/colorrunner/screens/menu/MainMenu.java b/core/src/de/samdev/colorrunner/screens/menu/MainMenu.java index efb8f2d..8631c76 100644 --- a/core/src/de/samdev/colorrunner/screens/menu/MainMenu.java +++ b/core/src/de/samdev/colorrunner/screens/menu/MainMenu.java @@ -103,8 +103,6 @@ button3.addListener(new InputListener(){ stage.act(); stage.draw(); - - } @Override @@ -125,8 +123,8 @@ button3.addListener(new InputListener(){ buttonPlay2.addListener(new ClickListener(){ @Override public void clicked(InputEvent event, float x, float y){ - CRGame.Inst().setScreen(new GameScreen(new EndlessMapProvider(System.currentTimeMillis()))); - music.stop(); + //CRGame.Inst().setScreen(new GameScreen(new EndlessMapProvider(System.currentTimeMillis()))); + CRGame.Inst().setScreen(new EndlessGameMenu(music)); } }); @@ -145,10 +143,10 @@ button3.addListener(new InputListener(){ }); table.add(title).padBottom(40).row(); - table.add(buttonPlay1).size((int)((double)Gdx.graphics.getWidth() / 2.0D),60).padBottom(20).row(); - table.add(buttonPlay2).size((int)((double)Gdx.graphics.getWidth() / 2.0D),60).padBottom(20).row(); - table.add(buttonOption).size((int)((double)Gdx.graphics.getWidth() / 2.0D),60).padBottom(20).row(); - table.add(buttonExit).size((int)((double)Gdx.graphics.getWidth() / 2.0D),60).padBottom(20).row(); + table.add(buttonPlay1).size((int)((double)Gdx.graphics.getWidth() / 2.0D),80).padBottom(20).row(); + table.add(buttonPlay2).size((int)((double)Gdx.graphics.getWidth() / 2.0D),80).padBottom(20).row(); + table.add(buttonOption).size((int)((double)Gdx.graphics.getWidth() / 2.0D),80).padBottom(20).row(); + table.add(buttonExit).size((int)((double)Gdx.graphics.getWidth() / 2.0D),80).padBottom(20).row(); table.setFillParent(true); stage.addActor(table);