diff --git a/res/levels/test.level b/res/levels/test.level index 13c4168..2bcf5a3 100644 --- a/res/levels/test.level +++ b/res/levels/test.level @@ -1,5 +1,5 @@ -name:Lustiger Levelname -backgroundMusic:music/bla.wav +name:Testlevel \o/ +backgroundMusic:music/ScooterFriendsTurbo8Bit.wav background:StarBackground - [0-4] diff --git a/src/de/teamteamteam/spacescooter/level/Level.java b/src/de/teamteamteam/spacescooter/level/Level.java index 89494c6..7c16eb2 100644 --- a/src/de/teamteamteam/spacescooter/level/Level.java +++ b/src/de/teamteamteam/spacescooter/level/Level.java @@ -9,6 +9,7 @@ import de.teamteamteam.spacescooter.entity.enemy.EnemyOne; import de.teamteamteam.spacescooter.entity.enemy.EnemyThree; import de.teamteamteam.spacescooter.entity.enemy.EnemyTwo; import de.teamteamteam.spacescooter.screen.GameScreen; +import de.teamteamteam.spacescooter.sound.SoundSystem; import de.teamteamteam.spacescooter.utility.Loader; import de.teamteamteam.spacescooter.utility.Random; @@ -32,6 +33,11 @@ public final class Level { */ private int levelClock; + /** + * Thread handle for the backgroundMusic being played. + */ + private Thread backgroundMusic; + /** * Constructor creating a LevelConfig based on a given config file. @@ -48,6 +54,7 @@ public final class Level { public void doBuildUp() { this.spawnEntityByAvailableName(Entity.availableNames.valueOf(this.config.background), 0, 50); GameScreen.setPlayer(new Player(200, 300)); + this.backgroundMusic = SoundSystem.playSound(this.config.backgroundMusic); } /** @@ -129,4 +136,15 @@ public final class Level { break; } } + + /** + * Clean up before the Level is torn down. + * Stop the music, ... + */ + public void tearDown() { + if(this.backgroundMusic != null) { + this.backgroundMusic.interrupt(); + this.backgroundMusic = null; + } + } } diff --git a/src/de/teamteamteam/spacescooter/screen/GameScreen.java b/src/de/teamteamteam/spacescooter/screen/GameScreen.java index 40cb763..ddc5b94 100644 --- a/src/de/teamteamteam/spacescooter/screen/GameScreen.java +++ b/src/de/teamteamteam/spacescooter/screen/GameScreen.java @@ -10,7 +10,6 @@ import de.teamteamteam.spacescooter.gui.InterfaceBar; import de.teamteamteam.spacescooter.gui.ScoreBar; import de.teamteamteam.spacescooter.gui.ShieldBar; import de.teamteamteam.spacescooter.level.Level; -import de.teamteamteam.spacescooter.sound.SoundSystem; import de.teamteamteam.spacescooter.utility.CollisionHandler; /** @@ -33,11 +32,6 @@ public class GameScreen extends Screen { */ private long gameClockTrigger; - /** - * Internal Thread handle for the background music. - */ - private Thread backgroundMusic; - /** * GameScreen Constructor. * Takes the level as its second parameter. @@ -54,8 +48,6 @@ public class GameScreen extends Screen { new HealthBar(10, 5); new ShieldBar(10, 27); new ScoreBar(575, 33); - - this.backgroundMusic = SoundSystem.playSound("music/ScooterFriendsTurbo8Bit.wav"); } @@ -106,7 +98,7 @@ public class GameScreen extends Screen { */ @Override public void cleanup() { - this.backgroundMusic.interrupt(); + this.level.tearDown(); super.cleanup(); }