Commit fa81c572 authored by ivarnm's avatar ivarnm
Browse files

Merge branch 'dev'

parents 7fc78a72 c1000682
package com.gameware.game.sprites;
package com.gameware.game.sprites.colorRushSprites;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Sound;
......@@ -6,8 +6,11 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector3;
import com.gameware.game.GameWare;
import com.gameware.game.sprites.Sprite;
public class ColorRushButton extends Sprite{
// These are the buttons that needs to be pressed according to the matching color of the target in the Color Rush minigame
public class ColorRushButton extends Sprite {
private Texture mainTexture;
private Texture disabledTexture;
private int colorNum;
......
package com.gameware.game.sprites;
package com.gameware.game.sprites.colorRushSprites;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector3;
import com.gameware.game.sprites.Sprite;
public class ColorRushTarget extends Sprite{
// This is the block that you need to press the matching color to remove in the Color Rush minigame
public class ColorRushTarget extends Sprite {
private int nextHeight;
private Vector3 velocity;
private Texture mainTexture;
......
package com.gameware.game.sprites;
package com.gameware.game.sprites.fruitSlicerSprites;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector3;
import com.gameware.game.sprites.Sprite;
// This is the fruit that can be chopped in the Fruit Slicer minigame
public class Fruit extends Sprite {
private Vector3 cutPosition1;
......@@ -131,6 +133,7 @@ public class Fruit extends Sprite {
@Override
public void dispose() {
// Nothing to dispose
}
public boolean isDisposable() {
......
package com.gameware.game.sprites;
package com.gameware.game.sprites.fruitSlicerSprites;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector3;
import com.gameware.game.sprites.Sprite;
// This is the circle trail that are left when slicing in the Fruit Slicer minigame
public class SlicingCircle extends Sprite {
private Texture slicingVFX;
......
package com.gameware.game.sprites;
package com.gameware.game.sprites.pauseStateSprites;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector3;
import com.gameware.game.sprites.Sprite;
// This is the confirmation box when trying to exit a minigame when in the pause state
public class ConfirmationBox extends Sprite {
private Texture boxTexture;
......
package com.gameware.game.sprites;
package com.gameware.game.sprites.pauseStateSprites;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Vector3;
import com.gameware.game.sprites.Sprite;
// These are the animated circles that can be seen in the background of the pause state
public class PauseCircle extends Sprite {
private int radius;
......
package com.gameware.game.sprites;
package com.gameware.game.sprites.pauseStateSprites;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector3;
import com.gameware.game.sprites.Sprite;
// This is the button used for "Resume" and "Exit" in the pause state
public class PauseMenuButton extends Sprite {
private Texture buttonTexture;
......
......@@ -4,15 +4,25 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.gameware.game.GameStateManager;
import com.gameware.game.GameWare;
import com.gameware.game.sprites.ConfirmationBox;
import com.gameware.game.sprites.pauseStateSprites.ConfirmationBox;
import com.gameware.game.sprites.LoadingText;
import com.gameware.game.sprites.PauseCircle;
import com.gameware.game.sprites.PauseMenuButton;
import com.gameware.game.sprites.pauseStateSprites.PauseCircle;
import com.gameware.game.sprites.pauseStateSprites.PauseMenuButton;
import com.gameware.game.states.games.PlayStateUnion;
import java.util.ArrayList;
import java.util.List;
/*
State shown when players pause a game.
Since it is still inside a game, the group wanted it to have a different look than the other menu states.
However it was not a game, so it doesn't extend either the MenuStateUnion or the PlayStateUnion.
It is therefore a bit of a special state, kind of in between the menu states and the game states.
*/
public class PauseState extends State {
// Data
......@@ -33,7 +43,7 @@ public class PauseState extends State {
private boolean needsConfirmation;
// Widgets
private List<PauseCircle> pauseCircles;
private List<PauseCircle> pauseBackgroundCircles;
private ConfirmationBox confirmationBox;
private PauseMenuButton resumeButton;
private PauseMenuButton exitButton;
......@@ -54,7 +64,7 @@ public class PauseState extends State {
this.countdownDurationLeft = 3f;
this.countdownStarted = false;
this.pauseCircles = new ArrayList<PauseCircle>();
this.pauseBackgroundCircles = new ArrayList<PauseCircle>();
this.pausedGame = pausedGame;
this.originalFontColor = new Color(this.pausedGame.getFontColor());
......@@ -76,7 +86,7 @@ public class PauseState extends State {
for(int i = 0; i<25; i++){
this.pauseCircles.add(new PauseCircle());
this.pauseBackgroundCircles.add(new PauseCircle());
}
}
......@@ -137,7 +147,7 @@ public class PauseState extends State {
// If the user has pressed the resume button the countdown has started
if(this.countdownStarted){
this.countdownDurationLeft -= dt;
this.countdownNumberTexture = this.countdownNumbers.get(Math.min(Math.max((int) (this.countdownDurationLeft),0), 3));
this.countdownNumberTexture = this.countdownNumbers.get(Math.min(Math.max((int) (this.countdownDurationLeft),0), 2));
// If the countdown has finished we resume the game
if(this.countdownDurationLeft <= 0){
......@@ -148,7 +158,7 @@ public class PauseState extends State {
}
}
for(PauseCircle pc : this.pauseCircles){
for(PauseCircle pc : this.pauseBackgroundCircles){
pc.update(dt);
}
}
......@@ -164,7 +174,7 @@ public class PauseState extends State {
// Animated circles
for(PauseCircle pc : pauseCircles){
for(PauseCircle pc : pauseBackgroundCircles){
pc.draw(sb);
}
......@@ -204,7 +214,7 @@ public class PauseState extends State {
@Override
public void dispose() {
for(PauseCircle pc : pauseCircles){
for(PauseCircle pc : pauseBackgroundCircles){
pc.dispose();
}
......@@ -222,5 +232,9 @@ public class PauseState extends State {
}
@Override
public void reset() { }
public void reset() {
this.needsConfirmation = false;
this.countdownStarted = false;
this.countdownDurationLeft = 3f;
}
}
......@@ -2,20 +2,27 @@ package com.gameware.game.states;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.gameware.game.GameStateManager;
import com.gameware.game.GameWare;
/*
State is the super class/union of all the states in the application.
A state has their own logic and rendering. State contains common variables between
MenuStateUnion and PlayStateUnion. All states must have their own update method.
Patterns: State, Union Design, Update method
*/
public abstract class State {
// Common variables between MenuStateUnion and PlayStateUnion
// Data
protected GameStateManager gsm;
protected Stage stage = new Stage();
protected final OrthographicCamera cam = new OrthographicCamera();
protected final Skin skin = new Skin(Gdx.files.internal(GameWare.skinFilePath));
// Sound effects
......@@ -23,13 +30,9 @@ public abstract class State {
protected Sound pauseResumeBtnSound;
protected Sound pauseStateBtnSound;
// Variables
protected boolean firstTimeRunningUpdate = true;
protected State(GameStateManager gsm){
this.gsm = gsm;
cam.setToOrtho(false, Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2);
// Add sound effects
this.buttonPressSound = Gdx.audio.newSound(Gdx.files.internal("sfx/button_press.ogg"));
......@@ -43,6 +46,7 @@ public abstract class State {
// Abstract state methods
protected abstract void handleInput();
// Requires all states to have the update method
public abstract void update(float dt);
public abstract void render(SpriteBatch sb);
......
package com.gameware.game.states;
package com.gameware.game.states.games;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.gameware.game.sprites.Bubble;
import com.gameware.game.sprites.bubbleWrapSprites.Bubble;
import com.gameware.game.GameStateManager;
import java.util.ArrayList;
......@@ -27,9 +28,9 @@ public class BubbleWrapState extends PlayStateUnion {
public BubbleWrapState(GameStateManager gsm) {
super(gsm);
super.setPauseButtonWhite();
super.setTotalGameTime(20f);
super.setTotalTimeLimit(20f);
super.setFontColorWhite();
super.screenshot = new Texture(Gdx.files.internal("gameTextures/BubbleWrap/bubbleWrapPhotoEdit.png"));
super.setThumbnail(new Texture(Gdx.files.internal("gameTextures/BubbleWrap/bubbleWrapPhotoEdit.png")));
background = new Texture(Gdx.files.internal("gameTextures/BubbleWrap/bubblewrap_background.jpg"));
unpopped = new Texture(Gdx.files.internal("gameTextures/BubbleWrap/bubble_unpopped_1.png"));
......@@ -61,7 +62,7 @@ public class BubbleWrapState extends PlayStateUnion {
// Keeps score consistent
// One point per bubble popped, plus three points for each second of remaining time. Time bonus is only given if the player pops all the bubbles.
if(this.poppedBubbles == this.bubbles.size()){
score = this.poppedBubbles + Math.max(Math.round((super.getTotalGameTime() - super.getCurrentDuration())*3), 0);
score = this.poppedBubbles + Math.max(Math.round((super.getTotalTimeLimit() - super.getCurrentDuration())*3), 0);
}
else{
score = this.poppedBubbles;
......
package com.gameware.game.states;
package com.gameware.game.states.games;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.gameware.game.sprites.ColorRushButton;
import com.gameware.game.sprites.ColorRushTarget;
import com.gameware.game.sprites.colorRushSprites.ColorRushButton;
import com.gameware.game.sprites.colorRushSprites.ColorRushTarget;
import com.gameware.game.GameStateManager;
import java.util.ArrayList;
import java.util.Collections;
......@@ -25,8 +26,8 @@ public class ColorRushState extends PlayStateUnion {
public ColorRushState(GameStateManager gsm){
super(gsm);
super.screenshot = new Texture(Gdx.files.internal("gameTextures/ColorRush/colorRushPhotoEdit.png"));
super.setTotalGameTime(30f);
super.setThumbnail(new Texture(Gdx.files.internal("gameTextures/ColorRush/colorRushPhotoEdit.png")));
super.setTotalTimeLimit(30f);
// Creates the background
this.background = new Texture(Gdx.files.internal("gameTextures/ColorRush/ColorRushBackground.jpg"));
......
package com.gameware.game.states;
package com.gameware.game.states.games;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Sound;
......@@ -6,8 +6,9 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector3;
import com.gameware.game.GameWare;
import com.gameware.game.sprites.Fruit;
import com.gameware.game.sprites.SlicingCircle;
import com.gameware.game.sprites.fruitSlicerSprites.Fruit;
import com.gameware.game.sprites.fruitSlicerSprites.SlicingCircle;
import com.gameware.game.GameStateManager;
import java.util.ArrayList;
import java.util.List;
......@@ -32,8 +33,10 @@ public class FruitSlicerState extends PlayStateUnion {
public FruitSlicerState(GameStateManager gsm) {
super(gsm);
super.setTotalGameTime(60f);
super.screenshot = new Texture(Gdx.files.internal("gameTextures/FruitSlicer/FruitSlicerPhotoEdit.png"));
super.setTotalTimeLimit(45f);
super.setThumbnail(new Texture(Gdx.files.internal("gameTextures/FruitSlicer/FruitSlicerPhotoEdit.png")));
super.setFontColorWhite();
super.setPauseButtonWhite();
this.sliceWhooshSound = Gdx.audio.newSound(Gdx.files.internal("sfx/FruitSlicerWhooshSound.mp3"));
this.sliceSquishSound = Gdx.audio.newSound(Gdx.files.internal("sfx/FruitSlicerSquishSound.mp3"));
......@@ -77,6 +80,12 @@ public class FruitSlicerState extends PlayStateUnion {
this.oldTouchPosition.x = touchX;
this.oldTouchPosition.y = touchY;
}
// Adds new slicing circles if the user is touching
if(Gdx.input.isTouched()) {
this.slicingCircles.add(new SlicingCircle(Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY(), this.slicingCircleVFX));
}
}
@Override
......@@ -86,11 +95,6 @@ public class FruitSlicerState extends PlayStateUnion {
this.handleInput();
// Adds new slicing circles if the user is touching
if(Gdx.input.isTouched()) {
this.slicingCircles.add(new SlicingCircle(Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY(), this.slicingCircleVFX));
}
// Updates the slicing circles
for(SlicingCircle slicingCircle : this.slicingCircles){
slicingCircle.update(dt);
......@@ -104,7 +108,7 @@ public class FruitSlicerState extends PlayStateUnion {
this.timeSinceLastEmit += dt;
// Increases the emiting frequency towards the endingEmitFrequency as the game gets closer to the end
float currentFrequency = (float) (this.startingEmitFrequency - (this.startingEmitFrequency - this.endingEmitFrequency) * Math.min(super.getCurrentDuration() / (super.getTotalGameTime() * 0.6), 1));
float currentFrequency = (float) (this.startingEmitFrequency - (this.startingEmitFrequency - this.endingEmitFrequency) * Math.min(super.getCurrentDuration() / (super.getTotalTimeLimit() * 0.6), 1));
// Emits a new fruit
if(this.timeSinceLastEmit > currentFrequency){
......@@ -164,7 +168,7 @@ public class FruitSlicerState extends PlayStateUnion {
// Four different emit modes: from left, from right, from entire bottom, and from bottom center with different velocity angles
int emitMode = (int) (Math.random() * 4);
Fruit fruit;
Texture fruitTexture = this.fruitTextures.get((int) (Math.random() * 20));
Texture fruitTexture = this.fruitTextures.get((int) (Math.random() * this.fruitTextures.size()));
Vector3 velocity = new Vector3(Gdx.graphics.getWidth() * 3 / 4, 0, 0);
int x, y, emitAngle;
......
package com.gameware.game.states;
package com.gameware.game.states.games;
import com.badlogic.gdx.Gdx;
......@@ -14,17 +14,28 @@ 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 com.gameware.game.states.FinishedTournamentState;
import com.gameware.game.states.GameStateManager;
import com.gameware.game.states.menus.FinishedTournamentState;
import com.gameware.game.GameStateManager;
import com.gameware.game.states.PauseState;
import com.gameware.game.states.ScoreState;
import com.gameware.game.states.SinglePlayerSelectGameState;
import com.gameware.game.states.menus.ScoreState;
import com.gameware.game.states.menus.SinglePlayerSelectGameState;
import com.gameware.game.states.State;
import com.gameware.game.states.ViewTournamentState;
import com.gameware.game.states.menus.ViewTournamentState;
import java.io.IOException;
import java.util.List;
/*
The PlayStateUnion class is the Union of all game states.
If you are going to create a game, it has to extend this class. It has necessary variables
and methods, such as the gameDone() method which changes to the correct menu state.
Has the reset method abstract because all games must have a reset method, however it will
be different for each game.
Patterns: Union Design, (State)
*/
public abstract class PlayStateUnion extends State {
......@@ -36,11 +47,11 @@ public abstract class PlayStateUnion extends State {
// Game values
private int score;
protected float totalGameTime = 0f;
protected float totalTimeLimit = 0f;
protected float currentDuration = 0f;
// Game objects
protected Texture screenshot = null;
private Texture thumbnail = new Texture(Gdx.files.internal("gameTextures/placeholderThumbnail.png"));
private PauseButton pauseButton;
private LoadingText loadingText = new LoadingText();
private BitmapFont font;
......@@ -60,7 +71,7 @@ public abstract class PlayStateUnion extends State {
// Default font (black color)
font = new BitmapFont();
font.setColor(Color.BLACK);
font.getData().setScale((float) (Gdx.graphics.getWidth()/GameWare.WIDTH*1.75));
font.getData().setScale((float) (Gdx.graphics.getWidth()/GameWare.WIDTH*2.5));
}
// Override methods
......@@ -79,13 +90,13 @@ public abstract class PlayStateUnion extends State {
this.loadingText.update(dt);
// If the game has a total game time (if the game is time-based)
if(this.totalGameTime > 0f) {
if(this.totalTimeLimit > 0f) {
// Increases the current duration, used to keep track of the play duration and stop the game
// after a while
this.currentDuration += dt;
// Set score and start rendering the loading text if the game is over
if (this.currentDuration > this.totalGameTime) {
if (this.currentDuration > this.totalTimeLimit) {
this.setGameFinished();
return;
}
......@@ -116,24 +127,26 @@ public abstract class PlayStateUnion extends State {
this.loadingText.dispose();
this.pauseButton.dispose();
this.font.dispose();
this.thumbnail.dispose();
}
@Override
public void reset(){}
public abstract void reset();
// Renders the text - This is used by this class' render method as well as by the PauseState
public void renderText(SpriteBatch sb){
// Shows the current duration if it's supposed to be visible and the game is time-based
if(this.timeLeftVisible && this.totalGameTime > 0f) {
if(this.timeLeftVisible && this.totalTimeLimit > 0f) {
sb.begin();
// Time left
this.font.draw(sb, "Time: " + String.valueOf(Math.max(Math.round((this.totalGameTime - this.currentDuration) * 100), 0.00) / 100.0), Gdx.graphics.getWidth() / 40, Gdx.graphics.getHeight() - Gdx.graphics.getHeight() / 40 - Gdx.graphics.getHeight() / 60);
this.font.draw(sb, "Time: " + String.valueOf(Math.max(Math.round((this.totalTimeLimit - this.currentDuration) * 100), 0.00) / 100.0), Gdx.graphics.getWidth() / 40, Gdx.graphics.getHeight() - Gdx.graphics.getHeight() / 20);
sb.end();
}
if(this.currentScoreVisible){
sb.begin();
//Score
this.font.draw(sb, "Score: " + String.valueOf(this.score), Gdx.graphics.getWidth() / 40, Gdx.graphics.getHeight() - Gdx.graphics.getHeight() / 100);
sb.end();
......@@ -241,14 +254,19 @@ public abstract class PlayStateUnion extends State {
this.font.setColor(color);
}
public void setTotalGameTime(float totalGameTime){
this.totalGameTime = totalGameTime;
public void setTotalTimeLimit(float totalTimeLimit){
this.totalTimeLimit = totalTimeLimit;
}
public void setCurrentDuration(float currentDuration){
this.currentDuration = currentDuration;
}
public void setThumbnail(Texture thumbnailTexture){
this.thumbnail.dispose();
this.thumbnail = thumbnailTexture;
}
// Getters
public Color getFontColor(){
return this.font.getColor();
......@@ -258,12 +276,12 @@ public abstract class PlayStateUnion extends State {
return this.currentDuration;
}
public float getTotalGameTime(){
return this.totalGameTime;
public float getTotalTimeLimit(){
return this.totalTimeLimit;
}
public Texture getScreenshot(){
return screenshot;
public Texture getThumbnail(){
return thumbnail;
}
// Hide and show methods:
......
package com.gameware.game.states;
package com.gameware.game.states.menus;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
......@@ -21,11 +21,21 @@ import com.gameware.game.models.Alert;
import com.gameware.game.models.Round;
import com.gameware.game.models.Tournament;
import com.gameware.game.sprites.LoadingText;
import com.gameware.game.GameStateManager;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/*
State where players can view, join and enter tournaments, or go to the create new state.
Patterns: Publish-Subscribe, Delegation
Publish-Subscribe and delegation is used on the buttons. Where P-S is used by utilizing
click listeners and delegation is used by the button to delegate what happens to this state.
*/
public class CreateJoinTournamentState extends MenuStateUnion {
// Data
......
package com.gameware.game.states;
package com.gameware.game.states.menus;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
......@@ -22,11 +22,22 @@ import com.gameware.game.models.Game;
import com.gameware.game.models.Round;
import com.gameware.game.models.Tournament;
import com.gameware.game.sprites.LoadingText;