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

Completes issue #60 and #73

parent ac21d8c2
Branches
No related tags found
1 merge request!57Resolve "Fix bubble game"
Showing
with 268 additions and 42 deletions
frontend/android/assets/glassy/raw/ConfirmationSprite.png

20.3 KiB

frontend/android/assets/glassy/raw/DimmingTexture.png

189 B

frontend/android/assets/glassy/raw/ExitButton.png

3.16 KiB

frontend/android/assets/glassy/raw/PauseText.png

54.8 KiB | W: | H:

frontend/android/assets/glassy/raw/PauseText.png

10.5 KiB | W: | H:

frontend/android/assets/glassy/raw/PauseText.png
frontend/android/assets/glassy/raw/PauseText.png
frontend/android/assets/glassy/raw/PauseText.png
frontend/android/assets/glassy/raw/PauseText.png
  • 2-up
  • Swipe
  • Onion skin
frontend/android/assets/glassy/raw/ResumeButton.png

5.5 KiB

...@@ -11,6 +11,7 @@ import com.gameware.game.states.BubbleWrapState; ...@@ -11,6 +11,7 @@ import com.gameware.game.states.BubbleWrapState;
import com.gameware.game.models.Player; import com.gameware.game.models.Player;
import com.gameware.game.states.ColorRushState; import com.gameware.game.states.ColorRushState;
import com.gameware.game.states.GameStateManager; import com.gameware.game.states.GameStateManager;
import com.gameware.game.states.PauseState;
import com.gameware.game.states.PlayStateTemplate; import com.gameware.game.states.PlayStateTemplate;
import com.gameware.game.states.LoginState; import com.gameware.game.states.LoginState;
...@@ -69,7 +70,8 @@ public class GameWare extends ApplicationAdapter { ...@@ -69,7 +70,8 @@ public class GameWare extends ApplicationAdapter {
music.setVolume(0.1f); music.setVolume(0.1f);
toggleMusic(); toggleMusic();
gsm.push(new LoginState(gsm)); gsm.push(new BubbleWrapState(gsm));
// try{ // try{
// List<Game> games = QueryIntermediate.getGames(); // List<Game> games = QueryIntermediate.getGames();
// System.out.println(games); // System.out.println(games);
......
...@@ -53,8 +53,6 @@ public class ColorRushButton extends Sprite{ ...@@ -53,8 +53,6 @@ public class ColorRushButton extends Sprite{
@Override @Override
public void update(float dt) { public void update(float dt) {
position.x = (int) Math.round(position.x);
position.y = (int) Math.round(position.y);
} }
@Override @Override
......
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;
}
}
...@@ -31,8 +31,6 @@ public class PauseButton extends Sprite { ...@@ -31,8 +31,6 @@ public class PauseButton extends Sprite {
} }
@Override @Override
public void reset() { public void reset() {
......
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);
}
}
package com.gameware.game.states; package com.gameware.game.states;
import com.badlogic.gdx.Gdx; 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.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.ui.Container; 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.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.gameware.game.GameWare;
import com.gameware.game.sprites.Bubble; import com.gameware.game.sprites.Bubble;
import com.gameware.game.sprites.PauseButton; import com.gameware.game.sprites.PauseButton;
...@@ -15,7 +20,7 @@ public class BubbleWrapState extends PlayStateTemplate { ...@@ -15,7 +20,7 @@ public class BubbleWrapState extends PlayStateTemplate {
private ArrayList<Bubble> bubbles; private ArrayList<Bubble> bubbles;
private int poppedBubbles; private int poppedBubbles;
private Texture background; private Image background;
private float currentTime = 0f; private float currentTime = 0f;
private float totalTime = totalGameTime; private float totalTime = totalGameTime;
private Label timeLabel; private Label timeLabel;
...@@ -27,7 +32,7 @@ public class BubbleWrapState extends PlayStateTemplate { ...@@ -27,7 +32,7 @@ public class BubbleWrapState extends PlayStateTemplate {
public BubbleWrapState(GameStateManager gsm) { public BubbleWrapState(GameStateManager gsm) {
super(gsm); super(gsm, true);
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"));
...@@ -35,12 +40,25 @@ public class BubbleWrapState extends PlayStateTemplate { ...@@ -35,12 +40,25 @@ public class BubbleWrapState extends PlayStateTemplate {
popped3 = new Texture(Gdx.files.internal("glassy/raw/bubble_popped_3.png")); popped3 = new Texture(Gdx.files.internal("glassy/raw/bubble_popped_3.png"));
this.poppedBubbles = 0; 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"))); 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);
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); stage.addActor(timeLabel);
...@@ -64,15 +82,18 @@ public class BubbleWrapState extends PlayStateTemplate { ...@@ -64,15 +82,18 @@ public class BubbleWrapState extends PlayStateTemplate {
} }
} }
// Keeps score consistent
this.setScore(this.poppedBubbles);
// Checks if the pause button was pressed // Checks if the pause button was pressed
if(this.pauseButton.isPressed(Gdx.input.getX(), Gdx.input.getY())){ super.checkPause();
this.gsm.push(new PauseState(this.gsm));
}
} }
} }
@Override @Override
public void update(float dt) { public void update(float dt) {
Gdx.input.setInputProcessor(stage);
this.handleInput(); this.handleInput();
this.currentTime += dt; this.currentTime += dt;
...@@ -95,12 +116,10 @@ public class BubbleWrapState extends PlayStateTemplate { ...@@ -95,12 +116,10 @@ public class BubbleWrapState extends PlayStateTemplate {
// Stage uses a Batch to draw // Stage uses a Batch to draw
@Override @Override
public void render(SpriteBatch sb) { 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(); stage.draw();
this.pauseButton.draw(sb); // Renders pause button
super.renderPauseButton(sb);
} }
......
...@@ -30,18 +30,12 @@ public class ColorRushState extends PlayStateTemplate { ...@@ -30,18 +30,12 @@ public class ColorRushState extends PlayStateTemplate {
private boolean buttonsEnabled = true; private boolean buttonsEnabled = true;
private boolean disposeTargetLeft = true; private boolean disposeTargetLeft = true;
private PauseButton pauseButton;
public ColorRushState(GameStateManager gsm){ public ColorRushState(GameStateManager gsm){
super(gsm); super(gsm, false);
// 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"));
// Creates the pause button
this.pauseButton = new PauseButton();
// Creates the bitmapfont // Creates the bitmapfont
font = new BitmapFont(); font = new BitmapFont();
font.setColor(Color.BLACK); font.setColor(Color.BLACK);
...@@ -71,6 +65,7 @@ public class ColorRushState extends PlayStateTemplate { ...@@ -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)); 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 targetWidth = Gdx.graphics.getWidth()/8;
int targetHeight = Gdx.graphics.getWidth()/8; int targetHeight = Gdx.graphics.getWidth()/8;
int targetX = Gdx.graphics.getWidth()/2 - targetWidth/2; int targetX = Gdx.graphics.getWidth()/2 - targetWidth/2;
...@@ -105,10 +100,11 @@ public class ColorRushState extends PlayStateTemplate { ...@@ -105,10 +100,11 @@ public class ColorRushState extends PlayStateTemplate {
} }
} }
// Checks if the pause button was pressed // Keeps score consistent
if(this.pauseButton.isPressed(Gdx.input.getX(), Gdx.input.getY())){ this.setScore(this.targetsHit);
this.gsm.push(new PauseState(this.gsm));
} //Pauses the game if the user pressed the pause button
super.checkPause();
} }
} }
...@@ -179,7 +175,8 @@ public class ColorRushState extends PlayStateTemplate { ...@@ -179,7 +175,8 @@ public class ColorRushState extends PlayStateTemplate {
sb.end(); sb.end();
this.pauseButton.draw(sb); // Renders pause button
super.renderPauseButton(sb);
for (ColorRushButton button : this.buttons) { for (ColorRushButton button : this.buttons) {
button.draw(sb); button.draw(sb);
......
...@@ -34,6 +34,10 @@ public class GameStateManager { ...@@ -34,6 +34,10 @@ 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();
} }
......
package com.gameware.game.states; package com.gameware.game.states;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture; 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.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer; 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.PauseCircle;
import com.gameware.game.sprites.PauseMenuButton;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import sun.awt.image.GifImageDecoder;
public class PauseState extends State { public class PauseState extends State {
private ShapeRenderer sr; private ShapeRenderer sr;
private List<PauseCircle> pauseCircles; private List<PauseCircle> pauseCircles;
private Texture background; private Texture background;
private Texture pauseText; private Texture pauseText;
private Texture dimmingTexture;
public PauseState(GameStateManager gsm) { private ConfirmationBox confirmationBox;
private PauseMenuButton resumeButton;
private PauseMenuButton exitButton;
private boolean needsConfirmation;
private PlayStateTemplate pausedGame;
public PauseState(GameStateManager gsm, PlayStateTemplate pausedGame) {
super(gsm); super(gsm);
this.background = new Texture(Gdx.files.internal("glassy/raw/PauseBackground.jpg")); this.background = new Texture(Gdx.files.internal("glassy/raw/PauseBackground.jpg"));
this.pauseText = new Texture(Gdx.files.internal("glassy/raw/PauseText.png")); 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.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++){ for(int i = 0; i<25; i++){
this.pauseCircles.add(new PauseCircle()); this.pauseCircles.add(new PauseCircle());
} }
...@@ -37,7 +53,33 @@ public class PauseState extends State { ...@@ -37,7 +53,33 @@ public class PauseState extends State {
@Override @Override
protected void handleInput() { protected void handleInput() {
if(Gdx.input.justTouched()){ if(Gdx.input.justTouched()){
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.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 { ...@@ -66,15 +108,31 @@ public class PauseState extends State {
} }
int scrollWidth = Gdx.graphics.getWidth()/2; // Draws the two bu
int scrollHeight = Gdx.graphics.getWidth()/4; this.resumeButton.draw(sb);
this.exitButton.draw(sb);
int textWidth = Gdx.graphics.getWidth()/2;
int textHeight = textWidth/15*4;
sb.begin(); sb.begin();
// Pause scroll // Pause text
sb.draw(this.pauseText, Gdx.graphics.getWidth()/2 - scrollWidth/2 , Gdx.graphics.getHeight()*3/4, scrollWidth, scrollHeight); 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(); sb.end();
// Needs confirmation if the user has pressed the exit button
if(this.needsConfirmation){
this.confirmationBox.draw(sb);
}
} }
@Override @Override
...@@ -85,6 +143,10 @@ public class PauseState extends State { ...@@ -85,6 +143,10 @@ public class PauseState extends State {
this.background.dispose(); this.background.dispose();
this.pauseText.dispose(); this.pauseText.dispose();
this.resumeButton.dispose();
this.exitButton.dispose();
this.confirmationBox.dispose();
this.dimmingTexture.dispose();
} }
@Override @Override
......
package com.gameware.game.states; 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.GameWare;
import com.gameware.game.QueryIntermediate; import com.gameware.game.QueryIntermediate;
import com.gameware.game.models.Round; import com.gameware.game.models.Round;
import com.gameware.game.models.Tournament; import com.gameware.game.models.Tournament;
import com.gameware.game.sprites.PauseButton;
import java.io.IOException; import java.io.IOException;
...@@ -14,10 +18,24 @@ public abstract class PlayStateTemplate extends State { ...@@ -14,10 +18,24 @@ public abstract class PlayStateTemplate extends State {
private Round round = null; private Round round = null;
private Tournament tournament = null; private Tournament tournament = null;
private Round nextRound = null; private Round nextRound = null;
protected PauseButton pauseButton;
protected float totalGameTime = 30f; protected float totalGameTime = 30f;
public PlayStateTemplate(GameStateManager gsm){ public PlayStateTemplate(GameStateManager gsm, boolean isPauseBtnWhite){
super(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();
}
}
public void renderPauseButton(SpriteBatch sb){
this.pauseButton.draw(sb);
} }
public void setRound(Round r){ public void setRound(Round r){
...@@ -60,5 +78,11 @@ public abstract class PlayStateTemplate extends State { ...@@ -60,5 +78,11 @@ public abstract class PlayStateTemplate extends State {
nextRound = QueryIntermediate.putRoundScore(round.get_id(),tournament.get_id(), this.score); 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));
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment