Commit 9da73392 authored by Tor Martin Frøberg Wang's avatar Tor Martin Frøberg Wang
Browse files

Almost completes issue #73

parent 382cc8e7
......@@ -70,6 +70,7 @@ public class GameWare extends ApplicationAdapter {
music.setVolume(0.1f);
toggleMusic();
//gsm.push(new LoginState(gsm));
gsm.push(new LoginState(gsm));
// try{
......
package com.gameware.game.sprites;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class LoadingText extends Sprite {
private boolean isLoading = false;
private boolean firstUpdateFinished = false;
private Texture loadingText = new Texture(Gdx.files.internal("LoadingText.png"));
private Texture dimmingBackgroundTexture = new Texture(Gdx.files.internal("DimmingTexture.png"));
@Override
public void reset() {
this.firstUpdateFinished = false;
this.isLoading = false;
}
@Override
public void draw(SpriteBatch sb) {
if(this.isLoading) {
sb.begin();
sb.draw(this.dimmingBackgroundTexture, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
sb.draw(this.loadingText, Gdx.graphics.getWidth() / 4, Gdx.graphics.getHeight() / 2, Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 10);
sb.end();
}
}
@Override
public void update(float dt) {
// If we've already completed the first call to this update method after isLoading was
// set to true (this means that the draw method has been called) and the loading text is
// visible we know that the loading has finished
if(this.isLoading && this.firstUpdateFinished){
this.isLoading = false;
this.firstUpdateFinished = false;
}
// We need to wait one iteration of update() for the screen to render the loading text first
else if(this.isLoading){
this.firstUpdateFinished = true;
}
}
@Override
public void dispose() {
this.dimmingBackgroundTexture.dispose();
this.loadingText.dispose();
}
public void setLoading(){
this.isLoading = true;
}
public boolean textIsRendering(){
return this.firstUpdateFinished && this.isLoading;
}
}
......@@ -82,20 +82,19 @@ public class BubbleWrapState extends PlayStateTemplate {
// Keeps score consistent
this.setScore(this.poppedBubbles);
// Checks if the pause button was pressed
super.checkPause();
}
}
@Override
public void update(float dt) {
super.update(dt);
Gdx.input.setInputProcessor(stage);
this.handleInput();
this.currentTime += dt;
timeLabel.setText("Time left: " + Math.round((totalTime - currentTime) * 100.0) / 100.0);
timeLabel.setText("Time left: " + Math.max(Math.round((totalTime - currentTime) * 100.0) / 100.0, 0.00));
// Game should finish if the time has run out
if (this.currentTime >= this.totalTime) {
......@@ -116,9 +115,7 @@ public class BubbleWrapState extends PlayStateTemplate {
public void render(SpriteBatch sb) {
stage.draw();
// Renders pause button
super.renderPauseButton(sb);
super.render(sb);
}
private void createBubbles() {
......@@ -163,18 +160,19 @@ public class BubbleWrapState extends PlayStateTemplate {
private void handleFinishedGame() {
System.out.println("Game finished, starting new state");
this.setScore(this.poppedBubbles);
this.gameDone();
super.setGameFinished();
return;
}
@Override
public void dispose() {
super.dispose();
stage.dispose();
this.unpopped.dispose();
this.popped1.dispose();
this.popped2.dispose();
this.popped3.dispose();
super.pauseButton.dispose();
}
@Override
......
......@@ -7,7 +7,6 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.gameware.game.GameWare;
import com.gameware.game.sprites.ColorRushButton;
import com.gameware.game.sprites.ColorRushTarget;
import com.gameware.game.sprites.PauseButton;
import java.util.ArrayList;
import java.util.Collections;
......@@ -103,23 +102,21 @@ public class ColorRushState extends PlayStateTemplate {
// Keeps score consistent
this.setScore(this.targetsHit);
//Pauses the game if the user pressed the pause button
super.checkPause();
}
}
@Override
public void update(float dt) {
super.update(dt);
// Increases the current duration, used to keep track of the play duration and stop the game
// after a while
this.currentDuration += dt;
// Post score and exit if the game is over
// Set score and start rendering the loading text if the game is over
if(this.currentDuration > this.totalGameDuration){
this.setScore(this.targetsHit);
this.gameDone();
this.setGameFinished();
return;
}
......@@ -171,14 +168,10 @@ public class ColorRushState extends PlayStateTemplate {
sb.draw(this.background, 0, Gdx.graphics.getHeight()/5, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
// Time left
this.font.draw(sb, String.valueOf(Math.round((this.totalGameDuration - this.currentDuration) * 100) / 100.0), Gdx.graphics.getWidth()/40,Gdx.graphics.getHeight() - Gdx.graphics.getHeight()/40);
this.font.draw(sb, String.valueOf(Math.max(Math.round((this.totalGameDuration - this.currentDuration) * 100), 0.00) / 100.0), Gdx.graphics.getWidth()/40,Gdx.graphics.getHeight() - Gdx.graphics.getHeight()/40);
sb.end();
// Renders pause button
super.renderPauseButton(sb);
for (ColorRushButton button : this.buttons) {
button.draw(sb);
}
......@@ -191,11 +184,13 @@ public class ColorRushState extends PlayStateTemplate {
target.draw(sb);
}
super.render(sb);
}
@Override
public void dispose() {
super.dispose();
for (ColorRushButton button : this.buttons) {
button.dispose();
}
......@@ -215,7 +210,6 @@ public class ColorRushState extends PlayStateTemplate {
this.font.dispose();
this.background.dispose();
this.disabledColorTexture.dispose();
super.pauseButton.dispose();
}
@Override
......
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.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
......@@ -12,6 +13,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.gameware.game.GameWare;
import com.gameware.game.QueryIntermediate;
import com.gameware.game.models.Player;
import com.gameware.game.sprites.LoadingText;
import java.io.IOException;
import java.util.NoSuchElementException;
......@@ -39,6 +41,12 @@ public class LoginState extends State {
private String takenUsernameText = "Username already taken";
private String ioExceptionText = "Something went wrong with query";
private LoadingText loadingText = new LoadingText();
private boolean loginBtnClicked = false;
private boolean signUpBtnClicked = false;
public LoginState(GameStateManager gsm) {
super(gsm);
makeStage();
......@@ -82,7 +90,7 @@ public class LoginState extends State {
loginBtn.addListener(new ClickListener() {
@Override
public void clicked(InputEvent e, float x, float y){
handleLoginBtnClick();
setLoginBtnClicked();
}
});
return loginBtn;
......@@ -93,7 +101,7 @@ public class LoginState extends State {
signUpBtn.addListener(new ClickListener() {
@Override
public void clicked(InputEvent e, float x, float y){
handleSignUpBtnClick();
setSignUpBtnClicked();
}
});
return signUpBtn;
......@@ -142,11 +150,23 @@ public class LoginState extends State {
@Override
public void update(float dt) {
stage.act(dt);
if(this.loginBtnClicked && this.loadingText.textIsRendering()){
this.handleLoginBtnClick();
}
if(this.signUpBtnClicked && this.loadingText.textIsRendering()){
this.handleSignUpBtnClick();
}
this.loadingText.update(dt);
}
@Override
public void render(SpriteBatch sb) {
stage.draw();
this.loadingText.draw(sb);
}
@Override
......@@ -160,6 +180,16 @@ public class LoginState extends State {
passwordInputField.setText(passwordInputText);
}
private void setLoginBtnClicked(){
this.loginBtnClicked = true;
this.loadingText.setLoading();
}
private void setSignUpBtnClicked(){
this.signUpBtnClicked = true;
this.loadingText.setLoading();
}
private void handleLoginBtnClick(){
String username = usernameInputField.getText();
String password = passwordInputField.getText();
......@@ -180,6 +210,8 @@ public class LoginState extends State {
System.out.println(e);
errorLabel.setText(e.getMessage());
}
this.loginBtnClicked = false;
}
private void handleSignUpBtnClick(){
......@@ -202,5 +234,7 @@ public class LoginState extends State {
System.out.println(e);
errorLabel.setText(e.getMessage());
}
this.signUpBtnClicked = false;
}
}
......@@ -9,6 +9,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.gameware.game.GameWare;
import com.gameware.game.sprites.LoadingText;
public class MenuState extends State{
......@@ -23,6 +24,10 @@ public class MenuState extends State{
private String optionBtnText = "Options";
private String logOutBtnText = "Log out";
private boolean multiBtnClicked = false;
private LoadingText loadingText = new LoadingText();
public MenuState(GameStateManager gsm) {
super(gsm);
makeStage();
......@@ -66,7 +71,7 @@ public class MenuState extends State{
TextButton multiPlayerBtn = new TextButton(multiPlayerBtnText, skin);
multiPlayerBtn.addListener(new ClickListener() {
@Override
public void clicked(InputEvent e, float x, float y){ handleMultiBtnClick(); }
public void clicked(InputEvent e, float x, float y){ setMultiBtnClicked(); }
});
return multiPlayerBtn;
}
......@@ -110,6 +115,11 @@ public class MenuState extends State{
@Override
public void update(float dt) {
if(this.multiBtnClicked && this.loadingText.textIsRendering()){
this.handleMultiBtnClick();
}
this.loadingText.update(dt);
Gdx.input.setInputProcessor(stage);
Gdx.input.setCatchBackKey(true);
handleInput();
......@@ -117,7 +127,10 @@ public class MenuState extends State{
}
@Override
public void render(SpriteBatch sb) { stage.draw(); }
public void render(SpriteBatch sb) {
stage.draw();
this.loadingText.draw(sb);
}
@Override
public void dispose() { stage.dispose(); }
......@@ -125,6 +138,11 @@ public class MenuState extends State{
@Override
public void reset() { }
private void setMultiBtnClicked(){
this.multiBtnClicked = true;
this.loadingText.setLoading();
}
private void handleOptionsBtnClick(){
gsm.set(new OptionsState(gsm));
}
......
......@@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.gameware.game.sprites.ConfirmationBox;
import com.gameware.game.sprites.LoadingText;
import com.gameware.game.sprites.PauseCircle;
import com.gameware.game.sprites.PauseMenuButton;
......@@ -22,18 +23,23 @@ public class PauseState extends State {
private PauseMenuButton exitButton;
private boolean needsConfirmation;
private PlayStateTemplate pausedGame;
private LoadingText loadingText;
private boolean userExited;
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.dimmingTexture = new Texture(Gdx.files.internal("DimmingTexture.png"));
this.pauseCircles = new ArrayList<PauseCircle>();
this.pausedGame = pausedGame;
this.loadingText = new LoadingText();
this.userExited = false;
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);
......@@ -62,10 +68,11 @@ public class PauseState extends State {
this.needsConfirmation = false;
}
// User confirms the exit, posts the current score
// User confirms the exit, this will now render the loading text and then post the
// score and exit
if(this.confirmationBox.yesPressed(touchX, touchY)) {
this.gsm.pop();
this.pausedGame.gameDone();
this.loadingText.setLoading();
this.userExited = true;
}
}
......@@ -75,7 +82,7 @@ public class PauseState extends State {
this.gsm.pop();
}
// First step of exitting; user now needs to confirm the exit via the popup
// First step of exiting; user now needs to confirm the exit via the popup
if(this.exitButton.isPressed(touchX, touchY)){
this.needsConfirmation = true;
}
......@@ -85,6 +92,12 @@ public class PauseState extends State {
@Override
public void update(float dt) {
if(this.userExited && this.loadingText.textIsRendering()){
this.gsm.pop();
this.pausedGame.gameDone();
}
this.loadingText.update(dt);
this.handleInput();
for(PauseCircle pc : this.pauseCircles){
......@@ -133,6 +146,7 @@ public class PauseState extends State {
this.confirmationBox.draw(sb);
}
this.loadingText.draw(sb);
}
@Override
......
......@@ -9,6 +9,7 @@ import com.gameware.game.QueryIntermediate;
import com.gameware.game.models.Round;
import com.gameware.game.models.RoundCheck;
import com.gameware.game.models.Tournament;
import com.gameware.game.sprites.LoadingText;
import com.gameware.game.sprites.PauseButton;
import java.io.IOException;
......@@ -19,8 +20,9 @@ public abstract class PlayStateTemplate extends State {
private Round round = null;
private Tournament tournament = null;
private Round nextRound = null;
protected PauseButton pauseButton;
private PauseButton pauseButton;
private Round updatedRound = null;
private LoadingText loadingText = new LoadingText();
protected float totalGameTime = 30f;
protected Texture screenshot = null;
......@@ -31,10 +33,31 @@ public abstract class PlayStateTemplate extends State {
this.pauseButton = new PauseButton();
}
public void renderPauseButton(SpriteBatch sb){
public void update(float dt){
// Updates the loading text; nothing happens if there is no loading
this.loadingText.update(dt);
// Post score and exit if the game is over and the loading text is rendering
if(this.loadingText.textIsRendering()){
this.gameDone();
return;
}
// Pause the game if the pause button was pressed
if(Gdx.input.justTouched() && this.pauseButton.isPressed(Gdx.input.getX(), Gdx.input.getY())){
this.gsm.push(new PauseState(this.gsm, this));
}
}
public void render(SpriteBatch sb){
this.loadingText.draw(sb);
this.pauseButton.draw(sb);
}
public void setGameFinished(){
this.loadingText.setLoading();
}
public void setRound(Round r){
this.round = r;
}
......@@ -104,13 +127,6 @@ 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();
......@@ -120,5 +136,10 @@ public abstract class PlayStateTemplate extends State {
public void setPauseButtonBlack(){
this.pauseButton.setButtonBlack();
}
public void dispose(){
this.loadingText.dispose();
this.pauseButton.dispose();
}
}
......@@ -19,6 +19,8 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.gameware.game.GameWare;
import com.gameware.game.models.Game;
import com.gameware.game.sprites.LoadingText;
import java.io.IOException;
public class ViewHighScoreState extends State {
......@@ -34,6 +36,10 @@ public class ViewHighScoreState extends State {
private Label stateNameLabel = new Label("High Scores", skin, "big");
private Label secondStateNameLabel = new Label("Select game", skin, "big");
private Game chosenGame = null;
private LoadingText loadingText = new LoadingText();
public ViewHighScoreState(GameStateManager gsm) {
super(gsm);
......@@ -97,6 +103,12 @@ public class ViewHighScoreState extends State {
@Override
public void update(float dt) {
if(this.chosenGame != null && this.loadingText.textIsRendering()){
this.handleGameBtnClick(this.chosenGame);
}
this.loadingText.update(dt);
Gdx.input.setInputProcessor(stage);
Gdx.input.setCatchBackKey(true);
handleInput();
......@@ -106,11 +118,13 @@ public class ViewHighScoreState extends State {
@Override
public void render(SpriteBatch sb) {
stage.draw();
this.loadingText.draw(sb);
}
@Override
public void dispose() {
stage.dispose();
this.loadingText.dispose();
}
@Override
......@@ -128,6 +142,11 @@ public class ViewHighScoreState extends State {
return backBtn;
}
private void setGameBtnClicked(Game game){
this.chosenGame = game;
this.loadingText.setLoading();
}
private void handleBackBtnClick(){
gsm.set(new MenuState(gsm));
}
......@@ -144,8 +163,8 @@ public class ViewHighScoreState extends State {
}
public void clicked(InputEvent event, float x, float y) {
handleGameBtnClick(game);
setGameBtnClicked(game);
};
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment