From 262f4e48093a9448c02aca257f21c73b24836110 Mon Sep 17 00:00:00 2001 From: Tor Martin Wang <tmwang@stud.ntnu.no> Date: Fri, 3 Apr 2020 21:26:54 +0200 Subject: [PATCH] Fixed some issues: removed unused peek method from gameware, removed boolean parameter from the playstatetemplate constructor, and changed the initial starting state to loginstate --- .../core/src/com/gameware/game/GameWare.java | 2 +- .../gameware/game/sprites/PauseButton.java | 41 ++++++++++++++----- .../gameware/game/states/BubbleWrapState.java | 7 ++-- .../gameware/game/states/ColorRushState.java | 3 +- .../game/states/GameStateManager.java | 4 -- .../game/states/PlayStateTemplate.java | 23 +++++++---- 6 files changed, 50 insertions(+), 30 deletions(-) diff --git a/frontend/core/src/com/gameware/game/GameWare.java b/frontend/core/src/com/gameware/game/GameWare.java index 383db4e..d0b7161 100644 --- a/frontend/core/src/com/gameware/game/GameWare.java +++ b/frontend/core/src/com/gameware/game/GameWare.java @@ -70,7 +70,7 @@ public class GameWare extends ApplicationAdapter { music.setVolume(0.1f); toggleMusic(); - gsm.push(new BubbleWrapState(gsm)); + gsm.push(new LoginState(gsm)); // try{ // List<Game> games = QueryIntermediate.getGames(); diff --git a/frontend/core/src/com/gameware/game/sprites/PauseButton.java b/frontend/core/src/com/gameware/game/sprites/PauseButton.java index e17d7dc..d80d13b 100644 --- a/frontend/core/src/com/gameware/game/sprites/PauseButton.java +++ b/frontend/core/src/com/gameware/game/sprites/PauseButton.java @@ -5,29 +5,35 @@ import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.Vector3; +import javax.xml.soap.Text; + public class PauseButton extends Sprite { private int width; private int height; private Vector3 position; - private Texture mainTexture; + private Texture blackButtonTexture; + private Texture whiteButtonTexture; + private Texture currentActiveTexture; // Customizable constructor - public PauseButton(int x, int y, int width, int height, Texture pauseButtonTex){ + public PauseButton(int x, int y, int width, int height, Texture blackBtnTex, Texture whiteBtnTex){ this.position = new Vector3(x, y, 0); this.width = width; this.height = height; - this.mainTexture = pauseButtonTex; + this.blackButtonTexture = blackBtnTex; + this.whiteButtonTexture = whiteBtnTex; + + this.currentActiveTexture = blackButtonTexture; } // Constructor with default settings (black button) public PauseButton(){ - this(Gdx.graphics.getWidth() - Gdx.graphics.getWidth()/8,Gdx.graphics.getHeight() - Gdx.graphics.getHeight()/13,Gdx.graphics.getWidth()/10,Gdx.graphics.getWidth()/10, new Texture(Gdx.files.internal("glassy/raw/PauseButtonBlack.png"))); - } - - // Constructor with default settings but customizable texture - public PauseButton(Texture pauseButtonTex){ - this(Gdx.graphics.getWidth() - Gdx.graphics.getWidth()/8,Gdx.graphics.getHeight() - Gdx.graphics.getHeight()/13,Gdx.graphics.getWidth()/10,Gdx.graphics.getWidth()/10, pauseButtonTex); + this(Gdx.graphics.getWidth() - Gdx.graphics.getWidth()/8, + Gdx.graphics.getHeight() - Gdx.graphics.getHeight()/13, + Gdx.graphics.getWidth()/10,Gdx.graphics.getWidth()/10, + new Texture(Gdx.files.internal("glassy/raw/PauseButtonBlack.png")), + new Texture(Gdx.files.internal("glassy/raw/PauseButtonWhite.png"))); } @@ -45,7 +51,7 @@ public class PauseButton extends Sprite { public void draw(SpriteBatch sb) { sb.begin(); - sb.draw(this.mainTexture, this.position.x, this.position.y, this.width, this.height); + sb.draw(this.currentActiveTexture, this.position.x, this.position.y, this.width, this.height); sb.end(); } @@ -56,10 +62,23 @@ public class PauseButton extends Sprite { @Override public void dispose() { - this.mainTexture.dispose(); + this.blackButtonTexture.dispose(); + this.whiteButtonTexture.dispose(); } public boolean isPressed(int x, int y){ return x > this.position.x && x < (this.position.x + this.width) && (Gdx.graphics.getHeight() - y) > this.position.y && (Gdx.graphics.getHeight() - y) < (this.position.y + this.height); } + + // The following two methods are used by the minigame-state to change the color of the pause button. + // This can be done during playtime if any future games has a dynamic background and want to + // alternate between using the two different colors on the pause button. + + public void setButtonWhite(){ + this.currentActiveTexture = this.whiteButtonTexture; + } + + public void setButtonBlack(){ + this.currentActiveTexture = this.whiteButtonTexture; + } } diff --git a/frontend/core/src/com/gameware/game/states/BubbleWrapState.java b/frontend/core/src/com/gameware/game/states/BubbleWrapState.java index 0515504..875eeab 100644 --- a/frontend/core/src/com/gameware/game/states/BubbleWrapState.java +++ b/frontend/core/src/com/gameware/game/states/BubbleWrapState.java @@ -32,7 +32,8 @@ public class BubbleWrapState extends PlayStateTemplate { public BubbleWrapState(GameStateManager gsm) { - super(gsm, true); + super(gsm); + super.setPauseButtonWhite(); unpopped = new Texture(Gdx.files.internal("glassy/raw/bubble_unpopped_1.png")); popped1 = new Texture(Gdx.files.internal("glassy/raw/bubble_popped_1.png")); @@ -46,8 +47,6 @@ public class BubbleWrapState extends PlayStateTemplate { this.background.setHeight(Gdx.graphics.getHeight()); stage.addActor(this.background); - this.pauseButton = new PauseButton(new Texture(Gdx.files.internal("glassy/raw/PauseButtonWhite.png"))); - // Label that displays how much time is left this.timeLabel = new Label("Time left: ", skin); @@ -176,7 +175,7 @@ public class BubbleWrapState extends PlayStateTemplate { this.popped1.dispose(); this.popped2.dispose(); this.popped3.dispose(); - this.pauseButton.dispose(); + super.pauseButton.dispose(); } @Override diff --git a/frontend/core/src/com/gameware/game/states/ColorRushState.java b/frontend/core/src/com/gameware/game/states/ColorRushState.java index 7a5f437..050df0b 100644 --- a/frontend/core/src/com/gameware/game/states/ColorRushState.java +++ b/frontend/core/src/com/gameware/game/states/ColorRushState.java @@ -31,7 +31,7 @@ public class ColorRushState extends PlayStateTemplate { private boolean disposeTargetLeft = true; public ColorRushState(GameStateManager gsm){ - super(gsm, false); + super(gsm); // Creates the background this.background = new Texture(Gdx.files.internal("glassy/raw/ColorRushBackground.jpg")); @@ -214,6 +214,7 @@ public class ColorRushState extends PlayStateTemplate { this.font.dispose(); this.background.dispose(); this.disabledColorTexture.dispose(); + super.pauseButton.dispose(); } @Override diff --git a/frontend/core/src/com/gameware/game/states/GameStateManager.java b/frontend/core/src/com/gameware/game/states/GameStateManager.java index b4af06f..420e730 100644 --- a/frontend/core/src/com/gameware/game/states/GameStateManager.java +++ b/frontend/core/src/com/gameware/game/states/GameStateManager.java @@ -34,10 +34,6 @@ public class GameStateManager { states.push(state); } - public State peek(){ - return states.get(states.size()-1); - } - public void removeCurrentState(){ states.remove(0).dispose(); } diff --git a/frontend/core/src/com/gameware/game/states/PlayStateTemplate.java b/frontend/core/src/com/gameware/game/states/PlayStateTemplate.java index 6a3d2f8..5e592d8 100644 --- a/frontend/core/src/com/gameware/game/states/PlayStateTemplate.java +++ b/frontend/core/src/com/gameware/game/states/PlayStateTemplate.java @@ -21,17 +21,11 @@ public abstract class PlayStateTemplate extends State { protected PauseButton pauseButton; protected float totalGameTime = 30f; - public PlayStateTemplate(GameStateManager gsm, boolean isPauseBtnWhite){ + public PlayStateTemplate(GameStateManager gsm){ super(gsm); - if(isPauseBtnWhite){ - // Uses customizable constructor with white button texture - this.pauseButton = new PauseButton(new Texture(Gdx.files.internal("glassy/raw/PauseButtonWhite.png"))); - } - else{ - // Uses default constructor; black button - this.pauseButton = new PauseButton(); - } + // Default pause button (black color) + this.pauseButton = new PauseButton(); } public void renderPauseButton(SpriteBatch sb){ @@ -79,10 +73,21 @@ public abstract class PlayStateTemplate extends State { } } + // Checks if the pause button was pressed, and pauses the minigame accordingly public void checkPause(){ if(this.pauseButton.isPressed(Gdx.input.getX(), Gdx.input.getY())){ this.gsm.push(new PauseState(this.gsm, this)); } } + + // Changes the color of the pause button to white + public void setPauseButtonWhite(){ + this.pauseButton.setButtonWhite(); + } + + // Changes the color of the pause button back to black if it was previously changed to white + public void setPauseButtonBlack(){ + this.pauseButton.setButtonBlack(); + } } -- GitLab