diff --git a/source/core/assets/images/towers/imageedit_9_7173145411.png b/source/core/assets/images/towers/imageedit_9_7173145411.png new file mode 100644 index 000000000..c43b4675b Binary files /dev/null and b/source/core/assets/images/towers/imageedit_9_7173145411.png differ diff --git a/source/core/assets/images/turret-select/Weapon-Tower-Clicked.png b/source/core/assets/images/turret-select/Weapon-Tower-Clicked.png new file mode 100644 index 000000000..fbfbedccb Binary files /dev/null and b/source/core/assets/images/turret-select/Weapon-Tower-Clicked.png differ diff --git a/source/core/assets/images/turret-select/Weapon-Tower-Default.png b/source/core/assets/images/turret-select/Weapon-Tower-Default.png new file mode 100644 index 000000000..fff06381b Binary files /dev/null and b/source/core/assets/images/turret-select/Weapon-Tower-Default.png differ diff --git a/source/core/assets/images/turret-select/droid-tower-clicked.png b/source/core/assets/images/turret-select/droid-tower-clicked.png new file mode 100644 index 000000000..4d182496d Binary files /dev/null and b/source/core/assets/images/turret-select/droid-tower-clicked.png differ diff --git a/source/core/assets/images/turret-select/droid-tower-default.png b/source/core/assets/images/turret-select/droid-tower-default.png new file mode 100644 index 000000000..958470e53 Binary files /dev/null and b/source/core/assets/images/turret-select/droid-tower-default.png differ diff --git a/source/core/assets/images/turret-select/fire-tower-clicked.png b/source/core/assets/images/turret-select/fire-tower-clicked.png new file mode 100644 index 000000000..ce1969010 Binary files /dev/null and b/source/core/assets/images/turret-select/fire-tower-clicked.png differ diff --git a/source/core/assets/images/turret-select/fire-tower-default.png b/source/core/assets/images/turret-select/fire-tower-default.png new file mode 100644 index 000000000..318b0f138 Binary files /dev/null and b/source/core/assets/images/turret-select/fire-tower-default.png differ diff --git a/source/core/assets/images/turret-select/imageedit_2_8132799771.png b/source/core/assets/images/turret-select/imageedit_2_8132799771.png new file mode 100644 index 000000000..6fafcf62f Binary files /dev/null and b/source/core/assets/images/turret-select/imageedit_2_8132799771.png differ diff --git a/source/core/assets/images/turret-select/imageedit_4_5616741474.png b/source/core/assets/images/turret-select/imageedit_4_5616741474.png new file mode 100644 index 000000000..f877adaec Binary files /dev/null and b/source/core/assets/images/turret-select/imageedit_4_5616741474.png differ diff --git a/source/core/assets/images/turret-select/mine-tower-clicked.png b/source/core/assets/images/turret-select/mine-tower-clicked.png new file mode 100644 index 000000000..cb8eebc75 Binary files /dev/null and b/source/core/assets/images/turret-select/mine-tower-clicked.png differ diff --git a/source/core/assets/images/turret-select/mine-tower-default.png b/source/core/assets/images/turret-select/mine-tower-default.png new file mode 100644 index 000000000..64bb31cae Binary files /dev/null and b/source/core/assets/images/turret-select/mine-tower-default.png differ diff --git a/source/core/assets/images/turret-select/stun-tower-clicked.png b/source/core/assets/images/turret-select/stun-tower-clicked.png new file mode 100644 index 000000000..d620b84e7 Binary files /dev/null and b/source/core/assets/images/turret-select/stun-tower-clicked.png differ diff --git a/source/core/assets/images/turret-select/stun-tower-default.png b/source/core/assets/images/turret-select/stun-tower-default.png new file mode 100644 index 000000000..5674c9020 Binary files /dev/null and b/source/core/assets/images/turret-select/stun-tower-default.png differ diff --git a/source/core/assets/images/turret-select/tnt-tower-clicked.png b/source/core/assets/images/turret-select/tnt-tower-clicked.png new file mode 100644 index 000000000..9abee203c Binary files /dev/null and b/source/core/assets/images/turret-select/tnt-tower-clicked.png differ diff --git a/source/core/assets/images/turret-select/tnt-tower-default.png b/source/core/assets/images/turret-select/tnt-tower-default.png new file mode 100644 index 000000000..09ee3b6de Binary files /dev/null and b/source/core/assets/images/turret-select/tnt-tower-default.png differ diff --git a/source/core/assets/images/turret-select/wall-tower-clicked.png b/source/core/assets/images/turret-select/wall-tower-clicked.png new file mode 100644 index 000000000..35cf07460 Binary files /dev/null and b/source/core/assets/images/turret-select/wall-tower-clicked.png differ diff --git a/source/core/assets/images/turret-select/wall-tower-default.png b/source/core/assets/images/turret-select/wall-tower-default.png new file mode 100644 index 000000000..bc7ba42f8 Binary files /dev/null and b/source/core/assets/images/turret-select/wall-tower-default.png differ diff --git a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java index 86f2b2d71..1dec49d86 100644 --- a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java +++ b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java @@ -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() { diff --git a/source/core/src/main/com/csse3200/game/components/gamearea/CurrencyDisplay.java b/source/core/src/main/com/csse3200/game/components/gamearea/CurrencyDisplay.java index 6300b1ed1..b319165d2 100644 --- a/source/core/src/main/com/csse3200/game/components/gamearea/CurrencyDisplay.java +++ b/source/core/src/main/com/csse3200/game/components/gamearea/CurrencyDisplay.java @@ -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 @@ -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 @@ -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); } @@ -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; diff --git a/source/core/src/main/com/csse3200/game/input/BuildInputComponent.java b/source/core/src/main/com/csse3200/game/input/BuildInputComponent.java index 0846b29c2..dd7041cbc 100644 --- a/source/core/src/main/com/csse3200/game/input/BuildInputComponent.java +++ b/source/core/src/main/com/csse3200/game/input/BuildInputComponent.java @@ -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 @@ -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); } } } diff --git a/source/core/src/main/com/csse3200/game/screens/TowerType.java b/source/core/src/main/com/csse3200/game/screens/TowerType.java index 1dd3eadf5..a6f79dbdf 100644 --- a/source/core/src/main/com/csse3200/game/screens/TowerType.java +++ b/source/core/src/main/com/csse3200/game/screens/TowerType.java @@ -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;} + } diff --git a/source/core/src/main/com/csse3200/game/screens/TurretSelectionScreen.java b/source/core/src/main/com/csse3200/game/screens/TurretSelectionScreen.java index 7508ae55a..9bc096a38 100644 --- a/source/core/src/main/com/csse3200/game/screens/TurretSelectionScreen.java +++ b/source/core/src/main/com/csse3200/game/screens/TurretSelectionScreen.java @@ -4,8 +4,10 @@ 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; @@ -13,10 +15,10 @@ 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; @@ -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) { @@ -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(); @@ -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())); @@ -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(); @@ -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); @@ -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 getTurretList() { return turretList; }