diff --git a/frontend/android/assets/glassy/raw/ConfirmationSprite.png b/frontend/android/assets/glassy/raw/ConfirmationSprite.png new file mode 100644 index 0000000000000000000000000000000000000000..90edb606773c8507471d2e2fcd165adf9dd19929 Binary files /dev/null and b/frontend/android/assets/glassy/raw/ConfirmationSprite.png differ diff --git a/frontend/android/assets/glassy/raw/DimmingTexture.png b/frontend/android/assets/glassy/raw/DimmingTexture.png new file mode 100644 index 0000000000000000000000000000000000000000..660a9ad25cc2fc6574570093cd25ca857ef67e71 Binary files /dev/null and b/frontend/android/assets/glassy/raw/DimmingTexture.png differ diff --git a/frontend/android/assets/glassy/raw/ExitButton.png b/frontend/android/assets/glassy/raw/ExitButton.png new file mode 100644 index 0000000000000000000000000000000000000000..feb789f751ee76ad8d6e25bdc7e98609d4e09ee9 Binary files /dev/null and b/frontend/android/assets/glassy/raw/ExitButton.png differ diff --git a/frontend/android/assets/glassy/raw/PauseText.png b/frontend/android/assets/glassy/raw/PauseText.png index 32c2b42a05fa52302d22c006bcde72b22a6b55ff..7496fd7f6ca2aed81453db867919af7c512ae687 100644 Binary files a/frontend/android/assets/glassy/raw/PauseText.png and b/frontend/android/assets/glassy/raw/PauseText.png differ diff --git a/frontend/android/assets/glassy/raw/ResumeButton.png b/frontend/android/assets/glassy/raw/ResumeButton.png new file mode 100644 index 0000000000000000000000000000000000000000..eb15370fced7cb1222d15240f8afe28ee403587a Binary files /dev/null and b/frontend/android/assets/glassy/raw/ResumeButton.png differ diff --git a/frontend/core/src/com/gameware/game/GameWare.java b/frontend/core/src/com/gameware/game/GameWare.java index fa124df573de2e5b946d87a8cd9be0b55c3091b4..383db4e1701b2513ab27e80e80e895e113c67469 100644 --- a/frontend/core/src/com/gameware/game/GameWare.java +++ b/frontend/core/src/com/gameware/game/GameWare.java @@ -11,6 +11,7 @@ import com.gameware.game.states.BubbleWrapState; import com.gameware.game.models.Player; import com.gameware.game.states.ColorRushState; import com.gameware.game.states.GameStateManager; +import com.gameware.game.states.PauseState; import com.gameware.game.states.PlayStateTemplate; import com.gameware.game.states.LoginState; @@ -69,7 +70,8 @@ public class GameWare extends ApplicationAdapter { music.setVolume(0.1f); toggleMusic(); - gsm.push(new LoginState(gsm)); + gsm.push(new BubbleWrapState(gsm)); + // try{ // List<Game> games = QueryIntermediate.getGames(); // System.out.println(games); diff --git a/frontend/core/src/com/gameware/game/sprites/ColorRushButton.java b/frontend/core/src/com/gameware/game/sprites/ColorRushButton.java index 0a0f61e4ef1aecde49330a4dcde8d5f73115e1ba..da1295de40bbde182ffaac1a692ba0b37fdec4e8 100644 --- a/frontend/core/src/com/gameware/game/sprites/ColorRushButton.java +++ b/frontend/core/src/com/gameware/game/sprites/ColorRushButton.java @@ -53,8 +53,6 @@ public class ColorRushButton extends Sprite{ @Override public void update(float dt) { - position.x = (int) Math.round(position.x); - position.y = (int) Math.round(position.y); } @Override diff --git a/frontend/core/src/com/gameware/game/sprites/ConfirmationBox.java b/frontend/core/src/com/gameware/game/sprites/ConfirmationBox.java new file mode 100644 index 0000000000000000000000000000000000000000..c71e524080c4fa27544e3a42b881b7b4850500cb --- /dev/null +++ b/frontend/core/src/com/gameware/game/sprites/ConfirmationBox.java @@ -0,0 +1,72 @@ +package com.gameware.game.sprites; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.math.Vector3; + +public class ConfirmationBox extends Sprite { + + private Texture boxTexture; + private Vector3 position; + private int width, height; + + public ConfirmationBox(int x, int y, int width, int height){ + this.position = new Vector3(x, y,0); + this.width = width; + this.height = height; + + this.boxTexture = new Texture(Gdx.files.internal("glassy/raw/ConfirmationSprite.png")); + } + + @Override + public void reset() { + + } + + @Override + public Object report() { + return null; + } + + @Override + public void draw(SpriteBatch sb) { + sb.begin(); + sb.draw(this.boxTexture, this.position.x, this.position.y, this.width, this.height); + sb.end(); + } + + @Override + public void update(float dt) { + + } + + @Override + public void dispose() { + this.boxTexture.dispose(); + } + + public boolean yesPressed(int xTouch, int yTouch){ + return xTouch > this.position.x && xTouch < (this.position.x + this.width/2) && yTouch > this.position.y && yTouch < (this.position.y + this.height/2); + } + + public boolean noPressed(int xTouch, int yTouch){ + return xTouch > (this.position.x + this.width/2) && xTouch < (this.position.x + this.width) && yTouch > this.position.y && yTouch < (this.position.y + this.height/2); + } + + public int getX(){ + return (int) this.position.x; + } + + public int getY(){ + return (int) this.position.y; + } + + public int getWidth(){ + return this.width; + } + + public int getHeight(){ + return this.height; + } +} diff --git a/frontend/core/src/com/gameware/game/sprites/PauseButton.java b/frontend/core/src/com/gameware/game/sprites/PauseButton.java index fd3faf33b222c5ef8e44eb34a977603eca0d39b5..e17d7dc6085ecbe69659fe12207aa0473eed85aa 100644 --- a/frontend/core/src/com/gameware/game/sprites/PauseButton.java +++ b/frontend/core/src/com/gameware/game/sprites/PauseButton.java @@ -31,8 +31,6 @@ public class PauseButton extends Sprite { } - - @Override public void reset() { diff --git a/frontend/core/src/com/gameware/game/sprites/PauseMenuButton.java b/frontend/core/src/com/gameware/game/sprites/PauseMenuButton.java new file mode 100644 index 0000000000000000000000000000000000000000..4f110911dd3fe829b09eaf740c89357ef0c46ae3 --- /dev/null +++ b/frontend/core/src/com/gameware/game/sprites/PauseMenuButton.java @@ -0,0 +1,50 @@ +package com.gameware.game.sprites; + +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.math.Vector3; + +public class PauseMenuButton extends Sprite { + private Texture buttonTexture; + private Vector3 position; + private int width, height; + + public PauseMenuButton(Texture buttonTex, int x, int y, int width, int height){ + this.buttonTexture = buttonTex; + this.width = width; + this.height = height; + + this.position = new Vector3(x, y,0); + } + + @Override + public void reset() { + + } + + @Override + public Object report() { + return null; + } + + @Override + public void draw(SpriteBatch sb) { + sb.begin(); + sb.draw(this.buttonTexture, this.position.x, this.position.y, this.width, this.height); + sb.end(); + } + + @Override + public void update(float dt) { + + } + + @Override + public void dispose() { + this.buttonTexture.dispose(); + } + + public boolean isPressed(int xTouch, int yTouch){ + return xTouch > this.position.x && xTouch < (this.position.x + this.width) && yTouch > this.position.y && yTouch < (this.position.y + this.height); + } +} diff --git a/frontend/core/src/com/gameware/game/states/BubbleWrapState.java b/frontend/core/src/com/gameware/game/states/BubbleWrapState.java index 66ea48c3ff7712313fcb3c789ccaf2fb6033ae22..0515504bd8bd0c93720206b6094063bf34342ff0 100644 --- a/frontend/core/src/com/gameware/game/states/BubbleWrapState.java +++ b/frontend/core/src/com/gameware/game/states/BubbleWrapState.java @@ -1,11 +1,16 @@ package com.gameware.game.states; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.scenes.scene2d.ui.Container; +import com.badlogic.gdx.scenes.scene2d.ui.Image; import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.Table; +import com.gameware.game.GameWare; import com.gameware.game.sprites.Bubble; import com.gameware.game.sprites.PauseButton; @@ -15,7 +20,7 @@ public class BubbleWrapState extends PlayStateTemplate { private ArrayList<Bubble> bubbles; private int poppedBubbles; - private Texture background; + private Image background; private float currentTime = 0f; private float totalTime = totalGameTime; private Label timeLabel; @@ -27,7 +32,7 @@ public class BubbleWrapState extends PlayStateTemplate { public BubbleWrapState(GameStateManager gsm) { - super(gsm); + super(gsm, true); unpopped = new Texture(Gdx.files.internal("glassy/raw/bubble_unpopped_1.png")); popped1 = new Texture(Gdx.files.internal("glassy/raw/bubble_popped_1.png")); @@ -35,12 +40,25 @@ public class BubbleWrapState extends PlayStateTemplate { popped3 = new Texture(Gdx.files.internal("glassy/raw/bubble_popped_3.png")); this.poppedBubbles = 0; - this.background = new Texture(Gdx.files.internal("glassy/raw/bubblewrap_background.jpg")); + + this.background = new Image(new Texture(Gdx.files.internal("glassy/raw/bubblewrap_background.jpg"))); + this.background.setWidth(Gdx.graphics.getWidth()); + 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); - timeLabel.setPosition(Gdx.graphics.getWidth()/8, Gdx.graphics.getHeight() - Gdx.graphics.getHeight()/10); + + // Changes the label to a white color + BitmapFont font = new BitmapFont(); + font.getData().setScale(Gdx.graphics.getWidth() / GameWare.WIDTH * 2.5f); + Label.LabelStyle style = new Label.LabelStyle(font, Color.WHITE); + timeLabel.setStyle(style); + + timeLabel.setPosition(Gdx.graphics.getWidth()/2 - timeLabel.getWidth() / 2f, Gdx.graphics.getHeight() - Gdx.graphics.getHeight()/10); + stage.addActor(timeLabel); @@ -64,15 +82,18 @@ public class BubbleWrapState extends PlayStateTemplate { } } + // Keeps score consistent + this.setScore(this.poppedBubbles); + // Checks if the pause button was pressed - if(this.pauseButton.isPressed(Gdx.input.getX(), Gdx.input.getY())){ - this.gsm.push(new PauseState(this.gsm)); - } + super.checkPause(); } } @Override public void update(float dt) { + Gdx.input.setInputProcessor(stage); + this.handleInput(); this.currentTime += dt; @@ -95,12 +116,10 @@ public class BubbleWrapState extends PlayStateTemplate { // Stage uses a Batch to draw @Override public void render(SpriteBatch sb) { - stage.getBatch().begin(); - stage.getBatch().draw(this.background, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); - stage.getBatch().end(); stage.draw(); - this.pauseButton.draw(sb); + // Renders pause button + super.renderPauseButton(sb); } diff --git a/frontend/core/src/com/gameware/game/states/ColorRushState.java b/frontend/core/src/com/gameware/game/states/ColorRushState.java index cd6627ccd082ca91ecc38ee0d4933cf5c8fc8e6d..7a5f437e079e9658a985271a38a7776c96d0210b 100644 --- a/frontend/core/src/com/gameware/game/states/ColorRushState.java +++ b/frontend/core/src/com/gameware/game/states/ColorRushState.java @@ -30,18 +30,12 @@ public class ColorRushState extends PlayStateTemplate { private boolean buttonsEnabled = true; private boolean disposeTargetLeft = true; - - private PauseButton pauseButton; - public ColorRushState(GameStateManager gsm){ - super(gsm); + super(gsm, false); // Creates the background this.background = new Texture(Gdx.files.internal("glassy/raw/ColorRushBackground.jpg")); - // Creates the pause button - this.pauseButton = new PauseButton(); - // Creates the bitmapfont font = new BitmapFont(); font.setColor(Color.BLACK); @@ -71,6 +65,7 @@ public class ColorRushState extends PlayStateTemplate { buttons.add(new ColorRushButton(Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/8,Gdx.graphics.getWidth()/2,Gdx.graphics.getHeight()/8, this.colorTextures.get(3), this.disabledColorTexture, 3)); + // Parameters for the targets int targetWidth = Gdx.graphics.getWidth()/8; int targetHeight = Gdx.graphics.getWidth()/8; int targetX = Gdx.graphics.getWidth()/2 - targetWidth/2; @@ -105,10 +100,11 @@ public class ColorRushState extends PlayStateTemplate { } } - // Checks if the pause button was pressed - if(this.pauseButton.isPressed(Gdx.input.getX(), Gdx.input.getY())){ - this.gsm.push(new PauseState(this.gsm)); - } + // Keeps score consistent + this.setScore(this.targetsHit); + + //Pauses the game if the user pressed the pause button + super.checkPause(); } } @@ -179,7 +175,8 @@ public class ColorRushState extends PlayStateTemplate { sb.end(); - this.pauseButton.draw(sb); + // Renders pause button + super.renderPauseButton(sb); for (ColorRushButton button : this.buttons) { button.draw(sb); diff --git a/frontend/core/src/com/gameware/game/states/GameStateManager.java b/frontend/core/src/com/gameware/game/states/GameStateManager.java index 420e7306fef9dc1c56a69ca5dc83ae273b90279f..b4af06f1ec5ac73f6c32204a4c3547a9f2dd0748 100644 --- a/frontend/core/src/com/gameware/game/states/GameStateManager.java +++ b/frontend/core/src/com/gameware/game/states/GameStateManager.java @@ -34,6 +34,10 @@ 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/PauseState.java b/frontend/core/src/com/gameware/game/states/PauseState.java index 3a168203804252681ac505df7980ae289feee8bd..2b67f3d3c3b97358022633802fa533d469a73e18 100644 --- a/frontend/core/src/com/gameware/game/states/PauseState.java +++ b/frontend/core/src/com/gameware/game/states/PauseState.java @@ -1,34 +1,50 @@ package com.gameware.game.states; import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Texture; -import com.badlogic.gdx.graphics.g2d.Animation; import com.badlogic.gdx.graphics.g2d.SpriteBatch; -import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; -import com.gameware.game.sprites.LoadingCircle; +import com.gameware.game.sprites.ConfirmationBox; import com.gameware.game.sprites.PauseCircle; +import com.gameware.game.sprites.PauseMenuButton; import java.util.ArrayList; import java.util.List; -import sun.awt.image.GifImageDecoder; - public class PauseState extends State { private ShapeRenderer sr; private List<PauseCircle> pauseCircles; private Texture background; private Texture pauseText; - - public PauseState(GameStateManager gsm) { + private Texture dimmingTexture; + private ConfirmationBox confirmationBox; + private PauseMenuButton resumeButton; + private PauseMenuButton exitButton; + private boolean needsConfirmation; + private PlayStateTemplate pausedGame; + + public PauseState(GameStateManager gsm, PlayStateTemplate pausedGame) { super(gsm); this.background = new Texture(Gdx.files.internal("glassy/raw/PauseBackground.jpg")); this.pauseText = new Texture(Gdx.files.internal("glassy/raw/PauseText.png")); + this.dimmingTexture = new Texture(Gdx.files.internal("glassy/raw/DimmingTexture.png")); this.pauseCircles = new ArrayList<PauseCircle>(); + this.pausedGame = pausedGame; + + int confirmationBoxWidth = Gdx.graphics.getWidth()*7/8; + int confirmationBoxHeight = confirmationBoxWidth/2; + this.confirmationBox = new ConfirmationBox(Gdx.graphics.getWidth()/2 - confirmationBoxWidth/2, Gdx.graphics.getHeight()/2 - confirmationBoxHeight/2, confirmationBoxWidth, confirmationBoxHeight); + this.needsConfirmation = false; + + int buttonWidth = Gdx.graphics.getWidth()/3; + int buttonHeight = buttonWidth/2; + this.resumeButton = new PauseMenuButton(new Texture(Gdx.files.internal("glassy/raw/ResumeButton.png")), buttonWidth/3, Gdx.graphics.getHeight()/7, buttonWidth, buttonHeight); + this.exitButton = new PauseMenuButton(new Texture(Gdx.files.internal("glassy/raw/ExitButton.png")), buttonWidth + buttonWidth*2/3, Gdx.graphics.getHeight()/7, buttonWidth, buttonHeight); + + for(int i = 0; i<25; i++){ this.pauseCircles.add(new PauseCircle()); } @@ -37,7 +53,33 @@ public class PauseState extends State { @Override protected void handleInput() { if(Gdx.input.justTouched()){ - this.gsm.pop(); + int touchX = Gdx.input.getX(); + int touchY = Gdx.graphics.getHeight() - Gdx.input.getY(); + + if(this.needsConfirmation) { + // User doesn't want to exit after all + if(this.confirmationBox.noPressed(touchX, touchY)) { + this.needsConfirmation = false; + } + + // User confirms the exit, posts the current score + if(this.confirmationBox.yesPressed(touchX, touchY)) { + this.gsm.pop(); + this.pausedGame.gameDone(); + } + } + + else { + // Resumes the game + if(this.resumeButton.isPressed(touchX, touchY)){ + this.gsm.pop(); + } + + // First step of exitting; user now needs to confirm the exit via the popup + if(this.exitButton.isPressed(touchX, touchY)){ + this.needsConfirmation = true; + } + } } } @@ -66,15 +108,31 @@ public class PauseState extends State { } - int scrollWidth = Gdx.graphics.getWidth()/2; - int scrollHeight = Gdx.graphics.getWidth()/4; + // Draws the two bu + this.resumeButton.draw(sb); + this.exitButton.draw(sb); + + int textWidth = Gdx.graphics.getWidth()/2; + int textHeight = textWidth/15*4; sb.begin(); - // Pause scroll - sb.draw(this.pauseText, Gdx.graphics.getWidth()/2 - scrollWidth/2 , Gdx.graphics.getHeight()*3/4, scrollWidth, scrollHeight); + // Pause text + sb.draw(this.pauseText, Gdx.graphics.getWidth()/2 - textWidth/2 , Gdx.graphics.getHeight()*7/10, textWidth, textHeight); + + // Dimming layer that dims everything except the confirmation box when the + // user needs to confirm exit + if(this.needsConfirmation) { + sb.draw(this.dimmingTexture, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); + } sb.end(); + + // Needs confirmation if the user has pressed the exit button + if(this.needsConfirmation){ + this.confirmationBox.draw(sb); + } + } @Override @@ -85,6 +143,10 @@ public class PauseState extends State { this.background.dispose(); this.pauseText.dispose(); + this.resumeButton.dispose(); + this.exitButton.dispose(); + this.confirmationBox.dispose(); + this.dimmingTexture.dispose(); } @Override diff --git a/frontend/core/src/com/gameware/game/states/PlayStateTemplate.java b/frontend/core/src/com/gameware/game/states/PlayStateTemplate.java index 369c7d391daea36449dfd878fb0d061897f0f983..6a3d2f87a09a375d89ebebfcc7a6beab95e4a4d9 100644 --- a/frontend/core/src/com/gameware/game/states/PlayStateTemplate.java +++ b/frontend/core/src/com/gameware/game/states/PlayStateTemplate.java @@ -1,10 +1,14 @@ package com.gameware.game.states; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.gameware.game.GameWare; import com.gameware.game.QueryIntermediate; import com.gameware.game.models.Round; import com.gameware.game.models.Tournament; +import com.gameware.game.sprites.PauseButton; import java.io.IOException; @@ -14,10 +18,24 @@ public abstract class PlayStateTemplate extends State { private Round round = null; private Tournament tournament = null; private Round nextRound = null; + protected PauseButton pauseButton; protected float totalGameTime = 30f; - public PlayStateTemplate(GameStateManager gsm){ + public PlayStateTemplate(GameStateManager gsm, boolean isPauseBtnWhite){ 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(); + } + } + + public void renderPauseButton(SpriteBatch sb){ + this.pauseButton.draw(sb); } public void setRound(Round r){ @@ -60,5 +78,11 @@ public abstract class PlayStateTemplate extends State { nextRound = QueryIntermediate.putRoundScore(round.get_id(),tournament.get_id(), this.score); } } + + public void checkPause(){ + if(this.pauseButton.isPressed(Gdx.input.getX(), Gdx.input.getY())){ + this.gsm.push(new PauseState(this.gsm, this)); + } + } }