diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 000000000..d067fd2a9 Binary files /dev/null and b/.DS_Store differ diff --git a/source/core/assets/images/background.jpg b/source/core/assets/images/background.jpg new file mode 100644 index 000000000..c7bb34df7 Binary files /dev/null and b/source/core/assets/images/background.jpg differ diff --git a/source/core/assets/images/background1.png b/source/core/assets/images/background1.png new file mode 100644 index 000000000..ee64172f7 Binary files /dev/null and b/source/core/assets/images/background1.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 55e0daf6e..c4d032887 100644 --- a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java +++ b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java @@ -31,13 +31,22 @@ public class ForestGameArea extends GameArea { private static final Logger logger = LoggerFactory.getLogger(ForestGameArea.class); private static final int NUM_BUILDINGS = 4; + + + // private static final int NUM_TREES = 0; + private static final int NUM_GHOSTS = 0; private static final int NUM_GRUNTS = 5; private static final int NUM_BOSS = 4; private Timer bossSpawnTimer; + // 1 minute in millisecondsz + + + private int bossSpawnInterval = 10000; // 1 minute in milliseconds + private static final int NUM_WEAPON_TOWERS = 3; private static final GridPoint2 PLAYER_SPAWN = new GridPoint2(0, 0); // Temporary spawn point for testing diff --git a/source/core/src/main/com/csse3200/game/components/gamearea/GameAreaDisplay.java b/source/core/src/main/com/csse3200/game/components/gamearea/GameAreaDisplay.java index 4d27cb2c2..ab6a9b423 100644 --- a/source/core/src/main/com/csse3200/game/components/gamearea/GameAreaDisplay.java +++ b/source/core/src/main/com/csse3200/game/components/gamearea/GameAreaDisplay.java @@ -1,39 +1,311 @@ package com.csse3200.game.components.gamearea; 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.Label; +import com.badlogic.gdx.math.Vector2; +import com.badlogic.gdx.scenes.scene2d.Actor; +import com.badlogic.gdx.scenes.scene2d.InputEvent; +import com.badlogic.gdx.scenes.scene2d.InputListener; +import com.badlogic.gdx.scenes.scene2d.Stage; +import com.badlogic.gdx.scenes.scene2d.ui.*; +import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; +import com.badlogic.gdx.scenes.scene2d.utils.DragAndDrop; +import com.badlogic.gdx.scenes.scene2d.utils.Drawable; +import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; +import com.badlogic.gdx.utils.Null; +import com.csse3200.game.components.maingame.MainGameExitDisplay; import com.csse3200.game.ui.UIComponent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import com.badlogic.gdx.scenes.scene2d.ui.Dialog; +import com.badlogic.gdx.scenes.scene2d.ui.Table; + +import java.util.concurrent.TimeUnit; /** * Displays the name of the current game area. */ public class GameAreaDisplay extends UIComponent { + private static final Logger logger = LoggerFactory.getLogger(GameAreaDisplay.class); + private static final float Z_INDEX = 2f; + // Dialog for displaying tower details + + private Vector2[] towerPositions1; + private Vector2[] towerPositions2; // Store the positions of the towers + private Vector2[] towerPositions3; // Store the positions of the towers + + private Dialog towerDetailsDialog1; + private Dialog towerDetailsDialog2; + private Dialog towerDetailsDialog3;// Dialog for displaying tower details private String gameAreaName = ""; private Label title; + private int numTowers1 = 2; // Total number of towers + private int numTowers2 = 2; // Total number of towers + private int numTowers3 = 2; // Total number of towers + private Label numTowersLabel1; + private Label numTowersLabel2; + private Label numTowersLabel3; + + private boolean[] towerMoved1; + private boolean[] towerMoved2;// Array of flags to track if each tower has been moved + private boolean[] towerMoved3;// Array of flags to track if each tower has been moved + public GameAreaDisplay(String gameAreaName) { this.gameAreaName = gameAreaName; + towerPositions1 = new Vector2[2]; // Initialize for two towers + towerMoved1 = new boolean[2]; // Initialize for two towers + + towerPositions2 = new Vector2[2]; // Initialize for two towers + towerMoved2 = new boolean[2]; // Initialize for two towers + + towerPositions3 = new Vector2[2]; // Initialize for two towers + towerMoved3 = new boolean[2]; // Initialize for two towers + + towerDetailsDialog1 = createTowerDetailsDialog(); // Create the tower details dialog + towerDetailsDialog2 = createTowerDetailsDialog(); // Create the tower details dialog + towerDetailsDialog3 = createTowerDetailsDialog(); // Create the tower details dialog } @Override public void create() { super.create(); addActors(); + final Skin skin = new Skin(); + + + + + Image[] towers1 = new Image[2]; // Create an array for two towers + Image[] towers2 = new Image[2]; // Create an array for two towers + Image[] towers3 = new Image[3]; // Create an array for two towers + + + for (int i = 0; i < 2; i++) { + // Use "building1" for the first tower and "building2" for the second tower + skin.add("default", new Label.LabelStyle(new BitmapFont(), Color.WHITE)); + skin.add("building1", new Texture("images/towers/WallTower.png")); + // Load textures for building1 and building2 + towers1[i] = new Image(skin, "building1"); + towers1[i].setBounds(Gdx.graphics.getWidth() * 40f / 100f, Gdx.graphics.getHeight() * 80f / 100f, 100, 100); + stage.addActor(towers1[i]); + + final int towerIndex1 = i; // Capture the index in a final variable for the listener + towerPositions1[towerIndex1] = new Vector2(towers1[towerIndex1].getX(), towers1[towerIndex1].getY()); + + towers1[i].addListener(new InputListener() { + private float startX, startY; + + public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { + startX = towers1[towerIndex1].getX(); + startY = towers1[towerIndex1].getY(); + Gdx.app.log("GameAreaDisplay", "Touch Down on Tower " + towerIndex1); + towerDetailsDialog1.setVisible(true); + towerDetailsDialog1.show(stage); + + return true; // Return true to indicate that the event was handled + } + + public void touchDragged(InputEvent event, float x, float y, int pointer) { + float deltaX = towers1[towerIndex1].getX() - startX; + float deltaY = towers1[towerIndex1].getY() - startY; + + // Calculate the distance moved + float distanceMoved = (float) Math.sqrt(deltaX * deltaX + deltaY * deltaY); + + // Check if the tower has been moved for a significant distance + if (!towerMoved1[towerIndex1] && distanceMoved >= 100f) { + // Decrement the number of towers and set the flag for this tower + numTowers1--; + + towerMoved1[towerIndex1] = true; // Set the flag to indicate tower movement + } + + // Implement dragging logic here + towers1[towerIndex1].moveBy(x - towers1[towerIndex1].getWidth() / 2, + y - towers1[towerIndex1].getHeight() / 2); + + towerPositions1[towerIndex1] = new Vector2(towers1[towerIndex1].getX(), towers1[towerIndex1].getY()); + towerDetailsDialog1.setPosition( + towerPositions1[towerIndex1].x + towers1[towerIndex1].getWidth(), + towerPositions1[towerIndex1].y); + + } + + public void touchUp(InputEvent event, float x, float y, int pointer, int button) { + towerDetailsDialog1.hide(); + } + }); + } + for (int i = 0; i < 2; i++) { + // Use "building1" for the first tower and "building2" for the second tower + skin.add("default", new Label.LabelStyle(new BitmapFont(), Color.WHITE)); + skin.add("building2", new Texture("images/towers/turret_deployed.png")); + towers2[i] = new Image(skin, "building2"); + towers2[i].setBounds(Gdx.graphics.getWidth() * 50f / 100f, Gdx.graphics.getHeight() * 80f / 100f, 100, 100); + stage.addActor(towers2[i]); + + final int towerIndex2 = i; // Capture the index in a final variable for the listener + towerPositions2[towerIndex2] = new Vector2(towers2[towerIndex2].getX(), towers2[towerIndex2].getY()); + + towers2[i].addListener(new InputListener() { + private float startX, startY; + + public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { + startX = towers2[towerIndex2].getX(); + startY = towers2[towerIndex2].getY(); + Gdx.app.log("GameAreaDisplay", "Touch Down on Tower " + towerIndex2); + towerDetailsDialog2.setVisible(true); + towerDetailsDialog2.show(stage); + return true; // Return true to indicate that the event was handled + } + + public void touchDragged(InputEvent event, float x, float y, int pointer) { + float deltaX = towers2[towerIndex2].getX() - startX; + float deltaY = towers2[towerIndex2].getY() - startY; + + // Calculate the distance moved + float distanceMoved = (float) Math.sqrt(deltaX * deltaX + deltaY * deltaY); + + // Check if the tower has been moved for a significant distance + if (!towerMoved2[towerIndex2] && distanceMoved >= 100f) { + // Decrement the number of towers and set the flag for this tower + numTowers2--; + numTowersLabel2.setText("Towers: " + numTowers2); + towerMoved2[towerIndex2] = true; // Set the flag to indicate tower movement + } + + // Implement dragging logic here + towers2[towerIndex2].moveBy(x - towers2[towerIndex2].getWidth() / 2, + y - towers2[towerIndex2].getHeight() / 2); + + towerPositions2[towerIndex2] = new Vector2(towers2[towerIndex2].getX(), towers2[towerIndex2].getY()); + towerDetailsDialog2.setPosition( + towerPositions2[towerIndex2].x + towers2[towerIndex2].getWidth(), + towerPositions2[towerIndex2].y + ); + } + + public void touchUp(InputEvent event, float x, float y, int pointer, int button) { + towerDetailsDialog2.hide(); + } + }); + } + + for (int i = 0; i < 2; i++) { + // Use "building1" for the first tower and "building2" for the second tower + skin.add("default", new Label.LabelStyle(new BitmapFont(), Color.WHITE)); + skin.add("building3", new Texture("images/towers/mine_tower.png")); + // Load textures for building1 and building2 + towers3[i] = new Image(skin, "building3"); + towers3[i].setBounds(Gdx.graphics.getWidth() * 60f / 100f, Gdx.graphics.getHeight() * 80f / 100f, 100, 100); + stage.addActor(towers3[i]); + + final int towerIndex3 = i; // Capture the index in a final variable for the listener + towerPositions3[towerIndex3] = new Vector2(towers3[towerIndex3].getX(), towers3[towerIndex3].getY()); + + towers3[i].addListener(new InputListener() { + private float startX, startY; + + public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { + startX = towers3[towerIndex3].getX(); + startY = towers3[towerIndex3].getY(); + Gdx.app.log("GameAreaDisplay", "Touch Down on Tower " + towerIndex3); + towerDetailsDialog3.setVisible(true); + towerDetailsDialog3.show(stage); + return true; // Return true to indicate that the event was handled + } + + public void touchDragged(InputEvent event, float x, float y, int pointer) { + float deltaX = towers3[towerIndex3].getX() - startX; + float deltaY = towers3[towerIndex3].getY() - startY; + + // Calculate the distance moved + float distanceMoved = (float) Math.sqrt(deltaX * deltaX + deltaY * deltaY); + + // Check if the tower has been moved for a significant distance + if (!towerMoved3[towerIndex3] && distanceMoved >= 100f) { + // Decrement the number of towers and set the flag for this tower + numTowers3--; + + towerMoved3[towerIndex3] = true; // Set the flag to indicate tower movement + } + + // Implement dragging logic here + towers3[towerIndex3].moveBy(x - towers3[towerIndex3].getWidth() / 2, + y - towers3[towerIndex3].getHeight() / 2); + + towerPositions3[towerIndex3] = new Vector2(towers3[towerIndex3].getX(), towers3[towerIndex3].getY()); + towerDetailsDialog3.setPosition( + towerPositions3[towerIndex3].x + towers3[towerIndex3].getWidth(), + towerPositions3[towerIndex3].y + ); + + } + + public void touchUp(InputEvent event, float x, float y, int pointer, int button) { + towerDetailsDialog3.hide(); + } + }); + } + + // Create and add the label for the number of towers + numTowersLabel1 = new Label("TowersA: " + numTowers1, skin); + numTowersLabel1.setPosition(Gdx.graphics.getWidth() * 41f / 100f, Gdx.graphics.getHeight() * 75f / 100f); // Adjust the position as needed + stage.addActor(numTowersLabel1); + + numTowersLabel2 = new Label("TowersB: " + numTowers2, skin); + numTowersLabel2.setPosition(Gdx.graphics.getWidth() * 51f / 100f, Gdx.graphics.getHeight() * 75f / 100f); // Adjust the position as needed + stage.addActor(numTowersLabel2); + + numTowersLabel3 = new Label("TowersC: " + numTowers3, skin); + numTowersLabel3.setPosition(Gdx.graphics.getWidth() * 61f / 100f, Gdx.graphics.getHeight() * 75f / 100f); // Adjust the position as needed + stage.addActor(numTowersLabel3); + } + + + + public void render(float delta) { + // ... other rendering logic ... + + // Update the stage + stage.act(delta); + stage.draw(); } + private Dialog createTowerDetailsDialog() { + Skin skin = new Skin(Gdx.files.internal("flat-earth/skin/flat-earth-ui.json")); + // Register a label style named "default" with the skin + Label.LabelStyle labelStyle = new Label.LabelStyle(); + labelStyle.font = new BitmapFont(); + labelStyle.fontColor = Color.WHITE; + skin.add("default", labelStyle); + + // Create the dialog using the registered label style + Dialog dialog = new Dialog("Tower Details", skin,"default"); + dialog.text("Health: 100"); // Set tower health here + dialog.getContentTable().row(); + dialog.text("Attack: 50"); // Set tower attack here + dialog.button("Close"); + dialog.setVisible(false); // Hide the dialog initially + return dialog; + } private void addActors() { title = new Label(this.gameAreaName, skin, "large"); stage.addActor(title); } @Override - public void draw(SpriteBatch batch) { + public void draw(SpriteBatch batch) { int screenHeight = Gdx.graphics.getHeight(); - float offsetX = 0f; - float offsetY = 0f; + float offsetX = 10f; + float offsetY = 30f; title.setPosition(offsetX, screenHeight - offsetY); + } @Override @@ -41,4 +313,4 @@ public void dispose() { super.dispose(); title.remove(); } -} +} \ No newline at end of file diff --git a/source/core/src/main/com/csse3200/game/components/maingame/MainGameExitDisplay.java b/source/core/src/main/com/csse3200/game/components/maingame/MainGameExitDisplay.java index 105b30874..ccfb54efb 100644 --- a/source/core/src/main/com/csse3200/game/components/maingame/MainGameExitDisplay.java +++ b/source/core/src/main/com/csse3200/game/components/maingame/MainGameExitDisplay.java @@ -1,5 +1,6 @@ package com.csse3200.game.components.maingame; +import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.ui.Table; @@ -7,8 +8,20 @@ import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.csse3200.game.ui.UIComponent; import org.slf4j.Logger; +import com.badlogic.gdx.graphics.Texture; import org.slf4j.LoggerFactory; +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.scenes.scene2d.InputEvent; +import com.badlogic.gdx.scenes.scene2d.ui.Image; +import com.badlogic.gdx.scenes.scene2d.ui.Label; +import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle; +import com.badlogic.gdx.scenes.scene2d.ui.Skin; +import com.badlogic.gdx.scenes.scene2d.utils.DragAndDrop; +import com.badlogic.gdx.scenes.scene2d.utils.DragAndDrop.Payload; +import com.badlogic.gdx.scenes.scene2d.utils.DragAndDrop.Source; +import com.badlogic.gdx.utils.Null; + /** * Displays a button to exit the Main Game screen to the Main Menu screen. */ @@ -19,8 +32,43 @@ public class MainGameExitDisplay extends UIComponent { @Override public void create() { + super.create(); addActors(); + final Skin skin = new Skin(); + skin.add("default", new LabelStyle(new BitmapFont(), Color.WHITE)); + skin.add("badlogic", new Texture("images/towers/turret_deployed.png")); + + Image sourceImage = new Image(skin, "badlogic"); + sourceImage.setBounds(600, 900, 100, 100); +// stage.addActor(sourceImage); + +// Label dragTowerLabel = new Label("Drag Tower", skin); // The text you want to display +// dragTowerLabel.setPosition(610, 890); // Adjust the position as needed +// stage.addActor(dragTowerLabel); + + + DragAndDrop dragAndDrop = new DragAndDrop(); + dragAndDrop.addSource(new Source(sourceImage) { + @Null + public Payload dragStart (InputEvent event, float x, float y, int pointer) { + Payload payload = new Payload(); + payload.setObject("Some payload!"); + + payload.setDragActor(getActor()); + + Label validLabel = new Label("Some payload!", skin); + validLabel.setColor(0, 1, 0, 1); + payload.setValidDragActor(validLabel); + + Label invalidLabel = new Label("Some payload!", skin); + invalidLabel.setColor(1, 0, 0, 1); + payload.setInvalidDragActor(invalidLabel); + + return payload; + } + }); + } private void addActors() { diff --git a/source/core/src/main/com/csse3200/game/components/mainmenu/MainMenuDisplay.java b/source/core/src/main/com/csse3200/game/components/mainmenu/MainMenuDisplay.java index d15392b23..99d544362 100644 --- a/source/core/src/main/com/csse3200/game/components/mainmenu/MainMenuDisplay.java +++ b/source/core/src/main/com/csse3200/game/components/mainmenu/MainMenuDisplay.java @@ -1,5 +1,6 @@ package com.csse3200.game.components.mainmenu; +import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.scenes.scene2d.Actor; @@ -7,6 +8,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; +import com.csse3200.game.GdxGame; import com.csse3200.game.services.ServiceLocator; import com.csse3200.game.ui.UIComponent; import org.slf4j.Logger; @@ -16,93 +18,110 @@ * A ui component for displaying the Main menu. */ public class MainMenuDisplay extends UIComponent { - private static final Logger logger = LoggerFactory.getLogger(MainMenuDisplay.class); - private static final float Z_INDEX = 2f; - private Table table; - - @Override - public void create() { - super.create(); - addActors(); - } - - private void addActors() { - table = new Table(); - table.setFillParent(true); - Image title = - new Image( - ServiceLocator.getResourceService() - .getAsset("images/ui/Logo2.png", Texture.class)); - - TextButton startBtn = new TextButton("Start", skin); - TextButton loadBtn = new TextButton("Help", skin); - TextButton settingsBtn = new TextButton("Settings", skin); - TextButton exitBtn = new TextButton("Quit", skin); - - // Triggers an event when the button is pressed - startBtn.addListener( - new ChangeListener() { - @Override - public void changed(ChangeEvent changeEvent, Actor actor) { - logger.debug("Start button clicked"); - entity.getEvents().trigger("start"); - } - }); - - loadBtn.addListener( - new ChangeListener() { - @Override - public void changed(ChangeEvent changeEvent, Actor actor) { - logger.debug("Load button clicked"); - entity.getEvents().trigger("load"); - } - }); - - settingsBtn.addListener( - new ChangeListener() { - @Override - public void changed(ChangeEvent changeEvent, Actor actor) { - logger.debug("Settings button clicked"); - entity.getEvents().trigger("settings"); - } - }); - - exitBtn.addListener( - new ChangeListener() { - @Override - public void changed(ChangeEvent changeEvent, Actor actor) { - - logger.debug("Exit button clicked"); - entity.getEvents().trigger("exit"); - } - }); - - table.add(title); - table.row(); - table.add(startBtn).padTop(30f); - table.row(); - table.add(loadBtn).padTop(15f); - table.row(); - table.add(settingsBtn).padTop(15f); - table.row(); - table.add(exitBtn).padTop(15f); - - stage.addActor(table); - } - - @Override - public void draw(SpriteBatch batch) { - // draw is handled by the stage - } - - @Override - public float getZIndex() { - return Z_INDEX; - } - - @Override - public void dispose() { - table.clear(); - super.dispose(); - } + + private static final Logger logger = LoggerFactory.getLogger(MainMenuDisplay.class); + private static final float Z_INDEX = 2f; + private Table table; + private Table table1; + + + + + @Override + public void create() { + super.create(); + addActors(); + } + + + private void addActors() { + table = new Table(); + table1=new Table(); + table.setFillParent(true); + table1.setFillParent(true); + Image title = + new Image( + ServiceLocator.getResourceService() + .getAsset("images/background1.png", Texture.class)); + title.setWidth(Gdx.graphics.getWidth()); + title.setHeight(Gdx.graphics.getHeight()); + title.setPosition(0,0); + + + + + TextButton startBtn = new TextButton("Start", skin); + TextButton loadBtn = new TextButton("Help", skin); + TextButton settingsBtn = new TextButton("Settings", skin); + TextButton exitBtn = new TextButton("Quit", skin); + + // Triggers an event when the button is pressed + startBtn.addListener( + new ChangeListener() { + @Override + public void changed(ChangeEvent changeEvent, Actor actor) { + logger.debug("Start button clicked"); + entity.getEvents().trigger("start"); + } + }); + + loadBtn.addListener( + new ChangeListener() { + @Override + public void changed(ChangeEvent changeEvent, Actor actor) { + logger.debug("Load button clicked"); + entity.getEvents().trigger("load"); + } + }); + + settingsBtn.addListener( + new ChangeListener() { + @Override + public void changed(ChangeEvent changeEvent, Actor actor) { + logger.debug("Settings button clicked"); + entity.getEvents().trigger("settings"); + } + }); + + exitBtn.addListener( + new ChangeListener() { + @Override + public void changed(ChangeEvent changeEvent, Actor actor) { + + logger.debug("Exit button clicked"); + entity.getEvents().trigger("exit"); + } + }); + + + table.add(title); + table1.row(); + table1.add(startBtn).padTop(30f); + table1.row(); + table1.add(loadBtn).padTop(15f); + table1.row(); + table1.add(settingsBtn).padTop(15f); + table1.row(); + table1.add(exitBtn).padTop(15f); + + stage.addActor(table); + stage.addActor(table1); + } + + + @Override + public void draw(SpriteBatch batch) { + // draw is handled by the stage + } + + @Override + public float getZIndex() { + return Z_INDEX; + } + + @Override + public void dispose() { + table.clear(); + super.dispose(); + } } diff --git a/source/core/src/main/com/csse3200/game/components/player/PlayerStatsDisplay.java b/source/core/src/main/com/csse3200/game/components/player/PlayerStatsDisplay.java index 4fe787609..da9c329fc 100644 --- a/source/core/src/main/com/csse3200/game/components/player/PlayerStatsDisplay.java +++ b/source/core/src/main/com/csse3200/game/components/player/PlayerStatsDisplay.java @@ -1,14 +1,16 @@ package com.csse3200.game.components.player; +import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; -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.badlogic.gdx.scenes.scene2d.ui.*; +import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.csse3200.game.components.CombatStatsComponent; import com.csse3200.game.services.ServiceLocator; import com.csse3200.game.ui.UIComponent; +import com.badlogic.gdx.scenes.scene2d.InputEvent; + /** * A ui component for displaying player stats, e.g. health. */ @@ -45,7 +47,7 @@ private void addActors() { // Health text int health = entity.getComponent(CombatStatsComponent.class).getHealth(); CharSequence healthText = String.format("Health: %d", health); - healthLabel = new Label(healthText, skin, "large"); + healthLabel = new Label(healthText, skin, "default"); table.add(heartImage).size(heartSideLength).pad(5); table.add(healthLabel); @@ -61,16 +63,64 @@ public void draw(SpriteBatch batch) { * Updates the player's health on the ui. * @param health player health */ + // Inside the PlayerStatsDisplay class public void updatePlayerHealthUI(int health) { CharSequence text = String.format("Health: %d", health); healthLabel.setText(text); + + if (health == 0) { + // Player's health is zero or negative, trigger game over. + showGameOverPopup(); + } + } + + private void showGameOverPopup() { + // Create a Dialog pop-up for game over. + Dialog gameOverDialog = new Dialog("Game Over", skin); + + // Add a label with the game over message. + gameOverDialog.text("Your health reached 0. The game is over."); + + // Add a button to restart the game or exit. + + TextButton exitButton = new TextButton("Exit", skin); + + + exitButton.addListener(new ClickListener() { + @Override + public void clicked(InputEvent event, float x, float y) { + // Handle exiting the game (e.g., return to the main menu or close the app). + // You can use Gdx.app.exit() to close the app gracefully. + Gdx.app.exit(); + } + }); + + + gameOverDialog.button(exitButton); + + // Make the dialog modal (disables interactions with the game underneath). + gameOverDialog.setModal(true); + + // Calculate the position to center the dialog on the screen. + float dialogWidth = stage.getWidth() * 0.6f; // Adjust as needed + float dialogHeight = stage.getHeight() * 0.4f; // Adjust as needed + float dialogX = (stage.getWidth() - dialogWidth) / 2; + float dialogY = (stage.getHeight() - dialogHeight) / 2; + + // Set the dialog's size and position. + gameOverDialog.setSize(dialogWidth, dialogHeight); + gameOverDialog.setPosition(dialogX, dialogY); + + // Show the dialog on the stage. + stage.addActor(gameOverDialog); } + @Override public void dispose() { super.dispose(); heartImage.remove(); healthLabel.remove(); } -} +} \ No newline at end of file diff --git a/source/core/src/main/com/csse3200/game/screens/MainMenuScreen.java b/source/core/src/main/com/csse3200/game/screens/MainMenuScreen.java index 7c3dd3d4d..7536d673c 100644 --- a/source/core/src/main/com/csse3200/game/screens/MainMenuScreen.java +++ b/source/core/src/main/com/csse3200/game/screens/MainMenuScreen.java @@ -31,7 +31,7 @@ public class MainMenuScreen extends ScreenAdapter { private final Renderer renderer; private Texture backgroundTexture; private final SpriteBatch batch; - private static final String[] mainMenuTextures = {"images/ui/Logo2.png"}; + private static final String[] mainMenuTextures = {"images/background1.png"}; public MainMenuScreen(GdxGame game) { this.game = game; @@ -97,7 +97,7 @@ private void loadAssets() { logger.debug("Loading assets"); ResourceService resourceService = ServiceLocator.getResourceService(); resourceService.loadTextures(mainMenuTextures); - backgroundTexture = new Texture("images/background/background1.png"); // Load the background image + backgroundTexture = new Texture("images/background1.png"); ServiceLocator.getResourceService().loadAll(); }