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

Almost completes issue #73

parent 382cc8e7
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
android:theme="@style/GdxTheme" > android:theme="@style/GdxTheme" >
<activity <activity
android:name="com.gameware.game.AndroidLauncher" android:name="com.gameware.game.AndroidLauncher"
android:label="@string/app_name" android:label="@string/app_name"
android:screenOrientation="portrait" android:screenOrientation="portrait"
android:configChanges="keyboard|keyboardHidden|navigation|orientation|screenSize|screenLayout"> android:configChanges="keyboard|keyboardHidden|navigation|orientation|screenSize|screenLayout">
<intent-filter> <intent-filter>
......
...@@ -70,6 +70,7 @@ public class GameWare extends ApplicationAdapter { ...@@ -70,6 +70,7 @@ public class GameWare extends ApplicationAdapter {
music.setVolume(0.1f); music.setVolume(0.1f);
toggleMusic(); toggleMusic();
//gsm.push(new LoginState(gsm));
gsm.push(new LoginState(gsm)); gsm.push(new LoginState(gsm));
// try{ // 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 { ...@@ -82,20 +82,19 @@ public class BubbleWrapState extends PlayStateTemplate {
// Keeps score consistent // Keeps score consistent
this.setScore(this.poppedBubbles); this.setScore(this.poppedBubbles);
// Checks if the pause button was pressed
super.checkPause();
} }
} }
@Override @Override
public void update(float dt) { public void update(float dt) {
super.update(dt);
Gdx.input.setInputProcessor(stage); Gdx.input.setInputProcessor(stage);
this.handleInput(); this.handleInput();
this.currentTime += dt; 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 // Game should finish if the time has run out
if (this.currentTime >= this.totalTime) { if (this.currentTime >= this.totalTime) {
...@@ -116,9 +115,7 @@ public class BubbleWrapState extends PlayStateTemplate { ...@@ -116,9 +115,7 @@ public class BubbleWrapState extends PlayStateTemplate {
public void render(SpriteBatch sb) { public void render(SpriteBatch sb) {
stage.draw(); stage.draw();
// Renders pause button super.render(sb);
super.renderPauseButton(sb);
} }
private void createBubbles() { private void createBubbles() {
...@@ -163,18 +160,19 @@ public class BubbleWrapState extends PlayStateTemplate { ...@@ -163,18 +160,19 @@ public class BubbleWrapState extends PlayStateTemplate {
private void handleFinishedGame() { private void handleFinishedGame() {
System.out.println("Game finished, starting new state"); System.out.println("Game finished, starting new state");
this.setScore(this.poppedBubbles); this.setScore(this.poppedBubbles);
this.gameDone(); super.setGameFinished();
return; return;
} }
@Override @Override
public void dispose() { public void dispose() {
super.dispose();
stage.dispose(); stage.dispose();
this.unpopped.dispose(); this.unpopped.dispose();
this.popped1.dispose(); this.popped1.dispose();
this.popped2.dispose(); this.popped2.dispose();
this.popped3.dispose(); this.popped3.dispose();
super.pauseButton.dispose();
} }
@Override @Override
......
...@@ -7,7 +7,6 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch; ...@@ -7,7 +7,6 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.gameware.game.GameWare; import com.gameware.game.GameWare;
import com.gameware.game.sprites.ColorRushButton; import com.gameware.game.sprites.ColorRushButton;
import com.gameware.game.sprites.ColorRushTarget; import com.gameware.game.sprites.ColorRushTarget;
import com.gameware.game.sprites.PauseButton;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
...@@ -103,23 +102,21 @@ public class ColorRushState extends PlayStateTemplate { ...@@ -103,23 +102,21 @@ public class ColorRushState extends PlayStateTemplate {
// Keeps score consistent // Keeps score consistent
this.setScore(this.targetsHit); this.setScore(this.targetsHit);
//Pauses the game if the user pressed the pause button
super.checkPause();
} }
} }
@Override @Override
public void update(float dt) { public void update(float dt) {
super.update(dt);
// Increases the current duration, used to keep track of the play duration and stop the game // Increases the current duration, used to keep track of the play duration and stop the game
// after a while // after a while
this.currentDuration += dt; 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){ if(this.currentDuration > this.totalGameDuration){
this.setScore(this.targetsHit); this.setScore(this.targetsHit);
this.gameDone(); this.setGameFinished();
return; return;
} }
...@@ -171,14 +168,10 @@ public class ColorRushState extends PlayStateTemplate { ...@@ -171,14 +168,10 @@ public class ColorRushState extends PlayStateTemplate {
sb.draw(this.background, 0, Gdx.graphics.getHeight()/5, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); sb.draw(this.background, 0, Gdx.graphics.getHeight()/5, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
// Time left // 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(); sb.end();
// Renders pause button
super.renderPauseButton(sb);
for (ColorRushButton button : this.buttons) { for (ColorRushButton button : this.buttons) {
button.draw(sb); button.draw(sb);
} }
...@@ -191,11 +184,13 @@ public class ColorRushState extends PlayStateTemplate { ...@@ -191,11 +184,13 @@ public class ColorRushState extends PlayStateTemplate {
target.draw(sb); target.draw(sb);
} }
super.render(sb);
} }
@Override @Override
public void dispose() { public void dispose() {
super.dispose();
for (ColorRushButton button : this.buttons) { for (ColorRushButton button : this.buttons) {
button.dispose(); button.dispose();
} }
...@@ -215,7 +210,6 @@ public class ColorRushState extends PlayStateTemplate { ...@@ -215,7 +210,6 @@ 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
......
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.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener; import com.badlogic.gdx.scenes.scene2d.InputListener;
...@@ -12,6 +13,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; ...@@ -12,6 +13,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
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.Player; import com.gameware.game.models.Player;
import com.gameware.game.sprites.LoadingText;
import java.io.IOException; import java.io.IOException;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
...@@ -39,6 +41,12 @@ public class LoginState extends State { ...@@ -39,6 +41,12 @@ public class LoginState extends State {
private String takenUsernameText = "Username already taken"; private String takenUsernameText = "Username already taken";
private String ioExceptionText = "Something went wrong with query"; 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) { public LoginState(GameStateManager gsm) {
super(gsm); super(gsm);
makeStage(); makeStage();
...@@ -82,7 +90,7 @@ public class LoginState extends State { ...@@ -82,7 +90,7 @@ public class LoginState extends State {
loginBtn.addListener(new ClickListener() { loginBtn.addListener(new ClickListener() {
@Override @Override
public void clicked(InputEvent e, float x, float y){ public void clicked(InputEvent e, float x, float y){
handleLoginBtnClick(); setLoginBtnClicked();
} }
}); });
return loginBtn; return loginBtn;
...@@ -93,7 +101,7 @@ public class LoginState extends State { ...@@ -93,7 +101,7 @@ public class LoginState extends State {
signUpBtn.addListener(new ClickListener() { signUpBtn.addListener(new ClickListener() {
@Override @Override
public void clicked(InputEvent e, float x, float y){ public void clicked(InputEvent e, float x, float y){
handleSignUpBtnClick(); setSignUpBtnClicked();
} }
}); });
return signUpBtn; return signUpBtn;
...@@ -142,11 +150,23 @@ public class LoginState extends State { ...@@ -142,11 +150,23 @@ public class LoginState extends State {
@Override @Override
public void update(float dt) { public void update(float dt) {
stage.act(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 @Override
public void render(SpriteBatch sb) { public void render(SpriteBatch sb) {
stage.draw(); stage.draw();
this.loadingText.draw(sb);
} }
@Override @Override
...@@ -160,6 +180,16 @@ public class LoginState extends State { ...@@ -160,6 +180,16 @@ public class LoginState extends State {
passwordInputField.setText(passwordInputText); passwordInputField.setText(passwordInputText);
} }
private void setLoginBtnClicked(){
this.loginBtnClicked = true;
this.loadingText.setLoading();
}
private void setSignUpBtnClicked(){
this.signUpBtnClicked = true;
this.loadingText.setLoading();
}
private void handleLoginBtnClick(){ private void handleLoginBtnClick(){
String username = usernameInputField.getText(); String username = usernameInputField.getText();
String password = passwordInputField.getText(); String password = passwordInputField.getText();
...@@ -180,6 +210,8 @@ public class LoginState extends State { ...@@ -180,6 +210,8 @@ public class LoginState extends State {
System.out.println(e); System.out.println(e);
errorLabel.setText(e.getMessage()); errorLabel.setText(e.getMessage());
} }
this.loginBtnClicked = false;
} }
private void handleSignUpBtnClick(){ private void handleSignUpBtnClick(){
...@@ -202,5 +234,7 @@ public class LoginState extends State { ...@@ -202,5 +234,7 @@ public class LoginState extends State {
System.out.println(e); System.out.println(e);
errorLabel.setText(e.getMessage()); errorLabel.setText(e.getMessage());
} }
this.signUpBtnClicked = false;
} }
} }
...@@ -9,6 +9,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table; ...@@ -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.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.gameware.game.GameWare; import com.gameware.game.GameWare;
import com.gameware.game.sprites.LoadingText;
public class MenuState extends State{ public class MenuState extends State{
...@@ -23,6 +24,10 @@ public class MenuState extends State{ ...@@ -23,6 +24,10 @@ public class MenuState extends State{
private String optionBtnText = "Options"; private String optionBtnText = "Options";
private String logOutBtnText = "Log out"; private String logOutBtnText = "Log out";
private boolean multiBtnClicked = false;
private LoadingText loadingText = new LoadingText();
public MenuState(GameStateManager gsm) { public MenuState(GameStateManager gsm) {
super(gsm); super(gsm);
makeStage(); makeStage();
...@@ -66,7 +71,7 @@ public class MenuState extends State{ ...@@ -66,7 +71,7 @@ public class MenuState extends State{
TextButton multiPlayerBtn = new TextButton(multiPlayerBtnText, skin); TextButton multiPlayerBtn = new TextButton(multiPlayerBtnText, skin);
multiPlayerBtn.addListener(new ClickListener() { multiPlayerBtn.addListener(new ClickListener() {
@Override @Override
public void clicked(InputEvent e, float x, float y){ handleMultiBtnClick(); } public void clicked(InputEvent e, float x, float y){ setMultiBtnClicked(); }
}); });
return multiPlayerBtn; return multiPlayerBtn;
} }
...@@ -110,6 +115,11 @@ public class MenuState extends State{ ...@@ -110,6 +115,11 @@ public class MenuState extends State{
@Override @Override
public void update(float dt) { public void update(float dt) {
if(this.multiBtnClicked && this.loadingText.textIsRendering()){
this.handleMultiBtnClick();
}
this.loadingText.update(dt);
Gdx.input.setInputProcessor(stage); Gdx.input.setInputProcessor(stage);
Gdx.input.setCatchBackKey(true); Gdx.input.setCatchBackKey(true);
handleInput(); handleInput();
...@@ -117,7 +127,10 @@ public class MenuState extends State{ ...@@ -117,7 +127,10 @@ public class MenuState extends State{
} }
@Override @Override
public void render(SpriteBatch sb) { stage.draw(); } public void render(SpriteBatch sb) {
stage.draw();
this.loadingText.draw(sb);
}
@Override @Override
public void dispose() { stage.dispose(); } public void dispose() { stage.dispose(); }
...@@ -125,6 +138,11 @@ public class MenuState extends State{ ...@@ -125,6 +138,11 @@ public class MenuState extends State{
@Override @Override
public void reset() { } public void reset() { }
private void setMultiBtnClicked(){
this.multiBtnClicked = true;
this.loadingText.setLoading();
}
private void handleOptionsBtnClick(){ private void handleOptionsBtnClick(){
gsm.set(new OptionsState(gsm)); gsm.set(new OptionsState(gsm));
} }
......
...@@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.Texture; ...@@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.gameware.game.sprites.ConfirmationBox; import com.gameware.game.sprites.ConfirmationBox;
import com.gameware.game.sprites.LoadingText;
import com.gameware.game.sprites.PauseCircle; import com.gameware.game.sprites.PauseCircle;
import com.gameware.game.sprites.PauseMenuButton; import com.gameware.game.sprites.PauseMenuButton;
...@@ -22,18 +23,23 @@ public class PauseState extends State { ...@@ -22,18 +23,23 @@ public class PauseState extends State {
private PauseMenuButton exitButton; private PauseMenuButton exitButton;
private boolean needsConfirmation; private boolean needsConfirmation;
private PlayStateTemplate pausedGame; private PlayStateTemplate pausedGame;
private LoadingText loadingText;
private boolean userExited;
public PauseState(GameStateManager gsm, 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.dimmingTexture = new Texture(Gdx.files.internal("DimmingTexture.png"));
this.pauseCircles = new ArrayList<PauseCircle>(); this.pauseCircles = new ArrayList<PauseCircle>();
this.pausedGame = pausedGame; this.pausedGame = pausedGame;
this.loadingText = new LoadingText();
this.userExited = false;
int confirmationBoxWidth = Gdx.graphics.getWidth()*7/8; int confirmationBoxWidth = Gdx.graphics.getWidth()*7/8;
int confirmationBoxHeight = confirmationBoxWidth/2; int confirmationBoxHeight = confirmationBoxWidth/2;
this.confirmationBox = new ConfirmationBox(Gdx.graphics.getWidth()/2 - confirmationBoxWidth/2, Gdx.graphics.getHeight()/2 - confirmationBoxHeight/2, confirmationBoxWidth, confirmationBoxHeight); 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 { ...@@ -62,10 +68,11 @@ public class PauseState extends State {
this.needsConfirmation = false; 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)) {