Skip to content

Commit

Permalink
Merge pull request #161 from UQcsse3200/Team-5--tmp2
Browse files Browse the repository at this point in the history
[Team 5] Turret Selection, Game End, Further improvements to Economy
  • Loading branch information
The-AhmadAA authored Sep 12, 2023
2 parents fe28c74 + 328bd02 commit a8cef8f
Show file tree
Hide file tree
Showing 12 changed files with 273 additions and 16 deletions.
2 changes: 1 addition & 1 deletion source/core/assets/flat-earth/skin/flat-earth-ui.json
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@
com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle: {
default: {
font: font
fontColor: black
fontColor: white
}
button: {
font: button
Expand Down
Binary file added source/core/assets/sounds/economy/click.wav
Binary file not shown.
Binary file added source/core/assets/sounds/economy/click_1.wav
Binary file not shown.
4 changes: 3 additions & 1 deletion source/core/src/main/com/csse3200/game/GdxGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@ private Screen newScreen(ScreenType screenType) {
return new LevelSelectScreen(this);
case LOSING_SCREEN:
return new LosingScreen(this);
case TURRET_SELECTION:
return new TurretSelectionScreen(this);
default:
return null;
}
}

public enum ScreenType {
MAIN_MENU, MAIN_GAME, SETTINGS, STORY_SCREEN, LEVEL_SELECT, LOSING_SCREEN
MAIN_MENU, MAIN_GAME, SETTINGS, STORY_SCREEN, LEVEL_SELECT, TURRET_SELECTION, LOSING_SCREEN
}

/**
Expand Down
12 changes: 3 additions & 9 deletions source/core/src/main/com/csse3200/game/areas/ForestGameArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ public class ForestGameArea extends GameArea {
};
private static final String[] forestSounds = {
"sounds/Impact4.ogg",
"sounds/economy/click.wav",
"sounds/economy/click_1.wav",
"sounds/towers/gun_shot_trimmed.mp3",
"sounds/towers/deploy.mp3",
"sounds/towers/stow.mp3",
Expand Down Expand Up @@ -246,7 +248,6 @@ public void create() {
spawnEffectProjectile(new Vector2(2, 6), PhysicsLayer.NPC, towardsMobs, new Vector2(2f, 2f), ProjectileEffects.SLOW, false);
spawnXenoGrunts();
spawnWeaponTower();
spawnEngineer();
//bossKing1 = spawnBossKing1();
startWaveTimer();
// spawnIncome();
Expand Down Expand Up @@ -711,14 +712,7 @@ private void spawnIncome() {
spawnEntityAt(towerfactory, randomPos, true, true);
}
}

private void spawnEngineer() {
for (int i = 0; i < terrain.getMapBounds(0).x; i += 3) {
Entity engineer = EngineerFactory.createEngineer();
spawnEntityAt(engineer, new GridPoint2(1, i), true, true);
}
}


/**
* Creates the scanners (one per lane) that detect absence of towers and presence of mobs,
* and trigger engineer spawning
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.csse3200.game.components.gamearea;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
Expand Down Expand Up @@ -30,13 +31,15 @@ public class CurrencyDisplay extends UIComponent {
private Camera camera;
private TextButton scrapsTb;
private TextButton crystalsTb;
private Sound clickSound;

/**
* Adds actors to stage
*/
@Override
public void create() {
super.create();
clickSound = ServiceLocator.getResourceService().getAsset("sounds/economy/click.wav", Sound.class);
addActors();
}

Expand Down Expand Up @@ -101,12 +104,17 @@ public void updateCrystalsStats() {

/**
* A label that appears once currency is gained, to give the player visual feedback
* Also plays sound
* @param x Screen x coordinate
* @param y Screen y coordinate
* @param amount value to display on the pop-up
* @param offset value to offset the height of the label by
*/
public void currencyPopUp(float x , float y, int amount, int offset) {
// play sound and set the volume
long soundId = clickSound.play();
clickSound.setVolume(soundId, 0.4f);

Label label = new Label(String.format("+%d", amount), skin);
// remove label after it fades out
label.addAction(new SequenceAction(Actions.fadeOut(1.5f), Actions.removeActor()));
Expand Down
3 changes: 3 additions & 0 deletions source/core/src/main/com/csse3200/game/entities/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,7 @@ public int setLayer(int layer) {
return layer;
}

public String getName() {
return this.getClass().getSimpleName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ private void spawnPlanets() {
// Spawn desert planet
spawnPlanet(150, 150, Planets.DESERT[0], Planets.DESERT[1], "Desert", 1, (int) (timeCounter * 60) % 60 + 1);
// Spawn ice planet
spawnPlanet(150, 150, Planets.ICE[0], Planets.ICE[1],"Barren_or_Moon", 2, (int) (timeCounter * 60) % 60 + 1);
spawnPlanet(150, 150, Planets.ICE[0], Planets.ICE[1],"Barren_or_Moon", 2, (int) (timeCounter * 35) % 60 + 1);
// Spawn lava planet
spawnPlanet(200, 200, Planets.LAVA[0], Planets.LAVA[1],"Lava", 1, (int) (timeCounter * 60) % 60 + 1);
spawnPlanet(200, 200, Planets.LAVA[0], Planets.LAVA[1],"Lava", 1, (int) (timeCounter * 15) % 60 + 1);

spawnPlanetBorders();
}
Expand Down Expand Up @@ -94,15 +94,15 @@ private void spawnPlanetBorders() {
// Iterates through the planets checking for the bounding box
for (int[] planet : Planets.PLANETS) {
Rectangle planetRect = new Rectangle(planet[0], planet[1], planet[2], planet[3]);
if (planetRect.contains(mousePos.x, Gdx.graphics.getHeight() - mousePos.y)) {
if (planetRect.contains(mousePos.x, (float) Gdx.graphics.getHeight() - mousePos.y)) {
// If a planet is clicked it will load the level based on the planet
if (Gdx.input.justTouched()) {
dispose();
logger.info("Loading level {}", planet[4]);
game.setScreen(new MainGameScreen(game));
game.setScreen(new TurretSelectionScreen(game));
} else {
Sprite planetBorder = new Sprite(new Texture("planets/planetBorder.png"));
batch.draw(planetBorder, planet[0] - 2, planet[1] - 2, planet[2] + 3, planet[3] + 3);
batch.draw(planetBorder, planet[0] - 2.0f, planet[1] - 2.0f, planet[2] + 3.0f, planet[3] + 3.0f);
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions source/core/src/main/com/csse3200/game/screens/StoryScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ public void render(float delta) {
stage.draw();
}

/**
* Fixes the
* @param width
* @param height
*/
@Override
public void resize(int width, int height) {
stage.getViewport().update(width, height, true);
}

@Override
public void dispose() {
batch.dispose();
Expand Down
35 changes: 35 additions & 0 deletions source/core/src/main/com/csse3200/game/screens/TowerType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.csse3200.game.screens;

public enum TowerType {
WEAPON("images/towers/turret_deployed.png", "Weapon Tower",
"The Weapon Tower is a simple and basic turret that fires rapid shots at enemies dealing damage over time."),
TNT("images/towers/turret_deployed.png", "TNT Tower",
"The TNT Tower launches explosive projectiles, dealing area damage to groups of enemies."),
DROID("images/towers/turret_deployed.png", "Droid Tower",
"Droid Towers deploy robotic helpers that assist in combat and provide support to nearby turrets."),
WALL("images/towers/turret_deployed.png", "Wall Tower",
"The Wall Tower creates barriers to block enemy paths, slowing down their progress."),
FIRE("images/towers/turret_deployed.png", "Fire Tower",
"The Fire Tower emits flames, causing damage over time to enemies caught in its fiery radius."),
STUN("images/towers/turret_deployed.png", "Stun Tower",
"The Stun Tower releases electric shocks that temporarily immobilize and damage enemies."),
INCOME("images/towers/turret_deployed.png", "Income Tower",
"The Income Tower generates additional in-game currency over time.");

private final String imagePath;
private final String towerName;
private final String description;

TowerType(String imagePath, String towerName, String description) {
this.imagePath = imagePath;
this.towerName = towerName;
this.description = description;
}

public String getImagePath() { return imagePath; }

public String getTowerName() { return towerName; }

public String getDescription() { return description; }

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
package com.csse3200.game.screens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.csse3200.game.GdxGame;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.factories.TowerFactory;
import com.csse3200.game.physics.PhysicsService;
import com.csse3200.game.services.ResourceService;
import com.csse3200.game.services.ServiceLocator;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import java.util.*;

public class TurretSelectionScreen extends ScreenAdapter {

private static final int MAX_SELECTED_TURRETS = 5;
private Stage stage;
private List<TowerType> turretList;
private TextButton confirmButton;

private GdxGame game;

private SpriteBatch batch;

private Sprite introSprite;

private Label message;
private Label turretsPicked;
private Table table;
private static final String TEXTURE = "planets/background.png";
private Set<TowerType> selectedTurrets = new HashSet<>();

private static final Logger logger = LoggerFactory.getLogger(MainMenuScreen.class);

public TurretSelectionScreen(GdxGame game) {
this.game = game;
stage = new Stage(new ScreenViewport());
table = new Table();

// Set up the background
batch = new SpriteBatch();
Texture backgroundImage = new Texture(TEXTURE);
introSprite = new Sprite(backgroundImage);
introSprite.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

// Add all turrets to turret list
turretList = new ArrayList<>();
// Add turrets to the list
turretList.addAll(Arrays.asList(TowerType.values()));
// Restrictions can be added to the arrays i.e. map == "Forest" && level == 1 using for loop


Skin skin = new Skin(Gdx.files.internal("flat-earth/skin/flat-earth-ui.json"));
message = new Label("Select your turrets", skin);
turretsPicked = new Label("Turrets picked: ", skin);

confirmButton = new TextButton("Continue", skin);
confirmButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
game.setScreen(GdxGame.ScreenType.MAIN_GAME);
}
});

// Centered the message and turrets label
table.add(message).center().colspan(4).row();
table.add(turretsPicked).center().colspan(4).row();
int towersPerRow = 4; // Set the number of towers to display per row
int numRows = (int) Math.ceil((double)turretList.size() / towersPerRow); // Calculate the number of rows

for (int row = 0; row < numRows; row++) {
for (int col = 0; col < towersPerRow; col++) {
int index = row * towersPerRow + col;
if (index >= turretList.size()) {
break; // Ensure we don't try to access a turret beyond the list size
}

TowerType turret = turretList.get(index);

// Create a nested table for each turret
Table turretTable = new Table();
turretTable.center(); // Center the contents of the nested table

// Load the turret image
Texture turretTexture = new Texture(Gdx.files.internal(turret.getImagePath()));
Image turretImage = new Image(turretTexture);

// Add the image to the nested table
turretTable.add(turretImage).pad(10).row();

// Create a label for the turret description
Label turretDescriptionLabel = new Label(turret.getDescription(), skin);
turretDescriptionLabel.setWrap(true); // Wrap text if it's too long

// Add the description label to the nested table
turretTable.add(turretDescriptionLabel).center().width(200).pad(10).row(); // Adjust width if needed

// Create a TextButton for the turret name
TextButton turretButton = new TextButton(turret.getTowerName(), skin);
turretButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
logger.info(String.valueOf(selectedTurrets.size()));
if (selectedTurrets.size() > MAX_SELECTED_TURRETS) {
message.setText("You can only select up to 5 turrets.");
} else {
message.setText("Select your turrets");
}
if (selectedTurrets.contains(turret)) {
// Turret is already selected, unselect it
selectedTurrets.remove(turret);
// You can also change the button appearance to indicate unselection
logger.info(selectedTurrets.toString());
turretsPicked.setText("Turrets picked: " + selectedTurrets.toString());
} else if (selectedTurrets.size() == MAX_SELECTED_TURRETS) {
// Turret is not selected, but the max number of turrets has been reached
message.setText("You can only select up to 5 turrets.");
} else if (selectedTurrets.size() < MAX_SELECTED_TURRETS) {
// Turret is not selected, select it
selectedTurrets.add(turret);
turretsPicked.setText("Turrets picked: " + selectedTurrets.toString());
logger.info(selectedTurrets.toString());
}
else {
// Turret is not selected, select it
selectedTurrets.add(turret);
turretsPicked.setText("Turrets picked: " + selectedTurrets.toString());
//logger.info(selectedTurrets.toString());

// You can change the button appearance to indicate selection
}
}
});

// Add the turret name button to the nested table
turretTable.add(turretButton).center();

// Add the nested table to the main table
table.add(turretTable).pad(10).center();

// Center the contents of the main table cell
table.getCells().peek().center();
}

// Center the entire row
table.row().center();

}

// Centered the "continue" button
table.add(confirmButton).center().colspan(4).padBottom(20).row();

// Center the table within the stage
table.center();
stage.addActor(table);
table.setFillParent(true);
Gdx.input.setInputProcessor(stage);

}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
introSprite.draw(batch);
batch.end();
stage.draw();
}

public List<TowerType> getTurretList() {
return turretList;
}

@Override
public void dispose() {
stage.dispose();
}

}
Loading

0 comments on commit a8cef8f

Please sign in to comment.