Skip to content

Commit

Permalink
Added Triggers to the Next and win screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Moksh-Mehta7 committed Oct 14, 2023
1 parent e445867 commit 7dd01a8
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 45 deletions.
50 changes: 19 additions & 31 deletions source/core/src/main/com/csse3200/game/GdxGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,41 +64,29 @@ public void dispose() {
* @return new screen
*/
private Screen newScreen(ScreenType screenType) {
switch (screenType) {
case MAIN_MENU:
return new MainMenuScreen(this);
case MAIN_GAME:
return new MainGameScreen(this);
case SETTINGS:
return new SettingsScreen(this);
case STORY_SCREEN:
return new StoryScreen(this);
case LEVEL_SELECT:
return new LevelSelectScreen(this);
case LOSING_SCREEN:
return new LosingScreen(this);
case TURRET_SELECTION:
return new TurretSelectionScreen(this);
case HELP_SCREEN:
return new GameDescriptionHelpScreen(this);
case HELP_MOBS_SCREEN:
return new MobsDescriptionHelpScreen(this);
case HELP_TOWER_SCREEN:
return new TowerDescriptionHelpScreen(this);
case HELP_BOSS_SCREEN:
return new BossDescriptionHelpScreen(this);
case HOW_TO_PLAY:
return new HowToPlay(this);
case LOAD_SCREEN:
return new LoadingScreen(this);
default:
return null;
}
return switch (screenType) {
case Next_Screen -> new NextLevelScreen(this);
case Win_Screen -> new WinningScreen(this);
case MAIN_MENU -> new MainMenuScreen(this);
case MAIN_GAME -> new MainGameScreen(this);
case SETTINGS -> new SettingsScreen(this);
case STORY_SCREEN -> new StoryScreen(this);
case LEVEL_SELECT -> new LevelSelectScreen(this);
case LOSING_SCREEN -> new LosingScreen(this);
case TURRET_SELECTION -> new TurretSelectionScreen(this);
case HELP_SCREEN -> new GameDescriptionHelpScreen(this);
case HELP_MOBS_SCREEN -> new MobsDescriptionHelpScreen(this);
case HELP_TOWER_SCREEN -> new TowerDescriptionHelpScreen(this);
case HELP_BOSS_SCREEN -> new BossDescriptionHelpScreen(this);
case HOW_TO_PLAY -> new HowToPlay(this);
case LOAD_SCREEN -> new LoadingScreen(this);
default -> null;
};
}

public enum ScreenType {
MAIN_MENU, MAIN_GAME, SETTINGS, STORY_SCREEN, LEVEL_SELECT, TURRET_SELECTION, LOSING_SCREEN, HELP_SCREEN, LOAD_SCREEN,
HELP_MOBS_SCREEN, HELP_TOWER_SCREEN, HELP_BOSS_SCREEN, HOW_TO_PLAY
HELP_MOBS_SCREEN, HELP_TOWER_SCREEN, HELP_BOSS_SCREEN, Win_Screen, Next_Screen, HOW_TO_PLAY
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,19 @@ public MainGameActions(GdxGame game) {
public void create() {
entity.getEvents().addListener("exit", this::onExit);
entity.getEvents().addListener("lose", this::onLose);
//entity.getEvents().addListener("win", this::onWin);
entity.getEvents().addListener("win", this::WinningScreen);
entity.getEvents().addListener("Next Level", this::NextLevel);
}

private void NextLevel() {
logger.info("Next level");
game.setScreen(GdxGame.ScreenType.Next_Screen);

}

private void WinningScreen() {
logger.info("Uer Won the game");
game.setScreen(GdxGame.ScreenType.Win_Screen);
}

/**
Expand Down
18 changes: 12 additions & 6 deletions source/core/src/main/com/csse3200/game/screens/MainGameScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import com.csse3200.game.components.maingame.MainGameExitDisplay;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* The game screen containing the main game.
*
Expand Down Expand Up @@ -219,18 +218,26 @@ public void render(float delta) {
ServiceLocator.getWaveService().getDisplay().updateMobCount();
renderer.render();

// Check if the game has ended
// Check if the game has ended
if (ServiceLocator.getGameEndService().hasGameEnded()) {
ui.getEvents().trigger("lose");
}

// Check if all waves are completed and the level has been completed
if (ServiceLocator.getWaveService().isLevelCompleted()) {
logger.info("Main game level completed detected, go to win screen");
ui.getEvents().trigger("lose"); // needs to change to: ui.getEvents().trigger("win");
// Add something in to unlock the next planet/level?
if (selectedLevel == 2) { // Lava level
// If it's the lava level, go to the "win" screen
ui.getEvents().trigger("win");
logger.info("Main game level completed detected, go to win screen");
} else {
// For other levels, go to the "NextLevelScreen"
game.setScreen(GdxGame.ScreenType.Next_Screen);
logger.info("game level completed detected, go to NextLevelScreen");
}
}
}
}
// Add something in to unlock the next planet/level?

@Override
public void resize(int width, int height) {
Expand Down Expand Up @@ -304,7 +311,6 @@ private void createUI() {
.addComponent(ServiceLocator.getWaveService().getDisplay())
.addComponent(new MainGameExitDisplay())
.addComponent(new MainGameLoseDisplay())
//.addComponent(new MainGameWinDisplay()) <- needs to be uncommented when team 3 have implemented the ui
.addComponent(new MainGamePauseDisplay(this.game))
.addComponent(new Terminal())
.addComponent(inputComponent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ public class NextLevelScreen extends ScreenAdapter {

public NextLevelScreen(GdxGame game) {
batch = new SpriteBatch();
backgroundTexture = new Texture("next_level_background.png"); // Replace with the path to your background image
backgroundTexture = new Texture("planets/background.png"); // Replace with the path to your background image
font = new BitmapFont();

stage = new Stage(new ScreenViewport());
Gdx.input.setInputProcessor(stage);

Skin skin = new Skin(Gdx.files.internal("configs/text.json")); // Replace with the path to your UI skin JSON
Skin skin = new Skin(Gdx.files.internal("images/ui/buttons/glass.json")); // Replace with the path to your UI skin JSON
TextButton nextLevelButton = new TextButton("Next Level", skin);
nextLevelButton.addListener(new ClickListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ public class WinningScreen extends ScreenAdapter {
private Texture backgroundTexture;
private Sprite backgroundSprite;

private static final String BACKGROUND_TEXTURE = "winning_background.png"; // Set the path to your winning background image
private static final String BACKGROUND_TEXTURE = "planets/background.png"; // Set the path to your winning background image
private static final String WIN_TEXT = """
Congratulations! You won!
""";
private static final String[] winSounds = {"win_sound.ogg"}; // Set the path to your winning sound
// private static final String[] winSounds = {"win_sound.ogg"}; // Set the path to your winning sound
private final BitmapFont font;
private Stage stage;
private final ResourceService resourceService;
Expand All @@ -39,10 +39,11 @@ public WinningScreen(GdxGame game) {
font = new BitmapFont();
resourceService = new ResourceService();
ServiceLocator.registerResourceService(resourceService);
resourceService.loadSounds(winSounds);
// resourceService.loadSounds(winSounds);
resourceService.loadAll();
}


@Override
public void show() {
batch = new SpriteBatch();
Expand All @@ -53,7 +54,7 @@ public void show() {
stage = new Stage(new ScreenViewport());
Gdx.input.setInputProcessor(stage);

Skin skin = new Skin(Gdx.files.internal("configs/text.json"));
Skin skin = new Skin(Gdx.files.internal("images/ui/buttons/glass.json"));
TextButton exitButton = new TextButton("Exit Game", skin);
exitButton.addListener(new ClickListener(){
public void clicked(InputEvent event, float x, float y) {
Expand Down Expand Up @@ -84,7 +85,7 @@ public void clicked(InputEvent event, float x, float y) {
stage.addActor(table);

// Play win sound
resourceService.getAsset(winSounds[0], Sound.class).play(0.3f);
// resourceService.getAsset(winSounds[0], Sound.class).play(0.3f);
}

@Override
Expand Down

0 comments on commit 7dd01a8

Please sign in to comment.