diff --git a/core/src/com/mygdx/game/sprites/CircleButton.java b/core/src/com/mygdx/game/ds/buttons/CircleButton.java similarity index 96% rename from core/src/com/mygdx/game/sprites/CircleButton.java rename to core/src/com/mygdx/game/ds/buttons/CircleButton.java index 4ea6a4421bd0fee82ccb41c84de962836ea9e598..edb8196b8cf395c26f256c395cf4b3b690894a51 100644 --- a/core/src/com/mygdx/game/sprites/CircleButton.java +++ b/core/src/com/mygdx/game/ds/buttons/CircleButton.java @@ -1,4 +1,4 @@ -package com.mygdx.game.sprites; +package com.mygdx.game.ds.buttons; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; @@ -13,7 +13,6 @@ public class CircleButton { private int radius; private Texture img; - public CircleButton(int radius, int xStart, int yStart, String internalPath) { this.radius = radius; this.position = new Vector2(xStart, yStart); diff --git a/core/src/com/mygdx/game/ds/buttons/RectangleButton.java b/core/src/com/mygdx/game/ds/buttons/RectangleButton.java new file mode 100644 index 0000000000000000000000000000000000000000..7e692d7858e9213a2895454d94ecd769a29f020f --- /dev/null +++ b/core/src/com/mygdx/game/ds/buttons/RectangleButton.java @@ -0,0 +1,51 @@ +package com.mygdx.game.ds.buttons; + +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; +import com.badlogic.gdx.math.Rectangle; +import com.badlogic.gdx.math.Vector2; + +public class RectangleButton { + + private final Vector2 position; + private final Rectangle bounds; + private final ShapeRenderer shape; + private final Texture img; + private final int width; + private final int height; + private final float scale; + + public RectangleButton(float scale, int xStart, int yStart, String internalPath) { + this.scale = scale; + this.img = new Texture(internalPath); + this.width = (int) (img.getWidth() * scale); + this.height = (int ) (img.getHeight() * scale); + this.position = new Vector2(xStart, yStart); + this.bounds = new Rectangle(xStart, yStart, width, height); + this.shape = new ShapeRenderer(); + } + + public Vector2 getPosition() { + return position; + } + + public Rectangle getBounds() { + return bounds; + } + + public ShapeRenderer getShape() { + return shape; + } + + public int getWidth() {return this.width;} + + public int getHeight() {return this.height;} + + public Texture getImg() { + return img; + } + + public float getScale() { + return scale; + } +} diff --git a/core/src/com/mygdx/game/states/DummyState.java b/core/src/com/mygdx/game/states/DummyState.java index 5f861d23ef5b1573d3f5d8b93234addfe6342507..323f8b015674587d699012aea43252ef1661a251 100644 --- a/core/src/com/mygdx/game/states/DummyState.java +++ b/core/src/com/mygdx/game/states/DummyState.java @@ -5,6 +5,7 @@ import com.badlogic.gdx.Input; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.utils.ScreenUtils; +import com.mygdx.game.utils.Enums; import java.util.ArrayList; import java.util.Arrays; @@ -34,7 +35,7 @@ public class DummyState extends State { if (Gdx.input.isKeyPressed(Input.Keys.ENTER)) { bg.set(2, 0f); bg.set(1, 1f); - gsm.push(new SettingsState(SettingsState.SettingsBackground.CITY)); + gsm.push(new SettingsState(Enums.SettingsBackground.CITY, Enums.GameType.MENU)); } } diff --git a/core/src/com/mygdx/game/states/GameMenuState.java b/core/src/com/mygdx/game/states/GameMenuState.java index db97537a908a0a48642cb572a4991b805b586fb3..c40bc54800c8f8dda9d8f087a04fe67273cffc7e 100644 --- a/core/src/com/mygdx/game/states/GameMenuState.java +++ b/core/src/com/mygdx/game/states/GameMenuState.java @@ -8,6 +8,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.utils.ScreenUtils; import com.mygdx.game.FireBaseInterface; import com.mygdx.game.SoundManager; +import com.mygdx.game.utils.Enums; public class GameMenuState extends State { private GameStateManager gsm; @@ -137,7 +138,7 @@ public class GameMenuState extends State { gsm.push(new IntroCutsceneState()); } if (isLobbyButtonClicked(x, y)) { - gsm.push(new SettingsState(SettingsState.SettingsBackground.CITY)); + gsm.push(new SettingsState(Enums.SettingsBackground.CITY, Enums.GameType.MENU)); } if (isMenuButtonClicked(x, y)) { gsm.push(new StartState()); diff --git a/core/src/com/mygdx/game/states/GameStateManager.java b/core/src/com/mygdx/game/states/GameStateManager.java index f72bcc62c0d3c51504883a3eddd4dfab196c669d..319c9e511c7ea22c54fc1117f2de9c99b2357496 100644 --- a/core/src/com/mygdx/game/states/GameStateManager.java +++ b/core/src/com/mygdx/game/states/GameStateManager.java @@ -19,6 +19,9 @@ public class GameStateManager { public void push(State state) { states.push(state); } + public Stack<State> getStates() { + return states; + } public void pop() { states.pop(); diff --git a/core/src/com/mygdx/game/states/PlayState.java b/core/src/com/mygdx/game/states/PlayState.java index beb617e19f29ce01f6caa1244418993c8a6b9139..453de02ba6233c4876aaae4b14cdc362da892106 100644 --- a/core/src/com/mygdx/game/states/PlayState.java +++ b/core/src/com/mygdx/game/states/PlayState.java @@ -24,9 +24,11 @@ import com.mygdx.game.MoneySystem; import com.mygdx.game.SoundManager; import com.mygdx.game.entities.DisplayHero; import com.mygdx.game.entities.HeroFactory; +import com.mygdx.game.ds.buttons.RectangleButton; import com.mygdx.game.systems.HeroSystem; import com.mygdx.game.systems.ProjectileMovementSystem; import com.mygdx.game.types.HeroType; +import com.mygdx.game.utils.Enums; import java.util.ArrayList; import java.util.List; @@ -36,16 +38,19 @@ public class PlayState extends State{ private BitmapFont font; private Stage stage; private ShapeRenderer shapeRenderer; - SoundManager soundManager = SoundManager.getInstance(); - + private SoundManager soundManager = SoundManager.getInstance(); private MoneySystem moneySystem; private boolean isPlacementAllowed = false; private static Engine engine; private Board board; private TextButton counterText1; + private final RectangleButton menuButton; + private final GameStateManager gsm; public PlayState() { //super(gsm); + menuButton = new RectangleButton(0.5f, Gdx.graphics.getWidth() - 137, Gdx.graphics.getHeight() - 100, "Lobby-button.png"); + gsm = GameStateManager.getGsm(); initialize(); } @@ -125,13 +130,13 @@ public class PlayState extends State{ @Override public void render(SpriteBatch batch) { - Gdx.gl.glClearColor(0.5f, 0.5f, 0.5f, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); //calculateMoney(); batch.begin(); board.render(batch); + batch.draw(menuButton.getImg(), menuButton.getPosition().x - menuButton.getWidth() / 2f, menuButton.getPosition().y, menuButton.getWidth(), menuButton.getHeight()); batch.end(); stage.act(Gdx.graphics.getDeltaTime()); @@ -139,7 +144,16 @@ public class PlayState extends State{ } @Override - public void handleInput() {} + public void handleInput() { + if (Gdx.input.isTouched()) { + float touchX = Gdx.input.getX(); + float touchY = Gdx.graphics.getHeight() - Gdx.input.getY(); + if (menuButton.getBounds().contains(touchX, touchY)) { + //Implement Game.pause(); + gsm.push(new SettingsState(Enums.SettingsBackground.CITY, Enums.GameType.SINGLEPLAYER)); + } + } + } public void dispose() { diff --git a/core/src/com/mygdx/game/states/SettingsState.java b/core/src/com/mygdx/game/states/SettingsState.java index 726f414bf9e28a68f059a584e58369f8af5ee54f..9f008f7360ec972739b3bae94bf50fe0767c6ec6 100644 --- a/core/src/com/mygdx/game/states/SettingsState.java +++ b/core/src/com/mygdx/game/states/SettingsState.java @@ -1,40 +1,37 @@ package com.mygdx.game.states; import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.GlyphLayout; import com.badlogic.gdx.graphics.g2d.SpriteBatch; -import com.badlogic.gdx.scenes.scene2d.ui.Skin; -import com.badlogic.gdx.utils.Json; import com.badlogic.gdx.utils.ScreenUtils; -import com.mygdx.game.sprites.CircleButton; +import com.mygdx.game.ds.buttons.CircleButton; +import com.mygdx.game.ds.buttons.RectangleButton; +import com.mygdx.game.utils.Enums; import com.mygdx.game.utils.SettingsData; import com.mygdx.game.utils.Slider; -import java.io.File; import java.util.ArrayList; import java.util.Arrays; public class SettingsState extends State { - private GameStateManager gsm; - private BitmapFont font; - public enum SettingsBackground { - MENU, - CITY, - } + private final GameStateManager gsm; + private final BitmapFont font; private ArrayList<Float> bgColor; private Boolean isBlack; private final CircleButton exitButton; + private final RectangleButton leaveGameButton; private final Slider audioBar; private final Slider sfxBar; private Texture bgImage; + private final Enums.GameType gameType; - public SettingsState(SettingsBackground bg) { + public SettingsState(Enums.SettingsBackground bg, Enums.GameType type) { gsm = GameStateManager.getGsm(); font = new BitmapFont(); + gameType = type; switch (bg) { case MENU: @@ -49,9 +46,22 @@ public class SettingsState extends State { break; } + switch (type) { + //Replace with leave game button when implemented + case SINGLEPLAYER: + leaveGameButton = new RectangleButton(0.7f, Gdx.graphics.getWidth() / 2, 30, "Lobby-button.png"); + break; + case MULTIPLAYER: + leaveGameButton = new RectangleButton(0.7f, Gdx.graphics.getWidth() / 2, 30, "Lobby-button.png"); + break; + default: + //For testing + leaveGameButton = new RectangleButton(0.7f, Gdx.graphics.getWidth() / 2, 30, "Lobby-button.png"); + } + exitButton = new CircleButton(70, Gdx.graphics.getWidth() - 200, Gdx.graphics.getHeight() - 140, "redExitCross.png"); - audioBar = new Slider(Slider.SliderType.AUDIO, 800, 30, 100); - sfxBar = new Slider(Slider.SliderType.SFX, 800, 30, -100); + audioBar = new Slider(Enums.SliderType.AUDIO, 800, 30, 100); + sfxBar = new Slider(Enums.SliderType.SFX, 800, 30, -100); if (isBlack) { font.setColor(Color.BLACK); } else { @@ -59,6 +69,36 @@ public class SettingsState extends State { } } + private void renderText(SpriteBatch sb) { + font.getData().setScale(8f); + GlyphLayout glyphLayout = new GlyphLayout(); + glyphLayout.setText(font, "Settings"); + font.draw(sb, "Settings", Gdx.graphics.getWidth() / 2f - glyphLayout.width / 2, Gdx.graphics.getHeight() - 80); + font.getData().setScale(3f); + font.draw(sb, "Audio", Gdx.graphics.getWidth() / 2f - 400, Gdx.graphics.getHeight() / 2f + 170); + font.draw(sb, "SFX", Gdx.graphics.getWidth() / 2f - 400, Gdx.graphics.getHeight() / 2f -30); + } + + private void renderExitButton(SpriteBatch sb) { + sb.draw(exitButton.getImg(), exitButton.getPosition().x - 40, exitButton.getPosition().y - 40, 80, 80); + } + private void renderAudioBar() { + audioBar.render(); + } + private void renderSfxBar() { + sfxBar.render(); + } + private void renderLeaveGame(SpriteBatch sb) { + switch (gameType) { + case SINGLEPLAYER: + case MULTIPLAYER: + sb.draw(leaveGameButton.getImg(), leaveGameButton.getPosition().x - leaveGameButton.getWidth() / 2f, leaveGameButton.getPosition().y, leaveGameButton.getWidth(), leaveGameButton.getHeight()); + break; + default: + break; + } + } + @Override public void update(float dt) { handleInput(); @@ -69,8 +109,9 @@ public class SettingsState extends State { ScreenUtils.clear(bgColor.get(0), bgColor.get(1), bgColor.get(2), bgColor.get(3)); sb.begin(); sb.draw(bgImage, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); - renderHeader(sb); + renderText(sb); renderExitButton(sb); + renderLeaveGame(sb); sb.end(); renderAudioBar(); renderSfxBar(); @@ -84,6 +125,8 @@ public class SettingsState extends State { if (exitButton.getBounds().contains(touchX, touchY)) { //dispose(); gsm.pop(); + } else if(leaveGameButton.getBounds().contains(touchX, touchY)) { + gsm.set(new GameMenuState()); } else { SettingsData settingsData = SettingsData.loadSettings(); settingsData.saveSettings(); @@ -98,23 +141,5 @@ public class SettingsState extends State { font.dispose(); } - private void renderHeader(SpriteBatch sb) { - font.getData().setScale(8f); - GlyphLayout glyphLayout = new GlyphLayout(); - glyphLayout.setText(font, "Settings"); - font.draw(sb, "Settings", Gdx.graphics.getWidth() / 2 - glyphLayout.width / 2, Gdx.graphics.getHeight() - 80); - } - - private void renderExitButton(SpriteBatch sb) { - sb.draw(exitButton.getImg(), exitButton.getPosition().x - 40, exitButton.getPosition().y - 40, 80, 80); - } - - private void renderAudioBar() { - audioBar.render(); - } - - private void renderSfxBar() { - sfxBar.render(); - } } diff --git a/core/src/com/mygdx/game/states/StartState.java b/core/src/com/mygdx/game/states/StartState.java index 6a24ab9d150a17b21d3e0303d174741796662ca7..d4c0be5ea645010df460a94e703e7d46727a62b6 100644 --- a/core/src/com/mygdx/game/states/StartState.java +++ b/core/src/com/mygdx/game/states/StartState.java @@ -45,12 +45,9 @@ public class StartState extends State implements InputProcessor { board.setTexture(4, 3, texture1); board.setTexture(5, 3, texture1); - board.setTexture(4, 5, texture1); - - - } + @Override public void update(float dt) { diff --git a/core/src/com/mygdx/game/utils/Enums.java b/core/src/com/mygdx/game/utils/Enums.java new file mode 100644 index 0000000000000000000000000000000000000000..573fc691959c60f0bd130e4e40fb48481f5cc822 --- /dev/null +++ b/core/src/com/mygdx/game/utils/Enums.java @@ -0,0 +1,19 @@ +package com.mygdx.game.utils; + +public class Enums { + public enum GameType { + SINGLEPLAYER, + MULTIPLAYER, + MENU + } + + public enum SettingsBackground { + MENU, + CITY, + } + + public enum SliderType { + AUDIO, + SFX + } +} diff --git a/core/src/com/mygdx/game/utils/Slider.java b/core/src/com/mygdx/game/utils/Slider.java index 25c40ad18ec8821eaf05291ece3956dc4552a30e..867a25a1f492f5a18204a05a05d511b607279747 100644 --- a/core/src/com/mygdx/game/utils/Slider.java +++ b/core/src/com/mygdx/game/utils/Slider.java @@ -1,29 +1,15 @@ package com.mygdx.game.utils; import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.MathUtils; -import com.badlogic.gdx.utils.Json; -import com.badlogic.gdx.utils.JsonReader; -import com.badlogic.gdx.utils.JsonValue; import com.mygdx.game.HeroesVsMonsters; -import java.awt.SystemTray; -import java.io.File; - public class Slider { - public enum SliderType { - AUDIO, - SFX - } private final ShapeRenderer shapeRenderer; private final SpriteBatch sb; - private final float SCREEN_WIDTH; - private final float SCREEN_HEIGHT; - - private final SliderType type; + private final Enums.SliderType sliderType; private final float width; private final float height; private float sliderValue; @@ -35,12 +21,12 @@ public class Slider { private float isTouched; private final SettingsData settingsData; - public Slider(SliderType type, float barWidth, float barHeight, float yPos) { + public Slider(Enums.SliderType type, float barWidth, float barHeight, float yPos) { //General variables sb = HeroesVsMonsters.getSb(); shapeRenderer = new ShapeRenderer(); - SCREEN_WIDTH = Gdx.graphics.getWidth(); - SCREEN_HEIGHT = Gdx.graphics.getHeight(); + float SCREEN_WIDTH = Gdx.graphics.getWidth(); + float SCREEN_HEIGHT = Gdx.graphics.getHeight(); settingsData = SettingsData.loadSettings(); @@ -56,7 +42,7 @@ public class Slider { } //Local variables - this.type = type; + this.sliderType = type; this.width = barWidth; this.height = barHeight; this.yPos = yPos; @@ -116,7 +102,7 @@ public class Slider { if (isTouched < 0.1f && isTouched >= 0) { isTouched += Gdx.graphics.getDeltaTime(); } else if (isTouched >= 0){ - switch (type) { + switch (sliderType) { case AUDIO: settingsData.AUDIO = ((int) (sliderValue * 100)); break;