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

completes issue #15 and almost completes issue #41

parent 47003939
No related branches found
No related tags found
1 merge request!30Resolve "ColorRushState"
frontend/android/assets/glassy/raw/BlueSquare.png

804 B | W: | H:

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

4.07 KiB | W: | H:

frontend/android/assets/glassy/raw/BlueSquare.png
frontend/android/assets/glassy/raw/BlueSquare.png
frontend/android/assets/glassy/raw/BlueSquare.png
frontend/android/assets/glassy/raw/BlueSquare.png
  • 2-up
  • Swipe
  • Onion skin
frontend/android/assets/glassy/raw/PauseBackground.jpg

23.3 KiB

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

22.8 KiB

package com.gameware.game.sprites; package com.gameware.game.sprites;
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.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.math.Vector3;
public class RectangleColorRush extends Sprite{ public class ColorRushButton extends Sprite{
private int width; private int width;
private int height; private int height;
private int prevHeight;
private Vector3 position; private Vector3 position;
private Vector3 velocity;
private ShapeRenderer shapeRenderer;
private boolean move;
//private Color mainColor;
//private Color disabledColor;
private Texture mainTexture; private Texture mainTexture;
private Texture disabledTexture; private Texture disabledTexture;
private int colorNum; private int colorNum;
private boolean disabled; private boolean disabled;
public RectangleColorRush(int x, int y, int width, int height, Texture mainTexture, Texture disabledTexture, int colorNum){ public ColorRushButton(int x, int y, int width, int height, Texture mainTexture, Texture disabledTexture, int colorNum){
this.position = new Vector3(x, y, 0); this.position = new Vector3(x, y, 0);
this.prevHeight = y + height;
this.velocity = new Vector3(0, -150, 0);
this.width = width; this.width = width;
this.height = height; this.height = height;
this.shapeRenderer = new ShapeRenderer();
this.move = false;
//this.mainColor = mainColor;
this.mainTexture = mainTexture; this.mainTexture = mainTexture;
this.colorNum = colorNum;
//this.disabledColor = new Color().set(128/255f,128/255f,128/255f,1);
this.disabledTexture = disabledTexture; this.disabledTexture = disabledTexture;
this.colorNum = colorNum;
this.disabled = false; this.disabled = false;
} }
...@@ -51,21 +38,6 @@ public class RectangleColorRush extends Sprite{ ...@@ -51,21 +38,6 @@ public class RectangleColorRush extends Sprite{
@Override @Override
public void draw(SpriteBatch sb) { 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; Texture drawnTexture = this.mainTexture;
sb.begin(); sb.begin();
...@@ -81,34 +53,13 @@ public class RectangleColorRush extends Sprite{ ...@@ -81,34 +53,13 @@ public class RectangleColorRush extends Sprite{
@Override @Override
public void update(float dt) { public void update(float dt) {
position.x = (int) Math.round(position.x);
// moves the target-rectangles downwards if the user successfully hit a target position.y = (int) Math.round(position.y);
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 @Override
public void dispose() { public void dispose() {
//this.shapeRenderer.dispose(); // Textures are shared so they should not be disposed
}
// 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){ public boolean isPressed(int x, int y){
...@@ -140,12 +91,4 @@ public class RectangleColorRush extends Sprite{ ...@@ -140,12 +91,4 @@ public class RectangleColorRush extends Sprite{
public int getWidth(){ public int getWidth(){
return this.width; return this.width;
} }
public void setPrevHeight(int prevHeight){
this.prevHeight = prevHeight;
}
public int getPrevHeight(){
return this.prevHeight;
}
} }
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;
}
}
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);
}
}
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();
}
}
...@@ -2,62 +2,72 @@ package com.gameware.game.states; ...@@ -2,62 +2,72 @@ 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.Color;
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.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.Vector3;
import com.gameware.game.sprites.RectangleColorRush; 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.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
public class ColorRushState extends PlayStateTemplate { public class ColorRushState extends PlayStateTemplate {
private ShapeRenderer shapeRenderer; private List<ColorRushTarget> activeTargets;
private RectangleColorRush buttonLowerLeft; private List<ColorRushTarget> previousTargets;
private RectangleColorRush buttonLowerRight; private List<ColorRushButton> buttons;
private RectangleColorRush buttonUpperLeft;
private RectangleColorRush buttonUpperRight;
private List<RectangleColorRush> targets;
private List<RectangleColorRush> buttons;
private List<Color> colors;
private List<Texture> colorTextures; private List<Texture> colorTextures;
private Texture disabledColorTexture; private Texture disabledColorTexture;
private Texture background;
private BitmapFont font;
private float disabledDuration = 0f; 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 boolean buttonsEnabled = true;
private float totalDuration = 0f; private boolean disposeTargetLeft = true;
private Texture background;
private PauseButton pauseButton;
public ColorRushState(GameStateManager gsm){ public ColorRushState(GameStateManager gsm){
super(gsm); super(gsm);
this.shapeRenderer = new ShapeRenderer();
// 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();
// The colors used // Creates the bitmapfont
// this.colors = new ArrayList<Color>(); font = new BitmapFont();
// this.colors.add(new Color().set(255/255f,0/255f,0/255f,1f)); font.setColor(Color.BLACK);
// this.colors.add(new Color().set(0/255f,255/255f,0/255f,1f)); font.getData().setScale(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 color textures
this.colorTextures = new ArrayList<Texture>(); 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/RedSquare.png")));
this.colorTextures.add(new Texture(Gdx.files.internal("glassy/raw/BlueSquare.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/GreenSquare.png")));
this.colorTextures.add(new Texture(Gdx.files.internal("glassy/raw/VioletSquare.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 // Randomizes the button arrangement
Collections.shuffle(this.colorTextures); Collections.shuffle(this.colorTextures);
this.disabledColorTexture = new Texture(Gdx.files.internal("glassy/raw/GreySquare.png")); activeTargets = new ArrayList<ColorRushTarget>();
previousTargets = new ArrayList<ColorRushTarget>();
targets = new ArrayList<RectangleColorRush>(); buttons = new ArrayList<ColorRushButton>();
buttons = new ArrayList<RectangleColorRush>();
// The four buttons used // 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 ColorRushButton(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 ColorRushButton(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 ColorRushButton(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(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; int targetWidth = Gdx.graphics.getWidth()/8;
...@@ -78,7 +88,8 @@ public class ColorRushState extends PlayStateTemplate { ...@@ -78,7 +88,8 @@ public class ColorRushState extends PlayStateTemplate {
prevColor = color; 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; targetY += targetHeight;
} }
} }
...@@ -86,39 +97,55 @@ public class ColorRushState extends PlayStateTemplate { ...@@ -86,39 +97,55 @@ public class ColorRushState extends PlayStateTemplate {
@Override @Override
protected void handleInput() { protected void handleInput() {
if(Gdx.input.justTouched()){ if(Gdx.input.justTouched()){
// Checks if any of the color buttons were pressed
//Checks if any of the buttons were pressed for(ColorRushButton button : this.buttons){
for(RectangleColorRush button : this.buttons){
if(button.isPressed(Gdx.input.getX(), Gdx.input.getY())){ if(button.isPressed(Gdx.input.getX(), Gdx.input.getY())){
this.colorChanged(button.getColorNum()); 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 @Override
public void update(float dt) { public void update(float dt) {
// Increases the total time spent on this minigame, will be used for score calculation // Increases the current duration, used to keep track of the play duration and stop the game
if(!this.isFinished()){ // after a while
this.totalDuration += dt; this.currentDuration += dt;
}
// post score here perhaps // Post score and exit if the game is over
else{ 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 // Updates targets
for(RectangleColorRush target : this.targets){ for(ColorRushTarget target : this.activeTargets){
target.update(dt);
}
for(ColorRushTarget target : this.previousTargets){
target.update(dt); target.update(dt);
} }
// Updates buttons // Updates buttons
for(RectangleColorRush button : this.buttons){ for(ColorRushButton button : this.buttons){
button.update(dt); 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 // Accepts input if the buttons are enabled
if(this.buttonsEnabled) { if(this.buttonsEnabled) {
this.handleInput(); this.handleInput();
...@@ -129,11 +156,11 @@ public class ColorRushState extends PlayStateTemplate { ...@@ -129,11 +156,11 @@ public class ColorRushState extends PlayStateTemplate {
// Increases the counter for how long the buttons have been disabled so far // Increases the counter for how long the buttons have been disabled so far
this.disabledDuration += dt; this.disabledDuration += dt;
// The buttons get enabled after being disabled for 1.5 seconds // The buttons get enabled after being disabled for 1 second
if(this.disabledDuration >= 1.5){ if(this.disabledDuration >= this.penaltyDuration){
this.disabledDuration = 0f; this.disabledDuration = 0f;
this.buttonsEnabled = true; this.buttonsEnabled = true;
for(RectangleColorRush button : this.buttons){ for(ColorRushButton button : this.buttons){
button.setEnabledColor(); button.setEnabledColor();
} }
} }
...@@ -144,25 +171,44 @@ public class ColorRushState extends PlayStateTemplate { ...@@ -144,25 +171,44 @@ public class ColorRushState extends PlayStateTemplate {
@Override @Override
public void render(SpriteBatch sb) { public void render(SpriteBatch sb) {
sb.begin(); 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(); sb.end();
for (RectangleColorRush button : this.buttons) {
this.pauseButton.draw(sb);
for (ColorRushButton button : this.buttons) {
button.draw(sb); button.draw(sb);
} }
for (RectangleColorRush target : this.targets) { for (ColorRushTarget target : this.activeTargets) {
target.draw(sb); target.draw(sb);
} }
for (ColorRushTarget target : this.previousTargets) {
target.draw(sb);
}
} }
@Override @Override
public void dispose() { public void dispose() {
for (RectangleColorRush button : this.buttons) { for (ColorRushButton button : this.buttons) {
button.dispose(); button.dispose();
} }
for (RectangleColorRush target : this.targets) { for (ColorRushTarget target : this.activeTargets) {
target.dispose();
}
for (ColorRushTarget target : this.previousTargets) {
target.dispose(); target.dispose();
} }
...@@ -170,6 +216,7 @@ public class ColorRushState extends PlayStateTemplate { ...@@ -170,6 +216,7 @@ public class ColorRushState extends PlayStateTemplate {
tex.dispose(); tex.dispose();
} }
this.font.dispose();
this.background.dispose(); this.background.dispose();
this.disabledColorTexture.dispose(); this.disabledColorTexture.dispose();
} }
...@@ -188,13 +235,19 @@ public class ColorRushState extends PlayStateTemplate { ...@@ -188,13 +235,19 @@ public class ColorRushState extends PlayStateTemplate {
public void colorChanged(int color){ public void colorChanged(int color){
// If the user pressed the correct button // 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 // 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 <------- // ------> 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())); int newColor = (int) (Math.floor(Math.random()*this.colorTextures.size()));
...@@ -203,27 +256,25 @@ public class ColorRushState extends PlayStateTemplate { ...@@ -203,27 +256,25 @@ public class ColorRushState extends PlayStateTemplate {
newColor = (int) (Math.floor(Math.random()*this.colorTextures.size())); 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); ColorRushTarget newTarget = new ColorRushTarget((int) (topTarget.getPosition().x), Gdx.graphics.getHeight(), topTarget.getWidth(), topTarget.getHeight(), this.colorTextures.get(newColor), newColor, this.disposeTargetLeft);
newTarget.setPrevHeight(topTarget.getPrevHeight() + topTarget.getHeight()); newTarget.setNextHeight(topTarget.getNextHeight() + topTarget.getHeight());
targets.add(newTarget); 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 -------> // <------ Creates new target and places it at the top to keep the game going ------->
// Moves the remaining targets down // Moves all the targets downward
for(RectangleColorRush target : this.targets){ for(ColorRushTarget target : this.activeTargets){
target.makeMove(); 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 //If the user pressed the incorrect button all the buttons get disabled
else{ else{
this.buttonsEnabled = false; this.buttonsEnabled = false;
for(RectangleColorRush button : this.buttons){ for(ColorRushButton button : this.buttons){
button.setDisabledColor(); button.setDisabledColor();
} }
} }
......
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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment