Skip to content
Snippets Groups Projects
Commit 262f4e48 authored by Tor Martin Frøberg Wang's avatar Tor Martin Frøberg Wang
Browse files

Fixed some issues: removed unused peek method from gameware, removed boolean...

Fixed some issues: removed unused peek method from gameware, removed boolean parameter from the playstatetemplate constructor, and changed the initial starting state to loginstate
parent 21a7d23a
Branches
No related tags found
1 merge request!57Resolve "Fix bubble game"
...@@ -70,7 +70,7 @@ public class GameWare extends ApplicationAdapter { ...@@ -70,7 +70,7 @@ public class GameWare extends ApplicationAdapter {
music.setVolume(0.1f); music.setVolume(0.1f);
toggleMusic(); toggleMusic();
gsm.push(new BubbleWrapState(gsm)); gsm.push(new LoginState(gsm));
// try{ // try{
// List<Game> games = QueryIntermediate.getGames(); // List<Game> games = QueryIntermediate.getGames();
......
...@@ -5,29 +5,35 @@ import com.badlogic.gdx.graphics.Texture; ...@@ -5,29 +5,35 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.math.Vector3;
import javax.xml.soap.Text;
public class PauseButton extends Sprite { public class PauseButton extends Sprite {
private int width; private int width;
private int height; private int height;
private Vector3 position; private Vector3 position;
private Texture mainTexture; private Texture blackButtonTexture;
private Texture whiteButtonTexture;
private Texture currentActiveTexture;
// Customizable constructor // 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.position = new Vector3(x, y, 0);
this.width = width; this.width = width;
this.height = height; this.height = height;
this.mainTexture = pauseButtonTex; this.blackButtonTexture = blackBtnTex;
this.whiteButtonTexture = whiteBtnTex;
this.currentActiveTexture = blackButtonTexture;
} }
// Constructor with default settings (black button) // Constructor with default settings (black button)
public PauseButton(){ 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"))); this(Gdx.graphics.getWidth() - Gdx.graphics.getWidth()/8,
} Gdx.graphics.getHeight() - Gdx.graphics.getHeight()/13,
Gdx.graphics.getWidth()/10,Gdx.graphics.getWidth()/10,
// Constructor with default settings but customizable texture new Texture(Gdx.files.internal("glassy/raw/PauseButtonBlack.png")),
public PauseButton(Texture pauseButtonTex){ new Texture(Gdx.files.internal("glassy/raw/PauseButtonWhite.png")));
this(Gdx.graphics.getWidth() - Gdx.graphics.getWidth()/8,Gdx.graphics.getHeight() - Gdx.graphics.getHeight()/13,Gdx.graphics.getWidth()/10,Gdx.graphics.getWidth()/10, pauseButtonTex);
} }
...@@ -45,7 +51,7 @@ public class PauseButton extends Sprite { ...@@ -45,7 +51,7 @@ public class PauseButton extends Sprite {
public void draw(SpriteBatch sb) { public void draw(SpriteBatch sb) {
sb.begin(); 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(); sb.end();
} }
...@@ -56,10 +62,23 @@ public class PauseButton extends Sprite { ...@@ -56,10 +62,23 @@ public class PauseButton extends Sprite {
@Override @Override
public void dispose() { public void dispose() {
this.mainTexture.dispose(); this.blackButtonTexture.dispose();
this.whiteButtonTexture.dispose();
} }
public boolean isPressed(int x, int y){ 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); 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;
}
} }
...@@ -32,7 +32,8 @@ public class BubbleWrapState extends PlayStateTemplate { ...@@ -32,7 +32,8 @@ public class BubbleWrapState extends PlayStateTemplate {
public BubbleWrapState(GameStateManager gsm) { public BubbleWrapState(GameStateManager gsm) {
super(gsm, true); super(gsm);
super.setPauseButtonWhite();
unpopped = new Texture(Gdx.files.internal("glassy/raw/bubble_unpopped_1.png")); unpopped = new Texture(Gdx.files.internal("glassy/raw/bubble_unpopped_1.png"));
popped1 = new Texture(Gdx.files.internal("glassy/raw/bubble_popped_1.png")); popped1 = new Texture(Gdx.files.internal("glassy/raw/bubble_popped_1.png"));
...@@ -46,8 +47,6 @@ public class BubbleWrapState extends PlayStateTemplate { ...@@ -46,8 +47,6 @@ public class BubbleWrapState extends PlayStateTemplate {
this.background.setHeight(Gdx.graphics.getHeight()); this.background.setHeight(Gdx.graphics.getHeight());
stage.addActor(this.background); 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 // Label that displays how much time is left
this.timeLabel = new Label("Time left: ", skin); this.timeLabel = new Label("Time left: ", skin);
...@@ -176,7 +175,7 @@ public class BubbleWrapState extends PlayStateTemplate { ...@@ -176,7 +175,7 @@ public class BubbleWrapState extends PlayStateTemplate {
this.popped1.dispose(); this.popped1.dispose();
this.popped2.dispose(); this.popped2.dispose();
this.popped3.dispose(); this.popped3.dispose();
this.pauseButton.dispose(); super.pauseButton.dispose();
} }
@Override @Override
......
...@@ -31,7 +31,7 @@ public class ColorRushState extends PlayStateTemplate { ...@@ -31,7 +31,7 @@ public class ColorRushState extends PlayStateTemplate {
private boolean disposeTargetLeft = true; private boolean disposeTargetLeft = true;
public ColorRushState(GameStateManager gsm){ public ColorRushState(GameStateManager gsm){
super(gsm, false); super(gsm);
// Creates the background // Creates the background
this.background = new Texture(Gdx.files.internal("glassy/raw/ColorRushBackground.jpg")); this.background = new Texture(Gdx.files.internal("glassy/raw/ColorRushBackground.jpg"));
...@@ -214,6 +214,7 @@ public class ColorRushState extends PlayStateTemplate { ...@@ -214,6 +214,7 @@ public class ColorRushState extends PlayStateTemplate {
this.font.dispose(); this.font.dispose();
this.background.dispose(); this.background.dispose();
this.disabledColorTexture.dispose(); this.disabledColorTexture.dispose();
super.pauseButton.dispose();
} }
@Override @Override
......
...@@ -34,10 +34,6 @@ public class GameStateManager { ...@@ -34,10 +34,6 @@ public class GameStateManager {
states.push(state); states.push(state);
} }
public State peek(){
return states.get(states.size()-1);
}
public void removeCurrentState(){ public void removeCurrentState(){
states.remove(0).dispose(); states.remove(0).dispose();
} }
......
...@@ -21,18 +21,12 @@ public abstract class PlayStateTemplate extends State { ...@@ -21,18 +21,12 @@ public abstract class PlayStateTemplate extends State {
protected PauseButton pauseButton; protected PauseButton pauseButton;
protected float totalGameTime = 30f; protected float totalGameTime = 30f;
public PlayStateTemplate(GameStateManager gsm, boolean isPauseBtnWhite){ public PlayStateTemplate(GameStateManager gsm){
super(gsm); super(gsm);
if(isPauseBtnWhite){ // Default pause button (black color)
// 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(); this.pauseButton = new PauseButton();
} }
}
public void renderPauseButton(SpriteBatch sb){ public void renderPauseButton(SpriteBatch sb){
this.pauseButton.draw(sb); this.pauseButton.draw(sb);
...@@ -79,10 +73,21 @@ public abstract class PlayStateTemplate extends State { ...@@ -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(){ public void checkPause(){
if(this.pauseButton.isPressed(Gdx.input.getX(), Gdx.input.getY())){ if(this.pauseButton.isPressed(Gdx.input.getX(), Gdx.input.getY())){
this.gsm.push(new PauseState(this.gsm, this)); 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();
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment