Skip to content

Commit

Permalink
did some bubble stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
mklemmingen committed Dec 2, 2023
1 parent 2526684 commit 1a9f395
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 23 deletions.
Binary file added assets/sounds/arcadecoin.mp3
Binary file not shown.
Binary file modified assets/speechbubbles/alarmattack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/speechbubbles/kill1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/speechbubbles/kill2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/speechbubbles/kill3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/speechbubbles/kill4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/speechbubbles/kill5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions core/src/com/boomchess/game/BoomChess.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.boomchess.game.backend.subsoldier.General;
import com.boomchess.game.frontend.actor.*;
import com.boomchess.game.frontend.picture.RandomImage;
import com.boomchess.game.frontend.picture.SpeechBubbles;
import com.boomchess.game.frontend.screen.RelativeResizer;
import com.boomchess.game.frontend.sound.MusicPlaylist;
import com.boomchess.game.frontend.sound.RandomSound;
Expand Down Expand Up @@ -229,6 +230,12 @@ public class BoomChess extends ApplicationAdapter {
// random texture object of kill speech bubbles
public static RandomImage killSpeeches;

// for the speech bubbles in general, we need to build a stage especially for them
public static Stage speechBubbleStage;

// for the sounds of the speechBubbles
public static RandomSound speechSounds;

// -----------------------------------------------------------------------------------------


Expand Down Expand Up @@ -408,6 +415,10 @@ public void create() {
bigExplosionSound = new RandomSound();
bigExplosionSound.addSound("sounds/boom.mp3");

// speech bubble pop up sounds
speechSounds = new RandomSound();
speechSounds.addSound("sounds/arcadecoin.mp3");

// load the sounds for the medieval mode

archerSound = new RandomSound();
Expand Down Expand Up @@ -611,6 +622,10 @@ public void changed(ChangeEvent event, Actor actor) {
actionSequence = new AttackSequence();

loadingScreenIsRunning = false;

// create the speechBubbleStage
speechBubbleStage = new Stage();

// ensures game starts in menu
createMainMenuStage();

Expand Down Expand Up @@ -709,6 +724,10 @@ public void render() {
botMovingStage.act(Gdx.graphics.getDeltaTime());
botMovingStage.draw();

// stage for the speech bubbles
speechBubbleStage.act(Gdx.graphics.getDeltaTime());
speechBubbleStage.draw();

// render the gameEndStage
gameEndStage.act();
gameEndStage.draw();
Expand Down Expand Up @@ -803,6 +822,9 @@ private void calculateDamage(String teamColor) {
}
}
}
// add a attack incoming bubble from SpeechBubbles
SpeechBubbles.createSpeechAttackIncoming();
// start the actionSequence, since Damage has checked all of the board
actionSequence.startSequences();
}

Expand Down Expand Up @@ -833,6 +855,9 @@ public void dispose() {
dottedLineStage.dispose();
deathExplosionStage.dispose();
gameEndStage.dispose();
speechBubbleStage.dispose();
botMovingStage.dispose();
loadingStage.dispose();

// dispose of all assets --- Textures do not natively get rubbish canned by Javas inbuilt collector
// Images do tho!
Expand Down
3 changes: 3 additions & 0 deletions core/src/com/boomchess/game/backend/Damage.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ public static void damagePiece(int damage, int positionAttX, int positionAttY,
BoomChess.createGameEndStage(attackerColor);
System.out.println("A General has died!");
}
// if the defending piece is not a general, we can just kill it
killPiece(positionDefX, positionDefY);
// add a speech bubble to the attacker
SpeechBubbles.createSpeechDefeatEnemy(positionAttX, positionAttY);
} else {
// set the new health of the piece to the currentHealth variable
gameBoard[positionDefX][positionDefY].setHealth(currentHealth);
Expand Down
20 changes: 12 additions & 8 deletions core/src/com/boomchess/game/frontend/actor/AttackSequence.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ public void startSequences(){
damageSequenceRunning = true;
lengthOfAttackList = attackList.size();

// adds an actor to the gameStage that displays "Attack in Progress"!
SpeechBubbles.createSpeechAttackIncoming();

actActor();
}

Expand Down Expand Up @@ -102,6 +99,10 @@ private void actActor(){
// clear all the stages
deathExplosionStage.clear();
dottedLineStage.clear();
// clear the botMovingStage
botMovingStage.clear();
// clear the speechBubbleStage
speechBubbleStage.clear();
// set damageSequenceRunning to false
damageSequenceRunning = false;
return;
Expand All @@ -122,20 +123,23 @@ private void actActor(){
// if it is a HitMarkerActor, add it to the GameStage
smallExplosionSound.play(soundVolume);
deathExplosionStage.addActor(actorBuddy);
timePerBreak = 0.25f;
timePerBreak = 1f;
} else if (actorBuddy instanceof DeathExplosionActor) {
// if it is a DeathExplosionActor, add it to the deathExplosionStage
BoomChess.bigExplosionSound.play(BoomChess.soundVolume);
deathExplosionStage.addActor(actorBuddy);
//adds a death kill speech bubble to the attacker
SpeechBubbles.createSpeechDefeatEnemy(((DeathExplosionActor) actorBuddy).X,
((DeathExplosionActor) actorBuddy).Y);
timePerBreak = 3f;
timePerBreak = 2f;
} else if (actorBuddy instanceof DottedLineActor) {
// if it is a DottedLineActor, add it to the GameStage
((DottedLineActor) actorBuddy).makeSound();
dottedLineStage.addActor(actorBuddy);
timePerBreak = 0.5f;
timePerBreak = 1f;
} else if (actorBuddy instanceof Bubble) {
// if it is a Bubble, add it to the speechBubbleStage
((Bubble) actorBuddy).makeSound(); // plays radio chatter
speechBubbleStage.addActor(actorBuddy);
timePerBreak = 2f;
} else {
// simulate throwing an error for the log
System.out.println("attackSequence.playNext() has an unknown actor type");
Expand Down
81 changes: 81 additions & 0 deletions core/src/com/boomchess/game/frontend/actor/Bubble.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.boomchess.game.frontend.actor;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Stack;
import com.boomchess.game.BoomChess;
import com.boomchess.game.backend.Board;
import com.boomchess.game.backend.Coordinates;
import com.boomchess.game.backend.Soldier;
import com.boomchess.game.frontend.interfaces.makeASoundInterface;
import com.boomchess.game.frontend.stage.MenuStage;

import static com.boomchess.game.BoomChess.*;

public class Bubble extends Actor {
/*
This class holds functions to create objects that hold the speech bubbles, it self destructs after 2 seconds
*/

// px coords
private float X;
private float Y;
// elapsed time since addition to stage
private float elapsed = 0;
// this is the maximum duration that the bubble will be on the screen
private static final float MAX_DURATION = 2f;
// this is the stack of the bubble
private Stack stack;

public Bubble(Stack stack, float X, float Y){
/*
This function creates a Stack object that holds the speech bubble that says "Attack in Progress!"
*/
this.stack = stack;
this.X = X;
this.Y = Y;
}

@Override
public void act(float delta) {
/*
* this method is called every frame to update the Bubbles Object and overrides the standard act method
* so that the Bubble will be removed after a certain amount of time
*/

// this ensures that if the player has gone back to the menu, the sequence will not continue
if (BoomChess.currentStage instanceof MenuStage){
remove(); // This will remove the actor from the stage
return;
}

super.act(delta);
elapsed += delta;
if (elapsed > MAX_DURATION) {
remove(); // This will remove the actor from the stage
}
}

// Override the draw method to add the stack at the correct position
@Override
public void draw(Batch batch, float parentAlpha) {
/*
This method is called every frame to draw the bubble
*/
super.draw(batch, parentAlpha);
stack.setPosition(X, Y);
stack.draw(batch, parentAlpha);
}

public void makeSound(){
// plays some cool sounds

speechSounds.play(soundVolume);

// TODO add some more sounds
}

}
48 changes: 33 additions & 15 deletions core/src/com/boomchess/game/frontend/picture/SpeechBubbles.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.badlogic.gdx.scenes.scene2d.ui.Stack;
import com.boomchess.game.BoomChess;
import com.boomchess.game.backend.Coordinates;
import com.boomchess.game.frontend.actor.Bubble;
import com.boomchess.game.frontend.actor.DeathExplosionActor;

import static com.boomchess.game.BoomChess.*;

Expand All @@ -21,27 +23,24 @@ public static void createSpeechAttackIncoming(){

Image alarmImage = new Image(BoomChess.alarmTexture);

alarmImage.setSize(tileSize*1, tileSize*0.5f);
alarm.add(alarmImage);
alarm.setSize(tileSize*1, tileSize*0.5f);
editImageStack(alarmImage, alarm);

Coordinates generalCoordinates;

// find the general coordinates to add a speech bubble to him
if(currentState == GameState.GREEN_TURN){
// if it is green's turn, find the general coordinates of green
generalCoordinates = BoomChess.findGeneral(false);
generalCoordinates = BoomChess.findGeneral(true);
}
else{
// if it is red's turn, find the general coordinates of red
generalCoordinates = BoomChess.findGeneral(true);
generalCoordinates = BoomChess.findGeneral(false);
}

//set position
// create bubble
assert generalCoordinates != null;
alarm.setPosition(generalCoordinates.getX() + (tileSize / 16), generalCoordinates.getY() + tileSize / 4);

deathExplosionStage.addActor(alarm);
createBubble(alarm, generalCoordinates.getX() + (tileSize / 16),
generalCoordinates.getY() + tileSize / 4);
}

// this function creates a Stack Object that creates a random speech bubble of defeating the enemy
Expand All @@ -52,16 +51,35 @@ public static void createSpeechDefeatEnemy(int x, int y) {
*/
Stack defeatEnemy = new Stack();
Image defeatEnemyImage = new Image(BoomChess.killSpeeches.getRandomTexture());
defeatEnemyImage.setSize(tileSize * 1.5f, tileSize * 0.75f);
defeatEnemy.add(defeatEnemyImage);
defeatEnemy.setSize(tileSize * 1.5f, tileSize * 0.75f);
editImageStack(defeatEnemyImage, defeatEnemy);

//adds a death kill speech bubble to the attacker
Coordinates deathCoordinates = calculatePXbyTile(x, y);
//set position
defeatEnemy.setPosition(deathCoordinates.getX(), deathCoordinates.getY());

deathExplosionStage.addActor(defeatEnemy);
// create bubble
createBubble(defeatEnemy, deathCoordinates.getX(), deathCoordinates.getY());
}

private static void editImageStack(Image image, Stack stack){
/*
This function scales the image and stack of each bubble according to the current tile size
*/
image.setSize(tileSize*1, tileSize*0.5f);
stack.setSize(tileSize*1, tileSize*0.5f);
stack.add(image);
}

private static void createBubble(Stack stack, float pxX, float pxY){
/*
This function creates a Bubble Object that is added to the current Action Sequence Object in BoomChess
*/

// create a Bubble Object with the parameters
Bubble bubble = new Bubble(stack, pxX, pxY);
bubble.setZIndex(1);
// add the Bubble Object to the current Action Sequence Object in BoomChess
actionSequence.addSequence(bubble);
System.out.println("Added a Speech Bubble at Screen Coords: " + pxX + ", " + pxY);
}


Expand Down

0 comments on commit 1a9f395

Please sign in to comment.