Skip to content

Commit

Permalink
merged team-5--Turret-Selection into team-2-sound
Browse files Browse the repository at this point in the history
  • Loading branch information
The-AhmadAA committed Oct 2, 2023
2 parents 34f3647 + 1863c2b commit 483b51d
Show file tree
Hide file tree
Showing 22 changed files with 119 additions and 76 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 9 additions & 11 deletions source/core/src/main/com/csse3200/game/areas/ForestGameArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,24 +341,22 @@ private void spawnTerrain() {
new GridPoint2(0, 0),
false,
false);
// // Right
// spawnEntityAt(
// ObstacleFactory.createWall(WALL_WIDTH, worldBounds.y),
// new GridPoint2(tileBounds.x, 0),
// false,
// false);
// Top
// Right
spawnEntityAt(
ObstacleFactory.createWall(worldBounds.x, WALL_WIDTH * 0),
new GridPoint2(0, tileBounds.y),
ObstacleFactory.createWall(WALL_WIDTH, worldBounds.y),
new GridPoint2(tileBounds.x, 0),
false,
false);
// Bottom
// Top
spawnEntityAt(
ObstacleFactory.createWall(worldBounds.x, WALL_WIDTH * 0),
new GridPoint2(0, 0),
new GridPoint2(0, tileBounds.y),
false,
false);
// Bottom
Entity wall = ObstacleFactory.createWall(worldBounds.x, WALL_WIDTH * 0);
wall.setPosition(0,-0.1f);
ServiceLocator.getEntityService().register(wall);
}

private Entity spawnPlayer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.csse3200.game.services.ServiceLocator;
import com.csse3200.game.ui.UIComponent;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import org.w3c.dom.Text;

/**
* A UI component for displaying the currency owned
Expand All @@ -29,6 +30,7 @@ public class CurrencyDisplay extends UIComponent {
private TextButton crystalsTb;
private Sound clickSound;
private Sound buildSound;
private TextButton test;

/**
* Adds actors to stage
Expand All @@ -55,9 +57,11 @@ private void addActors() {
ServiceLocator.getCurrencyService().getScrap().getAmount());
crystalsTb = createButton("images/economy/crystalBanner.png",
ServiceLocator.getCurrencyService().getCrystal().getAmount());
test = createButton("images/ui/Sprites/UI_Glass_Frame_Standard_01a.png", 100);

table.add(scrapsTb).width(scrapsTb.getWidth() * 0.5f).height(scrapsTb.getHeight() * 0.5f);
table.add(crystalsTb).width(crystalsTb.getWidth() * 0.5f).height(crystalsTb.getHeight() * 0.5f);
table.add(test).width(test.getWidth() * 0.5f).height(test.getHeight() * 0.5f);
stage.addActor(table);
}

Expand All @@ -71,7 +75,7 @@ private TextButton createButton(String imageFilePath, int value) {
tb.setDisabled(true);
tb.getLabel().setAlignment(Align.right);

tb.pad(0, 0, 0, 50);
tb.pad(0, 0, 0, 0);
tb.setTransform(true);

return tb;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public class BuildInputComponent extends InputComponent {
private final EntityService entityService;
private final Camera camera;
int value = -100;
private TowerType tower;

/**
* Constructor for the BuildInputComponent
Expand Down Expand Up @@ -76,52 +75,48 @@ public boolean touchDown(int screenX, int screenY, int pointer, int button) {
return false;
}

/**
* Instantiates and spawns the selected tower at the given x y coordinates on the tile map. Assumes that the given
* x and y coordinate is valid and that the TowerType exists in the CurrencyService.
*
* @param x x-coordinate int value
* @param y y-coordinate int value
*/
public void buildTower(int x, int y) {
// fetch the currently set TowerType in the currency service, and its associated build cost.
TowerType tower = ServiceLocator.getCurrencyService().getTower();
Entity newTower;
int cost = Integer.parseInt(ServiceLocator.getCurrencyService().getTower().getPrice()) * -1;
Entity newTower = null;

// build the selected tower
if (tower != null) {
switch (tower) {
case WEAPON:
newTower = TowerFactory.createWeaponTower();
newTower.setPosition(x, y);
ServiceLocator.getEntityService().register(newTower);
// ServiceLocator.getCurrencyService().getDisplay().currencyPopUp(cursorPosition.x, cursorPosition.y, value, 10);Entity newTower = TowerFactory.createWeaponTower();
break;
case INCOME:
newTower = TowerFactory.createIncomeTower();
newTower.setPosition(x, y);
ServiceLocator.getEntityService().register(newTower);
// ServiceLocator.getCurrencyService().getDisplay().currencyPopUp(cursorPosition.x, cursorPosition.y, value, 10);
break;
case TNT:
newTower = TowerFactory.createTNTTower();
newTower.setPosition(x, y);
ServiceLocator.getEntityService().register(newTower);
// ServiceLocator.getCurrencyService().getDisplay().currencyPopUp(cursorPosition.x, cursorPosition.y, value, 10);Entity newTower = TowerFactory.createWeaponTower();
break;
case DROID:
newTower = TowerFactory.createDroidTower();
newTower.setPosition(x, y);
ServiceLocator.getEntityService().register(newTower);
// ServiceLocator.getCurrencyService().getDisplay().currencyPopUp(cursorPosition.x, cursorPosition.y, value, 10);
break;
case WALL:
newTower = TowerFactory.createWallTower();
newTower.setPosition(x, y);
ServiceLocator.getEntityService().register(newTower);
// ServiceLocator.getCurrencyService().getDisplay().currencyPopUp(cursorPosition.x, cursorPosition.y, value, 10);
break;
case FIRE:
newTower = TowerFactory.createFireTower();
newTower.setPosition(x, y);
ServiceLocator.getEntityService().register(newTower);
// ServiceLocator.getCurrencyService().getDisplay().currencyPopUp(cursorPosition.x, cursorPosition.y, value, 10);Entity newTower = TowerFactory.createWeaponTower();
break;
case STUN:
newTower = TowerFactory.createStunTower();
newTower.setPosition(x, y);
ServiceLocator.getEntityService().register(newTower);
// ServiceLocator.getCurrencyService().getDisplay().currencyPopUp(cursorPosition.x, cursorPosition.y, value, 10);
}
if (newTower != null) {
newTower.setPosition(x, y);
ServiceLocator.getEntityService().register(newTower);
// show a popup that reflects the cost of the build
ServiceLocator.getCurrencyService().getDisplay().currencyPopUp(x, y, cost, 10);
}
}
}
Expand Down
51 changes: 32 additions & 19 deletions source/core/src/main/com/csse3200/game/screens/TowerType.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,48 @@
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;
WEAPON("Weapon Tower", "The Weapon Tower is a simple and basic turret that fires rapid shots at enemies dealing damage over time.",
0, "0", "images/turret-select/Weapon-Tower-Default.png", "images/turret-select/Weapon-Tower-Clicked.png"),
TNT("TNT Tower", "The TNT Tower launches explosive projectiles, dealing area damage to groups of enemies.",
1, "0", "images/turret-select/tnt-tower-default.png", "images/turret-select/tnt-tower-clicked.png"),
DROID("Droid Tower", "Droid Towers deploy robotic helpers that assist in combat and provide support to nearby turrets.",
2, "0", "images/turret-select/droid-tower-default.png", "images/turret-select/droid-tower-clicked.png"),
WALL("Wall Tower", "The Wall Tower creates barriers to block enemy paths, slowing down their progress.",
3, "100", "images/turret-select/wall-tower-default.png", "images/turret-select/wall-tower-clicked.png"),
FIRE("Fire Tower", "The Fire Tower emits flames, causing damage over time to enemies caught in its fiery radius.",
4, "0", "images/turret-select/fire-tower-default.png", "images/turret-select/fire-tower-clicked.png"),
STUN("Stun Tower", "The Stun Tower releases electric shocks that temporarily immobilize and damage enemies.",
5, "1000", "images/turret-select/stun-tower-default.png", "images/turret-select/stun-tower-clicked.png"),
INCOME("Income Tower", "The Income Tower generates additional in-game currency over time.",
5, "0", "images/turret-select/mine-tower-default.png", "images/turret-select/mine-tower-clicked.png");

private final String towerName;
private final String description;
private final int id;
private final String cost;
private final String defaultImage;
private final String clickedImage;


TowerType(String imagePath, String towerName, String description) {
this.imagePath = imagePath;
TowerType(String towerName, String description, int id, String cost, String defaultImage, String clickedImage) {
this.towerName = towerName;
this.description = description;
this.id = id;
this.cost = cost;
this.defaultImage = defaultImage;
this.clickedImage = clickedImage;
}

public String getImagePath() { return imagePath; }
public int getID() { return id; }

public String getTowerName() { return towerName; }

public String getDescription() { return description; }

public String getPrice() { return cost; }

public String getDefaultImage() {return defaultImage;}

public String getClickedImage() {return clickedImage;}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
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.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.csse3200.game.GdxGame;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.csse3200.game.services.ServiceLocator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -67,7 +69,12 @@ public TurretSelectionScreen(GdxGame game) {
message = new Label("Select your turrets", skin);
turretsPicked = new Label("Turrets picked: ", skin);

confirmButton = new TextButton("Continue", skin);
confirmButton = createButton("images/turret-select/imageedit_4_5616741474.png",
"images/ui/Sprites/UI_Glass_Button_Large_Press_01a1.png", "Continue");
Drawable pressDrawable = new TextureRegionDrawable(new TextureRegion(
new Texture("images/ui/Sprites/UI_Glass_Button_Large_Press_01a1.png")));
confirmButton.getStyle().down = pressDrawable;
confirmButton.pad(0,0,6,0);
confirmButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
Expand All @@ -77,6 +84,7 @@ public void clicked(InputEvent event, float x, float y) {
}
});


// Centered the message and turrets label
table.add(message).center().colspan(4).row();
table.add(turretsPicked).center().colspan(4).row();
Expand All @@ -96,23 +104,11 @@ public void clicked(InputEvent event, float x, float y) {
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() {
TextButton button = createButton(turret.getDefaultImage(),
turret.getClickedImage(), turret.getPrice());

button.pad(103, 15, 0, 0);
button.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
logger.info(String.valueOf(selectedTurrets.size()));
Expand Down Expand Up @@ -147,8 +143,8 @@ public void clicked(InputEvent event, float x, float y) {
}
});

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

// Add the nested table to the main table
table.add(turretTable).pad(10).center();
Expand All @@ -165,6 +161,7 @@ public void clicked(InputEvent event, float x, float y) {
// Centered the "continue" button
table.add(confirmButton).center().colspan(4).padBottom(20).row();


// Center the table within the stage
table.center();
stage.addActor(table);
Expand All @@ -182,6 +179,42 @@ public void render(float delta) {
stage.draw();
}

private TextButton createButton(String defaultImageFilePath, String alternateImageFilePath, String cost) {
Drawable defaultDrawable = new TextureRegionDrawable(new TextureRegion(new Texture(defaultImageFilePath)));
Drawable alternateDrawable = new TextureRegionDrawable(new TextureRegion(new Texture(alternateImageFilePath)));

TextButton.TextButtonStyle buttonStyle = new TextButton.TextButtonStyle();
buttonStyle.font = new BitmapFont(); // Set your desired font
buttonStyle.up = defaultDrawable; // Default state

// Create button
TextButton tb = new TextButton(String.format(cost), buttonStyle);

// Add click listener to toggle the image
final boolean[] isDefaultImage = {true}; // Keep track of the image state

tb.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);

// Toggle the image
if (isDefaultImage[0]) {
tb.getStyle().up = alternateDrawable;
} else {
tb.getStyle().up = defaultDrawable;
}

// Update the image state
isDefaultImage[0] = !isDefaultImage[0];
}
});

tb.setDisabled(true);

return tb;
}

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

0 comments on commit 483b51d

Please sign in to comment.