diff --git a/frontend/android/assets/glassy/raw/BlueSquare.png b/frontend/android/assets/glassy/raw/BlueSquare.png index 954f7ad891a7f800076c7d70f74e821caa5dbcd9..47aa4929374bb493a5511e443716d95db0eb607f 100644 Binary files a/frontend/android/assets/glassy/raw/BlueSquare.png and b/frontend/android/assets/glassy/raw/BlueSquare.png differ diff --git a/frontend/android/assets/glassy/raw/PauseBackground.jpg b/frontend/android/assets/glassy/raw/PauseBackground.jpg new file mode 100644 index 0000000000000000000000000000000000000000..0b6369540e6c00d01ab3e7d8072bc517cdb3c70f Binary files /dev/null and b/frontend/android/assets/glassy/raw/PauseBackground.jpg differ diff --git a/frontend/android/assets/glassy/raw/PauseButton.png b/frontend/android/assets/glassy/raw/PauseButton.png new file mode 100644 index 0000000000000000000000000000000000000000..4dd21e886fb3e020df9baed66438a53759823cb6 Binary files /dev/null and b/frontend/android/assets/glassy/raw/PauseButton.png differ diff --git a/frontend/core/src/com/gameware/game/sprites/ColorRushButton.java b/frontend/core/src/com/gameware/game/sprites/ColorRushButton.java new file mode 100644 index 0000000000000000000000000000000000000000..0a0f61e4ef1aecde49330a4dcde8d5f73115e1ba --- /dev/null +++ b/frontend/core/src/com/gameware/game/sprites/ColorRushButton.java @@ -0,0 +1,94 @@ +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.graphics.glutils.ShapeRenderer; +import com.badlogic.gdx.math.Vector3; + +public class ColorRushButton extends Sprite{ + private int width; + private int height; + private Vector3 position; + private Texture mainTexture; + private Texture disabledTexture; + private int colorNum; + private boolean disabled; + + public ColorRushButton(int x, int y, int width, int height, Texture mainTexture, Texture disabledTexture, int colorNum){ + this.position = new Vector3(x, y, 0); + this.width = width; + this.height = height; + this.mainTexture = mainTexture; + this.disabledTexture = disabledTexture; + this.colorNum = colorNum; + this.disabled = false; + } + + @Override + public void reset() { + + } + + @Override + public Object report() { + return null; + } + + @Override + public void draw(SpriteBatch sb) { + + Texture drawnTexture = this.mainTexture; + + sb.begin(); + + if(this.disabled){ + drawnTexture = this.disabledTexture; + } + + sb.draw(drawnTexture, this.position.x, this.position.y, this.width, this.height); + + sb.end(); + } + + @Override + public void update(float dt) { + position.x = (int) Math.round(position.x); + position.y = (int) Math.round(position.y); + } + + @Override + public void dispose() { + // Textures are shared so they should not be disposed + } + + public boolean isPressed(int x, int y){ + return x > this.position.x && x < (this.position.x + this.width) && (Gdx.graphics.getHeight() - y) > this.position.y && (Gdx.graphics.getHeight() - y) < (this.position.y + this.height); + } + + public int getColorNum(){ + return this.colorNum; + } + + // Effectively sets the color to grey + public void setDisabledColor(){ + this.disabled = true; + } + + // Effectively removes the grey color and sets the color to the main color + public void setEnabledColor(){ + this.disabled = false; + } + + public Vector3 getPosition(){ + return this.position; + } + + public int getHeight(){ + return this.height; + } + + public int getWidth(){ + return this.width; + } +} diff --git a/frontend/core/src/com/gameware/game/sprites/ColorRushTarget.java b/frontend/core/src/com/gameware/game/sprites/ColorRushTarget.java new file mode 100644 index 0000000000000000000000000000000000000000..bc145c639ec89915d806df26c4112f468804694e --- /dev/null +++ b/frontend/core/src/com/gameware/game/sprites/ColorRushTarget.java @@ -0,0 +1,128 @@ +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 ColorRushTarget extends Sprite{ + private int width; + private int height; + private int nextHeight; + private Vector3 position; + private Vector3 velocity; + private Texture mainTexture; + private int colorNum; + private float disposeOffsetTime; + private boolean disposalStarted; + private boolean disposeAnimLeft; + + public ColorRushTarget(int x, int y, int width, int height, Texture mainTexture, int colorNum, boolean disposeAnimLeft){ + this.position = new Vector3(x, y, 0); + this.nextHeight = y + height; + this.velocity = new Vector3(0, (int) (-Gdx.graphics.getHeight()*0.2), 0); + this.width = width; + this.height = height; + this.mainTexture = mainTexture; + this.colorNum = colorNum; + this.disposeOffsetTime = 0f; + this.disposalStarted = false; + this.disposeAnimLeft = disposeAnimLeft; + } + + @Override + public void reset() { + + } + + @Override + public Object report() { + return null; + } + + @Override + public void draw(SpriteBatch sb) { + sb.begin(); + + sb.draw(this.mainTexture, this.position.x, this.position.y, this.width, this.height); + + sb.end(); + } + + @Override + public void update(float dt) { + + // moves the target-rectangles downwards if the user successfully hit a target + if((this.nextHeight - this.position.y) <= this.height) { + this.velocity.scl(dt); + this.position.add(0, velocity.y, 0); + this.velocity.scl(1 / dt); + } + + + // Moves the targets to the side if it has been hit (i.e. disposalStarted = true) + if(this.disposalStarted){ + this.velocity.scl(dt); + this.position.add(velocity.x, velocity.y, 0); + this.velocity.scl(1 / dt); + + // Increments the dispose offset time + this.disposeOffsetTime += dt; + } + + + // Rounds the position to an integer + position.x = (int) Math.floor(position.x); + position.y = (int) Math.floor(position.y); + } + + @Override + public void dispose() { + // Textures are shared so they should not be disposed + } + + // Moves the target downwards, used for when the user hits a target and all other targets + // should move down + public void makeMove(){ + + // Effectively sets where the target "should" be one target-height down + this.nextHeight -= this.height; + } + + public boolean isPressed(int x, int y){ + return x > this.position.x && x < (this.position.x + this.width) && (Gdx.graphics.getHeight() - y) > this.position.y && (Gdx.graphics.getHeight() - y) < (this.position.y + this.height); + } + + public void startDisposal(){ + this.velocity.x = this.disposeAnimLeft ? -Gdx.graphics.getWidth()*2 : Gdx.graphics.getWidth()*2; + this.disposalStarted = true; + } + + public int getColorNum(){ + return this.colorNum; + } + + public Vector3 getPosition(){ + return this.position; + } + + public int getHeight(){ + return this.height; + } + + public int getWidth(){ + return this.width; + } + + public void setNextHeight(int nextHeight){ + this.nextHeight = nextHeight; + } + + public int getNextHeight(){ + return this.nextHeight; + } + + public boolean shouldDispose(){ + return this.disposeOffsetTime > 1; + } +} diff --git a/frontend/core/src/com/gameware/game/sprites/PauseButton.java b/frontend/core/src/com/gameware/game/sprites/PauseButton.java new file mode 100644 index 0000000000000000000000000000000000000000..1d8991b8c920c69ad82035f3a2bf96aeff22ee25 --- /dev/null +++ b/frontend/core/src/com/gameware/game/sprites/PauseButton.java @@ -0,0 +1,61 @@ +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 PauseButton extends Sprite { + private int width; + private int height; + private Vector3 position; + private Texture mainTexture; + + + // Customizable constructor + public PauseButton(int x, int y, int width, int height){ + this.position = new Vector3(x, y, 0); + this.width = width; + this.height = height; + + this.mainTexture = new Texture(Gdx.files.internal("glassy/raw/PauseButton.png")); + } + + // Constructor with default settings + public PauseButton(){ + this(Gdx.graphics.getWidth() - Gdx.graphics.getWidth()/8,Gdx.graphics.getHeight() - Gdx.graphics.getHeight()/13,50,50); + } + + + @Override + public void reset() { + + } + + @Override + public Object report() { + return null; + } + + @Override + public void draw(SpriteBatch sb) { + sb.begin(); + + sb.draw(this.mainTexture, this.position.x, this.position.y, this.width, this.height); + + sb.end(); + } + + @Override + public void update(float dt) { + } + + @Override + public void dispose() { + this.mainTexture.dispose(); + } + + public boolean isPressed(int x, int y){ + return x > this.position.x && x < (this.position.x + this.width) && (Gdx.graphics.getHeight() - y) > this.position.y && (Gdx.graphics.getHeight() - y) < (this.position.y + this.height); + } +} diff --git a/frontend/core/src/com/gameware/game/sprites/PauseCircle.java b/frontend/core/src/com/gameware/game/sprites/PauseCircle.java new file mode 100644 index 0000000000000000000000000000000000000000..0b982ab6c96b07cad271849a23650bb0106bb100 --- /dev/null +++ b/frontend/core/src/com/gameware/game/sprites/PauseCircle.java @@ -0,0 +1,78 @@ +package com.gameware.game.sprites; + +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; + +public class PauseCircle extends Sprite { + private int radius; + private Vector3 position; + private Vector3 velocity; + private ShapeRenderer sr; + + public PauseCircle(){ + this.position = new Vector3(); + this.velocity = new Vector3(); + + this.sr = new ShapeRenderer(); + this.sr.setColor(new Color().set((float) (Math.random()), (float)(Math.random()), (float) (Math.random()),1)); + + this.radius = (int) (Math.random() * Gdx.graphics.getWidth() * 0.1); + + this.velocity.x = (int) ((0.5 - Math.random()) * Gdx.graphics.getWidth() * 0.3); + this.velocity.y = (int) ((0.5 - Math.random()) * Gdx.graphics.getHeight() * 0.3); + this.position.x = (int) (Math.random() * (Gdx.graphics.getWidth() - this.radius*2) + this.radius); + this.position.y = (int) (Math.random() * (Gdx.graphics.getHeight() - this.radius*2) + this.radius); + } + + @Override + public void reset() { + + } + + @Override + public Object report() { + return null; + } + + @Override + public void draw(SpriteBatch sb) { + this.sr.begin(ShapeRenderer.ShapeType.Filled); + + this.sr.circle(this.position.x, this.position.y, this.radius); + + this.sr.end(); + } + + @Override + public void update(float dt) { + this.velocity.scl(dt); + this.position.add(velocity.x, velocity.y, 0); + this.velocity.scl(1 / dt); + + + // Bounces off the edges + if((this.position.x + this.radius) > Gdx.graphics.getWidth()){ + this.velocity.x = -Math.abs(this.velocity.x); + } + + if((this.position.x - this.radius) < 0){ + this.velocity.x = Math.abs(this.velocity.x); + } + + if((this.position.y + this.radius) > Gdx.graphics.getHeight()){ + this.velocity.y = -Math.abs(this.velocity.y); + } + + if((this.position.y - this.radius) < 0){ + this.velocity.y = Math.abs(this.velocity.y); + } + } + + @Override + public void dispose() { + this.sr.dispose(); + } +} diff --git a/frontend/core/src/com/gameware/game/sprites/RectangleColorRush.java b/frontend/core/src/com/gameware/game/sprites/RectangleColorRush.java deleted file mode 100644 index ffc078cb294e0af026dab305fc0ae1498340c241..0000000000000000000000000000000000000000 --- a/frontend/core/src/com/gameware/game/sprites/RectangleColorRush.java +++ /dev/null @@ -1,151 +0,0 @@ -package com.gameware.game.sprites; - -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.badlogic.gdx.graphics.glutils.ShapeRenderer; -import com.badlogic.gdx.math.Vector3; - -public class RectangleColorRush extends Sprite{ - private int width; - private int height; - private int prevHeight; - private Vector3 position; - private Vector3 velocity; - private ShapeRenderer shapeRenderer; - private boolean move; - //private Color mainColor; - //private Color disabledColor; - private Texture mainTexture; - private Texture disabledTexture; - private int colorNum; - private boolean disabled; - - public RectangleColorRush(int x, int y, int width, int height, Texture mainTexture, Texture disabledTexture, int colorNum){ - this.position = new Vector3(x, y, 0); - this.prevHeight = y + height; - this.velocity = new Vector3(0, -150, 0); - this.width = width; - this.height = height; - this.shapeRenderer = new ShapeRenderer(); - this.move = false; - //this.mainColor = mainColor; - this.mainTexture = mainTexture; - this.colorNum = colorNum; - //this.disabledColor = new Color().set(128/255f,128/255f,128/255f,1); - this.disabledTexture = disabledTexture; - this.disabled = false; - } - - @Override - public void reset() { - - } - - @Override - public Object report() { - return null; - } - - @Override - public void draw(SpriteBatch sb) { - - // Renders the object on the screen - - /*shapeRenderer.begin(ShapeRenderer.ShapeType.Filled); - - if(this.disabled){ - shapeRenderer.setColor(this.disabledColor); - } - else{ - shapeRenderer.setColor(this.mainColor); - } - - shapeRenderer.rect(this.position.x,this.position.y, this.width,this.height); - - shapeRenderer.end();*/ - - Texture drawnTexture = this.mainTexture; - - sb.begin(); - - if(this.disabled){ - drawnTexture = this.disabledTexture; - } - - sb.draw(drawnTexture, this.position.x, this.position.y, this.width, this.height); - - sb.end(); - } - - @Override - public void update(float dt) { - - // moves the target-rectangles downwards if the user successfully hit a target - if(this.move) { - this.velocity.scl(dt); - this.position.add(0, velocity.y, 0); - this.velocity.scl(1 / dt); - - if((this.prevHeight - this.position.y) >= this.height){ - this.move = false; - } - } - position.x = (float) Math.round(position.x); - position.y = (float) Math.round(position.y); - } - - @Override - public void dispose() { - //this.shapeRenderer.dispose(); - } - - // Moves the rectangle downwards, used for when the user hits a target and all other targets - // should move down - public void makeMove(){ - - // Effectively sets where the target "should" be one target-height down - this.prevHeight -= this.height; - - this.move = true; - } - - public boolean isPressed(int x, int y){ - return x > this.position.x && x < (this.position.x + this.width) && (Gdx.graphics.getHeight() - y) > this.position.y && (Gdx.graphics.getHeight() - y) < (this.position.y + this.height); - } - - public int getColorNum(){ - return this.colorNum; - } - - // Effectively sets the color to grey - public void setDisabledColor(){ - this.disabled = true; - } - - // Effectively removes the grey color and sets the color to the main color - public void setEnabledColor(){ - this.disabled = false; - } - - public Vector3 getPosition(){ - return this.position; - } - - public int getHeight(){ - return this.height; - } - - public int getWidth(){ - return this.width; - } - - public void setPrevHeight(int prevHeight){ - this.prevHeight = prevHeight; - } - - public int getPrevHeight(){ - return this.prevHeight; - } -} diff --git a/frontend/core/src/com/gameware/game/states/ColorRushState.java b/frontend/core/src/com/gameware/game/states/ColorRushState.java index 4c5cb6eee641088503a79cbe32952e91393f1716..22601cb891169e0e2b1498bc0c7074906dfe13e0 100644 --- a/frontend/core/src/com/gameware/game/states/ColorRushState.java +++ b/frontend/core/src/com/gameware/game/states/ColorRushState.java @@ -2,62 +2,72 @@ 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.BitmapFont; import com.badlogic.gdx.graphics.g2d.SpriteBatch; -import com.badlogic.gdx.graphics.glutils.ShapeRenderer; -import com.gameware.game.sprites.RectangleColorRush; +import com.badlogic.gdx.math.Vector3; +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; import java.util.List; public class ColorRushState extends PlayStateTemplate { - private ShapeRenderer shapeRenderer; - private RectangleColorRush buttonLowerLeft; - private RectangleColorRush buttonLowerRight; - private RectangleColorRush buttonUpperLeft; - private RectangleColorRush buttonUpperRight; - private List<RectangleColorRush> targets; - private List<RectangleColorRush> buttons; - private List<Color> colors; + private List<ColorRushTarget> activeTargets; + private List<ColorRushTarget> previousTargets; + private List<ColorRushButton> buttons; private List<Texture> colorTextures; private Texture disabledColorTexture; + private Texture background; + private BitmapFont font; private float disabledDuration = 0f; + private float currentDuration = 0f; + private float totalGameDuration = 30f; + private float penaltyDuration = 1f; + private int targetsHit = 0; private boolean buttonsEnabled = true; - private float totalDuration = 0f; - private Texture background; + private boolean disposeTargetLeft = true; + + + private PauseButton pauseButton; public ColorRushState(GameStateManager gsm){ super(gsm); - this.shapeRenderer = new ShapeRenderer(); + + // Creates the background this.background = new Texture(Gdx.files.internal("glassy/raw/ColorRushBackground.jpg")); + // Creates the pause button + this.pauseButton = new PauseButton(); - // The colors used -// this.colors = new ArrayList<Color>(); -// this.colors.add(new Color().set(255/255f,0/255f,0/255f,1f)); -// this.colors.add(new Color().set(0/255f,255/255f,0/255f,1f)); -// this.colors.add(new Color().set(0/255f,0/255f,255/255f,1f)); -// this.colors.add(new Color().set(128/255f,0/255f,128/255f,1f)); + // Creates the bitmapfont + font = new BitmapFont(); + font.setColor(Color.BLACK); + font.getData().setScale(1f); + + // Creates the color textures this.colorTextures = new ArrayList<Texture>(); this.colorTextures.add(new Texture(Gdx.files.internal("glassy/raw/RedSquare.png"))); this.colorTextures.add(new Texture(Gdx.files.internal("glassy/raw/BlueSquare.png"))); this.colorTextures.add(new Texture(Gdx.files.internal("glassy/raw/GreenSquare.png"))); this.colorTextures.add(new Texture(Gdx.files.internal("glassy/raw/VioletSquare.png"))); + this.disabledColorTexture = new Texture(Gdx.files.internal("glassy/raw/GreySquare.png")); + // Randomizes the button arrangement Collections.shuffle(this.colorTextures); - this.disabledColorTexture = new Texture(Gdx.files.internal("glassy/raw/GreySquare.png")); - - targets = new ArrayList<RectangleColorRush>(); - buttons = new ArrayList<RectangleColorRush>(); + activeTargets = new ArrayList<ColorRushTarget>(); + previousTargets = new ArrayList<ColorRushTarget>(); + buttons = new ArrayList<ColorRushButton>(); // The four buttons used - buttons.add(new RectangleColorRush(0, 0,Gdx.graphics.getWidth()/2,Gdx.graphics.getHeight()/8, this.colorTextures.get(0), this.disabledColorTexture, 0)); - buttons.add(new RectangleColorRush(Gdx.graphics.getWidth()/2, 0,Gdx.graphics.getWidth()/2,Gdx.graphics.getHeight()/8, this.colorTextures.get(1), this.disabledColorTexture, 1)); - buttons.add(new RectangleColorRush(0, Gdx.graphics.getHeight()/8,Gdx.graphics.getWidth()/2,Gdx.graphics.getHeight()/8, this.colorTextures.get(2), this.disabledColorTexture, 2)); - buttons.add(new RectangleColorRush(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(0, 0,Gdx.graphics.getWidth()/2,Gdx.graphics.getHeight()/8, this.colorTextures.get(0), this.disabledColorTexture, 0)); + buttons.add(new ColorRushButton(Gdx.graphics.getWidth()/2, 0,Gdx.graphics.getWidth()/2,Gdx.graphics.getHeight()/8, this.colorTextures.get(1), this.disabledColorTexture, 1)); + buttons.add(new ColorRushButton(0, Gdx.graphics.getHeight()/8,Gdx.graphics.getWidth()/2,Gdx.graphics.getHeight()/8, this.colorTextures.get(2), this.disabledColorTexture, 2)); + 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)); int targetWidth = Gdx.graphics.getWidth()/8; @@ -78,7 +88,8 @@ public class ColorRushState extends PlayStateTemplate { prevColor = color; - targets.add(new RectangleColorRush(targetX, targetY, targetWidth, targetHeight, this.colorTextures.get(color), this.disabledColorTexture, color)); + activeTargets.add(new ColorRushTarget(targetX, targetY, targetWidth, targetHeight, this.colorTextures.get(color), color, this.disposeTargetLeft)); + this.disposeTargetLeft = !this.disposeTargetLeft; targetY += targetHeight; } } @@ -86,39 +97,55 @@ public class ColorRushState extends PlayStateTemplate { @Override protected void handleInput() { if(Gdx.input.justTouched()){ - - //Checks if any of the buttons were pressed - for(RectangleColorRush button : this.buttons){ + // Checks if any of the color buttons were pressed + for(ColorRushButton button : this.buttons){ if(button.isPressed(Gdx.input.getX(), Gdx.input.getY())){ this.colorChanged(button.getColorNum()); } } + + // Checks if the pause button was pressed + if(this.pauseButton.isPressed(Gdx.input.getX(), Gdx.input.getY())){ + this.gsm.push(new PauseState(this.gsm)); + } } } @Override public void update(float dt) { - // Increases the total time spent on this minigame, will be used for score calculation - if(!this.isFinished()){ - this.totalDuration += 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 here perhaps - else{ + // Post score and exit if the game is over + if(this.currentDuration > this.totalGameDuration){ + this.setFinished(); + this.setScore(this.targetsHit); + //this.postScore(); + // Exits game and updates the current state + this.gsm.set(new CreateJoinTournamentState(this.gsm)); } // Updates targets - for(RectangleColorRush target : this.targets){ + for(ColorRushTarget target : this.activeTargets){ + target.update(dt); + } + + for(ColorRushTarget target : this.previousTargets){ target.update(dt); } // Updates buttons - for(RectangleColorRush button : this.buttons){ + for(ColorRushButton button : this.buttons){ button.update(dt); } + if(this.previousTargets.size() > 0 && this.previousTargets.get(0).shouldDispose()){ + this.previousTargets.remove(0).dispose(); + } + // Accepts input if the buttons are enabled if(this.buttonsEnabled) { this.handleInput(); @@ -129,11 +156,11 @@ public class ColorRushState extends PlayStateTemplate { // Increases the counter for how long the buttons have been disabled so far this.disabledDuration += dt; - // The buttons get enabled after being disabled for 1.5 seconds - if(this.disabledDuration >= 1.5){ + // The buttons get enabled after being disabled for 1 second + if(this.disabledDuration >= this.penaltyDuration){ this.disabledDuration = 0f; this.buttonsEnabled = true; - for(RectangleColorRush button : this.buttons){ + for(ColorRushButton button : this.buttons){ button.setEnabledColor(); } } @@ -144,25 +171,44 @@ public class ColorRushState extends PlayStateTemplate { @Override public void render(SpriteBatch sb) { sb.begin(); - sb.draw(this.background, 0, Gdx.graphics.getHeight()/5); + + // Background + 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); + sb.end(); - for (RectangleColorRush button : this.buttons) { + + this.pauseButton.draw(sb); + + for (ColorRushButton button : this.buttons) { button.draw(sb); } - for (RectangleColorRush target : this.targets) { + for (ColorRushTarget target : this.activeTargets) { target.draw(sb); } + + for (ColorRushTarget target : this.previousTargets) { + target.draw(sb); + } + + } @Override public void dispose() { - for (RectangleColorRush button : this.buttons) { + for (ColorRushButton button : this.buttons) { button.dispose(); } - for (RectangleColorRush target : this.targets) { + for (ColorRushTarget target : this.activeTargets) { + target.dispose(); + } + + for (ColorRushTarget target : this.previousTargets) { target.dispose(); } @@ -170,6 +216,7 @@ public class ColorRushState extends PlayStateTemplate { tex.dispose(); } + this.font.dispose(); this.background.dispose(); this.disabledColorTexture.dispose(); } @@ -188,13 +235,19 @@ public class ColorRushState extends PlayStateTemplate { public void colorChanged(int color){ // If the user pressed the correct button - if(targets.get(0).getColorNum() == color){ + if(activeTargets.get(0).getColorNum() == color){ + + // increases targets hit, used for score + this.targetsHit++; // Removes the bottom target - this.targets.remove(0).dispose(); + ColorRushTarget targetHit = this.activeTargets.remove(0); + targetHit.startDisposal(); + this.previousTargets.add(targetHit); + // ------> Creates new target and places it at the top to keep the game going <------- - RectangleColorRush topTarget = this.targets.get(targets.size() - 1); + ColorRushTarget topTarget = this.activeTargets.get(activeTargets.size() - 1); int newColor = (int) (Math.floor(Math.random()*this.colorTextures.size())); @@ -203,27 +256,25 @@ public class ColorRushState extends PlayStateTemplate { newColor = (int) (Math.floor(Math.random()*this.colorTextures.size())); } - RectangleColorRush newTarget = new RectangleColorRush((int) (topTarget.getPosition().x), Gdx.graphics.getHeight(), topTarget.getWidth(), topTarget.getHeight(), this.colorTextures.get(newColor), this.disabledColorTexture, newColor); - newTarget.setPrevHeight(topTarget.getPrevHeight() + topTarget.getHeight()); - targets.add(newTarget); + ColorRushTarget newTarget = new ColorRushTarget((int) (topTarget.getPosition().x), Gdx.graphics.getHeight(), topTarget.getWidth(), topTarget.getHeight(), this.colorTextures.get(newColor), newColor, this.disposeTargetLeft); + newTarget.setNextHeight(topTarget.getNextHeight() + topTarget.getHeight()); + activeTargets.add(newTarget); + + // Changes the direction the next target will be "disposed" + this.disposeTargetLeft = !this.disposeTargetLeft; // <------ Creates new target and places it at the top to keep the game going -------> - // Moves the remaining targets down - for(RectangleColorRush target : this.targets){ + // Moves all the targets downward + for(ColorRushTarget target : this.activeTargets){ target.makeMove(); } - - // If all targets have been hit, the game is completed - if(this.targets.size() == 0){ - this.setFinished(); - } } //If the user pressed the incorrect button all the buttons get disabled else{ this.buttonsEnabled = false; - for(RectangleColorRush button : this.buttons){ + for(ColorRushButton button : this.buttons){ button.setDisabledColor(); } } diff --git a/frontend/core/src/com/gameware/game/states/PauseState.java b/frontend/core/src/com/gameware/game/states/PauseState.java new file mode 100644 index 0000000000000000000000000000000000000000..bed940e0b419a7845ff6103ad72b72db6e7ebf49 --- /dev/null +++ b/frontend/core/src/com/gameware/game/states/PauseState.java @@ -0,0 +1,74 @@ +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.SpriteBatch; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; +import com.gameware.game.sprites.PauseCircle; + +import java.util.ArrayList; +import java.util.List; + +public class PauseState extends State { + private ShapeRenderer sr; + private List<PauseCircle> pauseCircles; + private Texture background; + + protected PauseState(GameStateManager gsm) { + super(gsm); + + this.background = new Texture(Gdx.files.internal("glassy/raw/PauseBackground.jpg")); + + this.pauseCircles = new ArrayList<PauseCircle>(); + + for(int i = 0; i<20; i++){ + this.pauseCircles.add(new PauseCircle()); + } + } + + @Override + protected void handleInput() { + if(Gdx.input.justTouched()){ + this.gsm.pop(); + } + } + + @Override + public void update(float dt) { + this.handleInput(); + + for(PauseCircle pc : this.pauseCircles){ + pc.update(dt); + } + } + + @Override + public void render(SpriteBatch sb) { + sb.begin(); + + // Background + sb.draw(this.background, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); + + sb.end(); + + for(PauseCircle pc : pauseCircles){ + pc.draw(sb); + } + } + + @Override + public void dispose() { + + } + + @Override + public void reset() { + + } + + @Override + public Object report() { + return null; + } +}