diff --git a/core/src/de/samdev/colorrunner/game/world/CRGameWorld.java b/core/src/de/samdev/colorrunner/game/world/CRGameWorld.java index 5d6edc3..811fdf2 100644 --- a/core/src/de/samdev/colorrunner/game/world/CRGameWorld.java +++ b/core/src/de/samdev/colorrunner/game/world/CRGameWorld.java @@ -2,6 +2,7 @@ package de.samdev.colorrunner.game.world; import com.badlogic.gdx.Game; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Preferences; import com.badlogic.gdx.audio.Music; import com.badlogic.gdx.math.Rectangle; @@ -17,6 +18,7 @@ import de.samdev.colorrunner.screens.gameScreen.GameScreen; import de.samdev.colorrunner.screens.menu.MainMenu; public class CRGameWorld implements GameInputListener { + private Preferences prefs = Gdx.app.getPreferences("settings"); public PlayerEntity player; public List entities; @@ -26,15 +28,17 @@ public class CRGameWorld implements GameInputListener { public MapProvider mapprovider; private Music music; public int scoreMeter = 0; - - + public CRGameWorld(MapProvider prov) { mapprovider = prov; - music = CRGame.manager.get("sound/mainsound.mp3", Music.class); music.setLooping(true); - music.play(); + + if(prefs.getBoolean("sound", true)) + music.play(); + else + music.stop(); reinitialize(); } diff --git a/core/src/de/samdev/colorrunner/screens/gameScreen/GameScreen.java b/core/src/de/samdev/colorrunner/screens/gameScreen/GameScreen.java index 254a5cf..630ce17 100644 --- a/core/src/de/samdev/colorrunner/screens/gameScreen/GameScreen.java +++ b/core/src/de/samdev/colorrunner/screens/gameScreen/GameScreen.java @@ -30,10 +30,6 @@ public class GameScreen implements Screen { renderer = new CRGameRenderer(world, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); // initialize renderer - - - - input = new CRGameInputProcessor(world); } diff --git a/core/src/de/samdev/colorrunner/screens/menu/MainMenu.java b/core/src/de/samdev/colorrunner/screens/menu/MainMenu.java index dc26e32..efb8f2d 100644 --- a/core/src/de/samdev/colorrunner/screens/menu/MainMenu.java +++ b/core/src/de/samdev/colorrunner/screens/menu/MainMenu.java @@ -1,6 +1,7 @@ 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; @@ -28,6 +29,7 @@ import de.samdev.colorrunner.screens.gameScreen.GameScreen; public class MainMenu implements Screen { + private Preferences prefs = Gdx.app.getPreferences("settings"); private Stage stage = new Stage(); private Table table = new Table(); @@ -72,14 +74,16 @@ button3.addListener(new InputListener(){ private Label title = new Label("Color Runner", skin); - private Music music; + public Music music; public MainMenu() { - music = CRGame.manager.get("sound/menusound.mp3", Music.class); - music.setLooping(true); - music.play(); - + music = CRGame.manager.get("sound/menusound.mp3", Music.class); + music.setLooping(true); + if(prefs.getBoolean("sound", true)) + music.play(); + else + music.stop(); } @Override @@ -129,7 +133,7 @@ button3.addListener(new InputListener(){ buttonOption.addListener(new ClickListener(){ @Override public void clicked(InputEvent event, float x, float y) { - CRGame.Inst().setScreen(new OptionMenuScreen()); + CRGame.Inst().setScreen(new OptionMenuScreen(music)); } }); diff --git a/core/src/de/samdev/colorrunner/screens/menu/OptionMenuScreen.java b/core/src/de/samdev/colorrunner/screens/menu/OptionMenuScreen.java index d6af193..b24b80d 100644 --- a/core/src/de/samdev/colorrunner/screens/menu/OptionMenuScreen.java +++ b/core/src/de/samdev/colorrunner/screens/menu/OptionMenuScreen.java @@ -2,7 +2,9 @@ package de.samdev.colorrunner.screens.menu; import com.badlogic.gdx.Game; 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; @@ -20,6 +22,7 @@ import de.samdev.colorrunner.screens.gameScreen.GameScreen; public class OptionMenuScreen implements Screen{ + private Preferences prefs = Gdx.app.getPreferences("settings"); private Stage stage = new Stage(); private Table table = new Table(); private Texture background = new Texture("images/background2.jpg"); @@ -27,9 +30,10 @@ public class OptionMenuScreen implements Screen{ private Skin skin = new Skin(Gdx.files.internal("skins/menuSkin.json"), new TextureAtlas(Gdx.files.internal("skins/menuSkin.pack"))); + private Music music; - public OptionMenuScreen() { - //cam.setToOrtho(false, (float)Gdx.graphics.getWidth() / 2, (float)Gdx.graphics.getHeight() / 2); + public OptionMenuScreen(Music music) { + this.music = music; } private Label title = new Label("Option", skin); @@ -60,14 +64,27 @@ public class OptionMenuScreen implements Screen{ @Override public void show() { - - TextButton buttonSound = new TextButton("Sound On/Off", skin); + TextButton buttonSound; + if(prefs.getBoolean("sound", true)) + buttonSound = new TextButton("Sound On", skin); + else + buttonSound = new TextButton("Sound Off", skin); + TextButton buttonBack = new TextButton("Back", skin); buttonSound.addListener(new ClickListener(){ @Override public void clicked(InputEvent event, float x, float y){ - + if(prefs.getBoolean("sound", true)) { + prefs.putBoolean("sound", false); + music.stop(); + } + else { + prefs.putBoolean("sound", true); + music.play(); + + } + ((Game)Gdx.app.getApplicationListener()).setScreen(new OptionMenuScreen(music)); } });