Skip to content
Snippets Groups Projects
Commit cdc7dab1 authored by Turid Cecilie Dahl's avatar Turid Cecilie Dahl
Browse files

Merge branch '75-bubblewrapfixes' into 'dev'

Resolve "BubbleWrapFixes"

Closes #75

See merge request !71
parents 2e8ab514 ac1e5a34
No related branches found
No related tags found
1 merge request!71Resolve "BubbleWrapFixes"
Showing
with 92 additions and 159 deletions
frontend/android/assets/glassy/raw/bubble_popped_1.png

53.8 KiB

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

59.1 KiB

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

54 KiB

......@@ -2,85 +2,52 @@ package com.gameware.game.sprites;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector3;
import java.util.ArrayList;
import java.util.Random;
public class Bubble extends Actor {
public class Bubble extends Sprite {
private float width;
private float height;
private int id;
private boolean justTouched = false;
private Vector3 position;
private boolean textureChanged = false;
private int timesTouched;
private ArrayList<Texture> poppedTextures;
private Texture unpoppedTex;
private Texture currentTexture;
// Wrapping Texture in Image because Image extends Widget extends Actor, so it can be used in a table
private Image bubble;
public Bubble(float w, float h, int id, Texture unpoppedTex, Texture poppedTex1, Texture poppedTex2, Texture poppedTex3) {
this.width = w;
this.height = h;
this.id = id;
this.timesTouched = 0;
this.unpoppedTex = unpoppedTex;
bubble = new Image(unpoppedTex);
public Bubble(int x, int y, float width, float height, Texture unpoppedTex, Texture poppedTex1, Texture poppedTex2, Texture poppedTex3) {
this.position = new Vector3(x,y,0);
this.width = width;
this.height = height;
// Add different textures for popped bubbles
this.poppedTextures = new ArrayList<>();
poppedTextures.add(poppedTex1);
poppedTextures.add(poppedTex2);
poppedTextures.add(poppedTex3);
bubble.addListener(new ClickListener() {
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
justTouched = true;
timesTouched++;
System.out.println("Bubble " + getId() + " has been popped " + getTimesTouched() + " time(s).");
setTouchable(Touchable.disabled);
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
justTouched = false;
}
});
this.currentTexture = unpoppedTex;
//For the reset method.
this.unpoppedTex = unpoppedTex;
}
public Image getTexture() {
return bubble;
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 changeToPoppedTexture() {
Random r = new Random();
this.bubble.setDrawable(new TextureRegionDrawable(new TextureRegion(poppedTextures.get(r.nextInt(poppedTextures.size())))));
this.currentTexture = poppedTextures.get(r.nextInt(poppedTextures.size()));
textureChanged = true;
}
public boolean isJustTouched() {
return justTouched;
}
public boolean isTextureChanged() {
return textureChanged;
}
public int getTimesTouched() {
return timesTouched;
}
public float getWidth() {
return width;
}
......@@ -89,18 +56,25 @@ public class Bubble extends Actor {
return height;
}
private int getId() {
return id;
}
public void reset() {
justTouched = false;
textureChanged = false;
timesTouched = 0;
this.bubble.setDrawable(new TextureRegionDrawable(new TextureRegion(this.unpoppedTex)));
this.currentTexture = unpoppedTex;
}
@Override
public void draw(SpriteBatch sb) {
Texture drawnTexture = this.currentTexture;
sb.begin();
sb.draw(drawnTexture,this.position.x,this.position.y,this.width,this.height);
sb.end();
}
@Override
public void update(float dt) {
}
public void dispose() {
// Textures are shared so they should not be disposed
}
}
......@@ -16,7 +16,7 @@ public class ConfirmationBox extends Sprite {
this.width = width;
this.height = height;
this.boxTexture = new Texture(Gdx.files.internal("glassy/raw/ConfirmationSprite.png"));
this.boxTexture = new Texture(Gdx.files.internal("ConfirmationSprite.png"));
}
@Override
......
......@@ -32,8 +32,8 @@ public class PauseButton extends Sprite {
this(Gdx.graphics.getWidth() - Gdx.graphics.getWidth()/8,
Gdx.graphics.getHeight() - Gdx.graphics.getHeight()/13,
Gdx.graphics.getWidth()/10,Gdx.graphics.getWidth()/10,
new Texture(Gdx.files.internal("glassy/raw/PauseButtonBlack.png")),
new Texture(Gdx.files.internal("glassy/raw/PauseButtonWhite.png")));
new Texture(Gdx.files.internal("PauseButtonBlack.png")),
new Texture(Gdx.files.internal("PauseButtonWhite.png")));
}
......
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.scenes.scene2d.ui.Container;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.gameware.game.GameWare;
import com.gameware.game.sprites.Bubble;
......@@ -16,17 +12,24 @@ import java.util.ArrayList;
public class BubbleWrapState extends PlayStateTemplate {
private ArrayList<Bubble> bubbles;
private int poppedBubbles;
private Image background;
private float currentTime = 0f;
private float totalTime = totalGameTime;
private Label timeLabel;
private Texture background;
private Texture unpopped;
private Texture popped1;
private Texture popped2;
private Texture popped3;
private Label timeLabel;
private ArrayList<Bubble> bubbles = new ArrayList<>();
private BitmapFont font;
private int poppedBubbles;
private int score;
private final int bubbleLength = 170;
private final int bubblePadding = 10;
private final int bubbleCount = 54;
private float currentTime = 0f;
private float totalTime = totalGameTime;
public BubbleWrapState(GameStateManager gsm) {
super(gsm);
......@@ -34,47 +37,43 @@ public class BubbleWrapState extends PlayStateTemplate {
super.screenshot = new Texture(Gdx.files.internal("bubbleWrapPhotoEdit.png"));
unpopped = new Texture(Gdx.files.internal("glassy/raw/bubble_unpopped_1.png"));
popped1 = new Texture(Gdx.files.internal("glassy/raw/bubble_popped_1.png"));
popped2 = new Texture(Gdx.files.internal("glassy/raw/bubble_popped_2.png"));
popped3 = new Texture(Gdx.files.internal("glassy/raw/bubble_popped_3.png"));
//Overrides PlayStateTemplate's gametime, because this game should not be 30 seconds long.
this.totalTime = 20f;
background = new Texture(Gdx.files.internal("bubblewrap_background.jpg"));
unpopped = new Texture(Gdx.files.internal("bubble_unpopped_1.png"));
popped1 = new Texture(Gdx.files.internal("bubble_popped_1.png"));
popped2 = new Texture(Gdx.files.internal("bubble_popped_2.png"));
popped3 = new Texture(Gdx.files.internal("bubble_popped_3.png"));
this.poppedBubbles = 0;
this.background = new Image(new Texture(Gdx.files.internal("glassy/raw/bubblewrap_background.jpg")));
this.background.setWidth(Gdx.graphics.getWidth());
this.background.setHeight(Gdx.graphics.getHeight());
stage.addActor(this.background);
// Label that displays how much time is left
this.timeLabel = new Label("Time left: ", skin);
// Changes the label to a white color
BitmapFont font = new BitmapFont();
font = new BitmapFont();
font.getData().setScale(Gdx.graphics.getWidth() / GameWare.WIDTH * 2.5f);
Label.LabelStyle style = new Label.LabelStyle(font, Color.WHITE);
timeLabel.setStyle(style);
timeLabel.setPosition(Gdx.graphics.getWidth()/2 - timeLabel.getWidth() / 2f, Gdx.graphics.getHeight() - Gdx.graphics.getHeight()/10);
stage.addActor(timeLabel);
// Fill the table with bubbles
for(int i = 0; i<9; i++){
for (int j = 0; j < this.bubbleCount/9; j++) {
bubbles.add(new Bubble(j*(bubbleLength + bubblePadding),i*(bubbleLength + bubblePadding),bubbleLength,bubbleLength,unpopped,popped1,popped2,popped3));
}
}
// Creates the bubbles, the table to put them in and adds them to the stage as Actors
createBubbles();
createBubbleWrapLayout();
}
@Override
protected void handleInput() {
if (Gdx.input.justTouched()) {
/* Checks if any bubble has been pressed and that it's not added
to the counter more than once */
/* Checks if any bubble has been pressed and that it's not added to the counter more than once */
for (Bubble bubble : bubbles) {
if (bubble.isJustTouched() && !bubble.isTextureChanged()) {
if (bubble.isPressed(Gdx.input.getX(),Gdx.input.getY()) && !bubble.isTextureChanged()) {
bubble.changeToPoppedTexture();
poppedBubbles++;
System.out.println(poppedBubbles);
}
}
......@@ -88,98 +87,58 @@ public class BubbleWrapState extends PlayStateTemplate {
@Override
public void update(float dt) {
Gdx.input.setInputProcessor(stage);
this.handleInput();
this.currentTime += dt;
timeLabel.setText("Time left: " + Math.round((totalTime - currentTime) * 100.0) / 100.0);
// Game should finish if the time has run out
if (this.currentTime >= this.totalTime) {
System.out.println("Score: " + poppedBubbles);
// Game should finish if the time has run out or all the bubbles are popped.
if ((this.currentTime >= this.totalTime) || poppedBubbles == 54) {
handleFinishedGame();
}
// Game should finish if all the bubbles are popped
if (poppedBubbles == 48) {
System.out.println("All bubbles are popped! Score: " + poppedBubbles);
handleFinishedGame();
}
stage.act();
}
// Stage uses a Batch to draw
@Override
public void render(SpriteBatch sb) {
stage.draw();
sb.begin();
sb.draw(this.background, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
this.font.draw(sb, String.valueOf(Math.round((this.totalTime - this.currentTime) * 100) / 100.0), Gdx.graphics.getWidth()/40,Gdx.graphics.getHeight() - Gdx.graphics.getHeight()/40);
sb.end();
// Renders pause button
super.renderPauseButton(sb);
for (Bubble bubble : this.bubbles){
bubble.draw(sb);
}
private void createBubbles() {
bubbles = new ArrayList<>();
int bubCount = 48;
for (int i = 0; i < bubCount; i++) {
bubbles.add(new Bubble(70, 70, i+1, this.unpopped, this.popped1, this.popped2, this.popped3));
}
}
private void createBubbleWrapLayout() {
Container<Table> tableContainer = new Container<>();
float sw = Gdx.graphics.getWidth();
float sh = Gdx.graphics.getHeight();
float cw = sw * 0.8f;
float ch = sh * 0.8f;
tableContainer.setSize(cw, ch);
tableContainer.setPosition((sw - cw) / 2.0f, (sh - ch) / 2.0f);
tableContainer.fillX();
Table table = new Table();
table.setFillParent(true);
// Fill the table with bubbles
for(int i = 0; i<8; i++){
table.row();
for (int j = i*6; j < (i+1)*6; j++) {
table.add(bubbles.get(j).getTexture());
stage.addActor(bubbles.get(j));
}
}
tableContainer.setActor(table);
stage.addActor(tableContainer);
}
private void handleFinishedGame() {
System.out.println("Game finished, starting new state");
this.setScore(this.poppedBubbles);
//Score is calculated. One point per bubble popped, pluss three points for each second of remaining time.
score = this.poppedBubbles + Math.round(this.totalTime - this.currentTime)*3;
this.setScore(score);
this.gameDone();
return;
}
@Override
public void dispose() {
stage.dispose();
this.unpopped.dispose();
this.popped1.dispose();
this.popped2.dispose();
this.popped3.dispose();
super.pauseButton.dispose();
for(Bubble bubble : bubbles){ bubble.dispose(); }
this.font.dispose();
this.background.dispose();
}
@Override
public void reset() {
this.poppedBubbles = 0;
this.currentTime = 0f;
createBubbles();
createBubbleWrapLayout();
for(Bubble bubble : bubbles){ bubble.reset(); }
}
}
......@@ -34,7 +34,7 @@ public class ColorRushState extends PlayStateTemplate {
super.screenshot = new Texture(Gdx.files.internal("colorRushPhotoEdit.png"));
// Creates the background
this.background = new Texture(Gdx.files.internal("glassy/raw/ColorRushBackground.jpg"));
this.background = new Texture(Gdx.files.internal("ColorRushBackground.jpg"));
// Creates the bitmapfont
font = new BitmapFont();
......@@ -44,12 +44,12 @@ public class ColorRushState extends PlayStateTemplate {
// 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.colorTextures.add(new Texture(Gdx.files.internal("RedSquare.png")));
this.colorTextures.add(new Texture(Gdx.files.internal("BlueSquare.png")));
this.colorTextures.add(new Texture(Gdx.files.internal("GreenSquare.png")));
this.colorTextures.add(new Texture(Gdx.files.internal("VioletSquare.png")));
this.disabledColorTexture = new Texture(Gdx.files.internal("glassy/raw/GreySquare.png"));
this.disabledColorTexture = new Texture(Gdx.files.internal("GreySquare.png"));
// Randomizes the button arrangement
Collections.shuffle(this.colorTextures);
......
......@@ -26,9 +26,9 @@ public class PauseState extends State {
public PauseState(GameStateManager gsm, PlayStateTemplate pausedGame) {
super(gsm);
this.background = new Texture(Gdx.files.internal("glassy/raw/PauseBackground.jpg"));
this.pauseText = new Texture(Gdx.files.internal("glassy/raw/PauseText.png"));
this.dimmingTexture = new Texture(Gdx.files.internal("glassy/raw/DimmingTexture.png"));
this.background = new Texture(Gdx.files.internal("PauseBackground.jpg"));
this.pauseText = new Texture(Gdx.files.internal("PauseText.png"));
this.dimmingTexture = new Texture(Gdx.files.internal("DimmingTexture.png"));
this.pauseCircles = new ArrayList<PauseCircle>();
......@@ -41,8 +41,8 @@ public class PauseState extends State {
int buttonWidth = Gdx.graphics.getWidth()/3;
int buttonHeight = buttonWidth/2;
this.resumeButton = new PauseMenuButton(new Texture(Gdx.files.internal("glassy/raw/ResumeButton.png")), buttonWidth/3, Gdx.graphics.getHeight()/7, buttonWidth, buttonHeight);
this.exitButton = new PauseMenuButton(new Texture(Gdx.files.internal("glassy/raw/ExitButton.png")), buttonWidth + buttonWidth*2/3, Gdx.graphics.getHeight()/7, buttonWidth, buttonHeight);
this.resumeButton = new PauseMenuButton(new Texture(Gdx.files.internal("ResumeButton.png")), buttonWidth/3, Gdx.graphics.getHeight()/7, buttonWidth, buttonHeight);
this.exitButton = new PauseMenuButton(new Texture(Gdx.files.internal("ExitButton.png")), buttonWidth + buttonWidth*2/3, Gdx.graphics.getHeight()/7, buttonWidth, buttonHeight);
for(int i = 0; i<25; i++){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment