diff --git a/source/core/assets/images/lose-screen/desktop-wallpaper-simple-stars-video-background-loop-black-and-white-aesthetic-space.jpg b/source/core/assets/images/lose-screen/desktop-wallpaper-simple-stars-video-background-loop-black-and-white-aesthetic-space.jpg new file mode 100644 index 000000000..52ca41115 Binary files /dev/null and b/source/core/assets/images/lose-screen/desktop-wallpaper-simple-stars-video-background-loop-black-and-white-aesthetic-space.jpg differ diff --git a/source/core/assets/images/lose-screen/lose-bg.jpg b/source/core/assets/images/lose-screen/lose-bg.jpg new file mode 100644 index 000000000..52ca41115 Binary files /dev/null and b/source/core/assets/images/lose-screen/lose-bg.jpg differ diff --git a/source/core/src/main/com/csse3200/game/GdxGame.java b/source/core/src/main/com/csse3200/game/GdxGame.java index 146fb71c7..42fdb3f7b 100644 --- a/source/core/src/main/com/csse3200/game/GdxGame.java +++ b/source/core/src/main/com/csse3200/game/GdxGame.java @@ -3,6 +3,7 @@ import com.badlogic.gdx.Game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Screen; +import com.csse3200.game.components.CombatStatsComponent; import com.csse3200.game.files.UserSettings; import com.csse3200.game.screens.*; import org.slf4j.Logger; @@ -74,13 +75,15 @@ private Screen newScreen(ScreenType screenType) { return new StoryScreen(this); case LEVEL_SELECT: return new LevelSelectScreen(this); + case LOSING_SCREEN: + return new LosingScreen(this); default: return null; } } public enum ScreenType { - MAIN_MENU, MAIN_GAME, SETTINGS, STORY_SCREEN, LEVEL_SELECT + MAIN_MENU, MAIN_GAME, SETTINGS, STORY_SCREEN, LEVEL_SELECT, LOSING_SCREEN } /** diff --git a/source/core/src/main/com/csse3200/game/components/maingame/MainGameActions.java b/source/core/src/main/com/csse3200/game/components/maingame/MainGameActions.java index cebeab67e..37dd07117 100644 --- a/source/core/src/main/com/csse3200/game/components/maingame/MainGameActions.java +++ b/source/core/src/main/com/csse3200/game/components/maingame/MainGameActions.java @@ -20,6 +20,7 @@ public MainGameActions(GdxGame game) { @Override public void create() { entity.getEvents().addListener("exit", this::onExit); + entity.getEvents().addListener("lose", this::onLose); } /** @@ -29,4 +30,8 @@ private void onExit() { logger.info("Exiting main game screen"); game.setScreen(GdxGame.ScreenType.MAIN_MENU); } + + private void onLose() { + game.setScreen(GdxGame.ScreenType.LOSING_SCREEN); + } } diff --git a/source/core/src/main/com/csse3200/game/components/maingame/MainGameLoseDisplay.java b/source/core/src/main/com/csse3200/game/components/maingame/MainGameLoseDisplay.java new file mode 100644 index 000000000..9828ee2a7 --- /dev/null +++ b/source/core/src/main/com/csse3200/game/components/maingame/MainGameLoseDisplay.java @@ -0,0 +1,64 @@ +package com.csse3200.game.components.maingame; + +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.scenes.scene2d.Actor; +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.ui.UIComponent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Displays a button to exit the Main Game screen to the Main Menu screen. + */ +public class MainGameLoseDisplay extends UIComponent { + private static final Logger logger = LoggerFactory.getLogger(MainGameExitDisplay.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.top().right(); + table.setFillParent(true); + + TextButton mainMenuBtn = new TextButton("Lose", skin); + + // Triggers an event when the button is pressed. + mainMenuBtn.addListener( + new ChangeListener() { + @Override + public void changed(ChangeEvent changeEvent, Actor actor) { + logger.debug("Quit button clicked"); + entity.getEvents().trigger("lose"); + } + }); + + table.add(mainMenuBtn).padTop(-100).padBottom(-500); + + 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(); + } +} + diff --git a/source/core/src/main/com/csse3200/game/screens/LosingScreen.java b/source/core/src/main/com/csse3200/game/screens/LosingScreen.java new file mode 100644 index 000000000..354046edc --- /dev/null +++ b/source/core/src/main/com/csse3200/game/screens/LosingScreen.java @@ -0,0 +1,109 @@ +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.BitmapFont; +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.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.viewport.ScreenViewport; +import com.csse3200.game.GdxGame; +import com.csse3200.game.screens.text.AnimatedText; +import com.csse3200.game.services.ServiceLocator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class LosingScreen extends ScreenAdapter { + private final GdxGame game; + private SpriteBatch batch; + private Texture introImage; + private Sprite introSprite; + + private static final String TEXTURE = "planets/background.png"; + private static final String INTRO_TEXT = """ + The aliens gained control. You lose! + """; + + private BitmapFont font; + private AnimatedText text; + private Stage stage; + private TextButton exitButton; + private TextButton mainMenuButton; + private TextButton playAgainButton; + + public LosingScreen(GdxGame game) { + this.game = game; + font = new BitmapFont(); + text = new AnimatedText(INTRO_TEXT, font, 0.05f); + font.getData().setScale(2, 2); + } + + @Override + public void show() { + batch = new SpriteBatch(); + introImage = new Texture(TEXTURE); + introSprite = new Sprite(introImage); + introSprite.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); + + stage = new Stage(new ScreenViewport()); + Gdx.input.setInputProcessor(stage); + + Skin skin = new Skin(Gdx.files.internal("flat-earth/skin/flat-earth-ui.json")); + exitButton = new TextButton("Exit Game", skin); + exitButton.addListener(new ClickListener(){ + public void clicked(InputEvent even, float x, float y) { + game.exit(); + } + }); + mainMenuButton = new TextButton("Back to Main Menu", skin); + mainMenuButton.addListener(new ClickListener() { + @Override + public void clicked(InputEvent event, float x, float y) { + game.setScreen(GdxGame.ScreenType.MAIN_MENU); + } + + }); + + playAgainButton = new TextButton("Play Again", skin); + playAgainButton.addListener(new ClickListener() { + public void clicked(InputEvent even, float x, float y) { + game.setScreen(GdxGame.ScreenType.MAIN_GAME); + } + }); + + Table table = new Table(); + table.setFillParent(true); + table.add(exitButton).padTop(-100).row(); + table.add(mainMenuButton).padTop(-200).row(); + table.add(playAgainButton).padTop(-300).row(); + stage.addActor(table); + } + + @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); + text.update(); + text.draw(batch, 730, 800); // Adjust the position + batch.end(); + + stage.draw(); + } + + @Override + public void dispose() { + batch.dispose(); + introImage.dispose(); + stage.dispose(); + } +} diff --git a/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java b/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java index c0f682b60..704ed65d7 100644 --- a/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java +++ b/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java @@ -20,6 +20,7 @@ import com.csse3200.game.areas.ForestGameArea; import com.csse3200.game.areas.terrain.TerrainFactory; import com.csse3200.game.components.maingame.MainGameActions; +import com.csse3200.game.components.maingame.MainGameLoseDisplay; import com.csse3200.game.entities.Entity; import com.csse3200.game.entities.EntityService; import com.csse3200.game.entities.factories.PlayerFactory; @@ -67,7 +68,6 @@ public class MainGameScreen extends ScreenAdapter { public static int viewportHeight= screenHeight; - private OrthographicCamera camera; private SpriteBatch batch; @@ -117,7 +117,6 @@ public MainGameScreen(GdxGame game) { ForestGameArea forestGameArea = new ForestGameArea(terrainFactory); forestGameArea.create(); } - @Override public void render(float delta) { physicsEngine.update(); @@ -128,7 +127,6 @@ public void render(float delta) { batch.draw(backgroundTexture, 0, 0, viewportWidth, viewportHeight); batch.end(); - renderer.render(); stage.act(Math.min(Gdx.graphics.getDeltaTime(), 1 / 30f)); stage.draw(); @@ -196,6 +194,7 @@ private void createUI() { .addComponent(new PerformanceDisplay()) .addComponent(new MainGameActions(this.game)) .addComponent(new MainGameExitDisplay()) + .addComponent(new MainGameLoseDisplay()) .addComponent(new Terminal()) .addComponent(inputComponent) .addComponent(new TerminalDisplay());