diff --git a/source/core/src/main/com/csse3200/game/components/tasks/MobTask/MobTask.java b/source/core/src/main/com/csse3200/game/components/tasks/MobTask/MobTask.java index 92ee1f3a..648600fe 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/MobTask/MobTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/MobTask/MobTask.java @@ -136,7 +136,7 @@ public void update() { if ((mob.getComponent(CombatStatsComponent.class).getHealth() <= 0 && !deathFlag)) { // decrement engineer count // ! tests failing because of textbox - ServiceLocator.getGameEndService().updateEngineerCount(); +// ServiceLocator.getGameEndService().updateEngineerCount(); changeState(State.DEATH); animate(); movementTask.stop(); diff --git a/source/core/src/main/com/csse3200/game/components/tasks/waves/LevelWaves.java b/source/core/src/main/com/csse3200/game/components/tasks/waves/LevelWaves.java index 19d6e910..c6ddffba 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/waves/LevelWaves.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/waves/LevelWaves.java @@ -63,7 +63,7 @@ public WaveClass getWave(int index) { public void spawnWave() { if (gameTime.getTime() >= startTime + spawnDelay * 1000) { do { - currentRandom = MathUtils.random(0, ServiceLocator.getMapService().getHeight()); + currentRandom = MathUtils.random(0, ServiceLocator.getMapService().getHeight() - 1); } while (currentRandom == previousRandom); ServiceLocator.getWaveService().setNextLane(currentRandom); GridPoint2 randomPos = new GridPoint2(19, currentRandom); diff --git a/source/core/src/main/com/csse3200/game/screens/HelpScreen/Tutorial.java b/source/core/src/main/com/csse3200/game/screens/HelpScreen/Tutorial.java index 41906faf..314da32b 100644 --- a/source/core/src/main/com/csse3200/game/screens/HelpScreen/Tutorial.java +++ b/source/core/src/main/com/csse3200/game/screens/HelpScreen/Tutorial.java @@ -225,7 +225,7 @@ public void render(float delta) { logger.info("Main game level completed detected, go to win screen"); } else { // For other levels, go to the "NextLevelScreen" - game.setScreen(new NextLevelScreen(game, selectedLevel)); + game.setScreen(GdxGame.ScreenType.Next_Screen); logger.info("game level completed detected, go to NextLevelScreen"); } } diff --git a/source/core/src/main/com/csse3200/game/screens/LevelSelectScreen.java b/source/core/src/main/com/csse3200/game/screens/LevelSelectScreen.java index 99f4977b..c5ba1f5b 100644 --- a/source/core/src/main/com/csse3200/game/screens/LevelSelectScreen.java +++ b/source/core/src/main/com/csse3200/game/screens/LevelSelectScreen.java @@ -62,6 +62,9 @@ public class LevelSelectScreen extends ScreenAdapter { float timeCounter = 0; private static final String BG_PATH = "planets/background.png"; + String[] bgm = { + "sounds/background/pre_game/Sci-Fi8Loop_story.ogg" + }; // Description Box private final Label descriptionBox; @@ -115,9 +118,6 @@ public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, f stage.addActor(descriptionTable); ServiceLocator.registerResourceService(new ResourceService()); - String[] bgm = { - "sounds/background/pre_game/Sci-Fi8Loop_story.ogg" - }; ServiceLocator.getResourceService().loadMusic(bgm); ServiceLocator.getResourceService().loadAll(); music = ServiceLocator.getResourceService().getAsset(bgm[0], Music.class); @@ -237,7 +237,8 @@ private void spawnPlanetBorders() { private void loadPlanetLevel(int[] planet) { logger.info("Loading level {}", planet[4]); GameLevelData.setSelectedLevel(planet[4]); - game.setScreen(new TurretSelectionScreen(game)); + music.stop(); + game.setScreen(GdxGame.ScreenType.TURRET_SELECTION); } /** @@ -365,6 +366,7 @@ public void resize(int width, int height) { */ @Override public void dispose() { + ServiceLocator.getResourceService().unloadAssets(bgm); stage.dispose(); batch.dispose(); music.dispose(); diff --git a/source/core/src/main/com/csse3200/game/screens/StoryScreen.java b/source/core/src/main/com/csse3200/game/screens/StoryScreen.java index d0d26d15..e93726b3 100644 --- a/source/core/src/main/com/csse3200/game/screens/StoryScreen.java +++ b/source/core/src/main/com/csse3200/game/screens/StoryScreen.java @@ -197,6 +197,7 @@ public void render(float delta) { private void next() { currentIndex++; if (currentIndex >= images.length) { + music.stop(); game.setScreen(new LevelSelectScreen(game, -1)); } } 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 207a8162..e71efa1c 100644 --- a/source/core/src/main/com/csse3200/game/screens/TurretSelectionScreen.java +++ b/source/core/src/main/com/csse3200/game/screens/TurretSelectionScreen.java @@ -102,8 +102,10 @@ public TurretSelectionScreen(GdxGame game) { @Override public void clicked(InputEvent event, float x, float y) { click.play(0.4f); + music.stop(); // Handle the "back" action, e.g., return to the previous screen - game.setScreen(GdxGame.ScreenType.LEVEL_SELECT); // Replace PREVIOUS_SCREEN with the appropriate screen type + game.setScreen(GdxGame.ScreenType.LEVEL_SELECT); // Replace PREVIOU + // S_SCREEN with the appropriate screen type } }); @@ -120,6 +122,7 @@ public void clicked(InputEvent event, float x, float y) { for (TowerType t : selectedTurrets) { towers.add(t); } + music.stop(); ServiceLocator.setTowerTypes(towers);; game.setScreen(GdxGame.ScreenType.LOAD_SCREEN); } @@ -234,7 +237,7 @@ public void clicked(InputEvent event, float x, float y) { stage.addActor(table); table.setFillParent(true); Gdx.input.setInputProcessor(stage); - + logger.info("Playing music"); music.setVolume(0.4f); music.setLooping(true); music.play(); @@ -349,6 +352,7 @@ public void loadSounds() { public void unloadSounds() { ServiceLocator.getResourceService().unloadAssets(sounds); + ServiceLocator.getResourceService().unloadAssets(bgm); } /** * Disposes of the stage