-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added lose button and implemented lose screen
Implemented LosingScreen class and a lose button on MainGameScreen for demonstration purposes until lose game state is implemented
- Loading branch information
1 parent
46a3c0a
commit 4a95dfe
Showing
7 changed files
with
184 additions
and
4 deletions.
There are no files selected for viewing
Binary file added
BIN
+22.3 KB
...allpaper-simple-stars-video-background-loop-black-and-white-aesthetic-space.jpg
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
source/core/src/main/com/csse3200/game/components/maingame/MainGameLoseDisplay.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
|
109 changes: 109 additions & 0 deletions
109
source/core/src/main/com/csse3200/game/screens/LosingScreen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters