diff --git a/bin/de/bricked/resources/sounds/destroy_brick.mp3 b/bin/de/bricked/resources/sounds/destroy_brick.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..188f9704a00f3421a37a438580cd8c0c7af71903 Binary files /dev/null and b/bin/de/bricked/resources/sounds/destroy_brick.mp3 differ diff --git a/bin/de/bricked/resources/sounds/finished_level.mp3 b/bin/de/bricked/resources/sounds/finished_level.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..7b190396ae0060beca3709f697a1c4f8cb7c1003 Binary files /dev/null and b/bin/de/bricked/resources/sounds/finished_level.mp3 differ diff --git a/bin/de/bricked/resources/sounds/g.mp3 b/bin/de/bricked/resources/sounds/g.mp3 deleted file mode 100644 index 8bf2fdc5a7439fa5d89cce76bd1c0a03eed8f5b9..0000000000000000000000000000000000000000 Binary files a/bin/de/bricked/resources/sounds/g.mp3 and /dev/null differ diff --git a/bin/de/bricked/resources/sounds/game_over.mp3 b/bin/de/bricked/resources/sounds/game_over.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..80148d9cdd4ee2bb79d38b46b8f2e332682a2dbd Binary files /dev/null and b/bin/de/bricked/resources/sounds/game_over.mp3 differ diff --git a/bin/de/bricked/resources/sounds/hit_brick.mp3 b/bin/de/bricked/resources/sounds/hit_brick.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..80dae7bf515d60865328b6fd9e6e59ddd97fb25f Binary files /dev/null and b/bin/de/bricked/resources/sounds/hit_brick.mp3 differ diff --git a/bin/de/bricked/resources/sounds/hit_paddle.mp3 b/bin/de/bricked/resources/sounds/hit_paddle.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..d57dd2687c1d7614940b655e80a357add37c0107 Binary files /dev/null and b/bin/de/bricked/resources/sounds/hit_paddle.mp3 differ diff --git a/bin/de/bricked/resources/sounds/hit_wall.mp3 b/bin/de/bricked/resources/sounds/hit_wall.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..b3944f7afdc3a2186323014077e1bf74b2190b3d Binary files /dev/null and b/bin/de/bricked/resources/sounds/hit_wall.mp3 differ diff --git a/bin/de/bricked/resources/sounds/life_lost.mp3 b/bin/de/bricked/resources/sounds/life_lost.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..9ae1796065f2db2cf15377e42aacd97cfd590350 Binary files /dev/null and b/bin/de/bricked/resources/sounds/life_lost.mp3 differ diff --git a/bin/de/bricked/resources/sounds/s.mp3 b/bin/de/bricked/resources/sounds/s.mp3 deleted file mode 100644 index e036fa38c4199c308e5f75241d9cf324202a72d3..0000000000000000000000000000000000000000 Binary files a/bin/de/bricked/resources/sounds/s.mp3 and /dev/null differ diff --git a/bin/de/bricked/resources/sounds/tnt.mp3 b/bin/de/bricked/resources/sounds/tnt.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..308c229c4fb80b2cceb8d98b78fe03ab06f35fba Binary files /dev/null and b/bin/de/bricked/resources/sounds/tnt.mp3 differ diff --git a/src/de/bricked/game/Game.java b/src/de/bricked/game/Game.java index 48846459eacd718c9cc24bc3c2068dd4f8d71ec2..dc3a8ed8bdc2887d38d84a85a1f188221c770e4d 100644 --- a/src/de/bricked/game/Game.java +++ b/src/de/bricked/game/Game.java @@ -8,6 +8,7 @@ import de.bricked.game.levels.Level; import de.bricked.game.levels.LevelPack; import de.bricked.game.powerups.PowerUp; import de.bricked.game.settings.Settings; +import de.bricked.game.sound.SoundHandler; import de.bricked.ui.LevelController; import javafx.geometry.Point2D; import logger.LogLevel; @@ -30,10 +31,15 @@ public class Game private int multiplicator; private LevelController levelController; private ArrayList<PowerUp> movingPowerUps; + private SoundHandler soundHandler; public Game() { this.settings = new Settings(); + this.soundHandler = new SoundHandler(); + //DEBUG + soundHandler.setVolume(1.0); + soundHandler.setMuted(false); this.levelPack = null; this.level = null; this.livesRemaining = 0; @@ -178,6 +184,11 @@ public class Game { this.movingPowerUps = movingPowerUps; } + + public SoundHandler getSoundHandler() + { + return soundHandler; + } public Point2D reflectBall(HitLocation hitLocation, Point2D direction) { diff --git a/src/de/bricked/game/board/Board.java b/src/de/bricked/game/board/Board.java index e63e6845e159e1543946a5484ec67b12dec3c2eb..7e8b3afa18024a4de810b96ecf1862bb8b699ff4 100644 --- a/src/de/bricked/game/board/Board.java +++ b/src/de/bricked/game/board/Board.java @@ -210,6 +210,11 @@ public class Board if(hittedBrick.getType().equals(BrickType.TNT)) { explodeBrick(row, col); + game.getSoundHandler().play("tnt"); + } + else + { + game.getSoundHandler().play("destroy_brick"); } if(hittedBrick.getPowerUp() != null) @@ -224,11 +229,12 @@ public class Board { game.getLevelController().showAnimatedPoints(row, col, hittedBrick.getType().getPoints(), 15, false); } - game.getLevelController().increaseMultiplicator(hittedBrick.getType().getPoints()); + game.getLevelController().increaseMultiplicator(hittedBrick.getType().getPoints()); LevelController.redrawBrick(col, row, bricks.get(row).get(col), true); } else { + game.getSoundHandler().play("hit_brick"); LevelController.redrawBrick(col, row, bricks.get(row).get(col), false); } } diff --git a/src/de/bricked/game/sound/SoundHandler.java b/src/de/bricked/game/sound/SoundHandler.java index 9e8f4df9b0f808b3fd24b2b4b6f7dc4cccc14ec8..e72c1e8dffcb6d7f3e0f920f41e7b37be0105549 100644 --- a/src/de/bricked/game/sound/SoundHandler.java +++ b/src/de/bricked/game/sound/SoundHandler.java @@ -13,11 +13,13 @@ public class SoundHandler { private double volume; private boolean muted; - + private boolean isPlayingTNT; + public SoundHandler() { volume = 0.0; muted = false; + isPlayingTNT = false; } public void play(String soundID) @@ -26,16 +28,26 @@ public class SoundHandler { try { - String path = SoundHandler.class.getResource(Config.JAR_SOUND_SAVEDIR + soundID + ".mp3").toURI().toURL().toString(); - Media sound = new Media(path); - MediaPlayer mediaPlayer = new MediaPlayer(sound); - mediaPlayer.setVolume(volume); - mediaPlayer.setAutoPlay(true); + if(!isPlayingTNT) + { + if(soundID.equalsIgnoreCase("tnt")) + { + isPlayingTNT = true; + } + String path = SoundHandler.class.getResource(Config.JAR_SOUND_SAVEDIR + soundID + ".mp3").toURI().toURL().toString(); + Media sound = new Media(path); + MediaPlayer mediaPlayer = new MediaPlayer(sound); + mediaPlayer.setVolume(volume); + mediaPlayer.setAutoPlay(true); + mediaPlayer.setOnEndOfMedia(()->{ + isPlayingTNT = false; + }); + } } catch (MalformedURLException | URISyntaxException e) { Logger.log(LogLevel.ERROR, Logger.exceptionToString(e)); - } + } } } diff --git a/src/de/bricked/main/Main.java b/src/de/bricked/main/Main.java index da4c00cc682b4369e13ea207b2c9409f8812c697..f9f87fb66ae2cf476432cc5b928f6bf9aa5189cc 100644 --- a/src/de/bricked/main/Main.java +++ b/src/de/bricked/main/Main.java @@ -36,7 +36,7 @@ public class Main extends Application stage.getIcons().add(new Image("/de/bricked/resources/icon.png")); stage.setTitle(bundle.getString("app.name")); stage.setScene(scene); - stage.setResizable(true); + stage.setResizable(false); stage.setOnCloseRequest(new EventHandler<WindowEvent>() { diff --git a/src/de/bricked/resources/sounds/destroy_brick.mp3 b/src/de/bricked/resources/sounds/destroy_brick.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..188f9704a00f3421a37a438580cd8c0c7af71903 Binary files /dev/null and b/src/de/bricked/resources/sounds/destroy_brick.mp3 differ diff --git a/src/de/bricked/resources/sounds/finished_level.mp3 b/src/de/bricked/resources/sounds/finished_level.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..7b190396ae0060beca3709f697a1c4f8cb7c1003 Binary files /dev/null and b/src/de/bricked/resources/sounds/finished_level.mp3 differ diff --git a/src/de/bricked/resources/sounds/g.mp3 b/src/de/bricked/resources/sounds/g.mp3 deleted file mode 100644 index 8bf2fdc5a7439fa5d89cce76bd1c0a03eed8f5b9..0000000000000000000000000000000000000000 Binary files a/src/de/bricked/resources/sounds/g.mp3 and /dev/null differ diff --git a/src/de/bricked/resources/sounds/game_over.mp3 b/src/de/bricked/resources/sounds/game_over.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..80148d9cdd4ee2bb79d38b46b8f2e332682a2dbd Binary files /dev/null and b/src/de/bricked/resources/sounds/game_over.mp3 differ diff --git a/src/de/bricked/resources/sounds/hit_brick.mp3 b/src/de/bricked/resources/sounds/hit_brick.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..80dae7bf515d60865328b6fd9e6e59ddd97fb25f Binary files /dev/null and b/src/de/bricked/resources/sounds/hit_brick.mp3 differ diff --git a/src/de/bricked/resources/sounds/hit_paddle.mp3 b/src/de/bricked/resources/sounds/hit_paddle.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..d57dd2687c1d7614940b655e80a357add37c0107 Binary files /dev/null and b/src/de/bricked/resources/sounds/hit_paddle.mp3 differ diff --git a/src/de/bricked/resources/sounds/hit_wall.mp3 b/src/de/bricked/resources/sounds/hit_wall.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..b3944f7afdc3a2186323014077e1bf74b2190b3d Binary files /dev/null and b/src/de/bricked/resources/sounds/hit_wall.mp3 differ diff --git a/src/de/bricked/resources/sounds/life_lost.mp3 b/src/de/bricked/resources/sounds/life_lost.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..9ae1796065f2db2cf15377e42aacd97cfd590350 Binary files /dev/null and b/src/de/bricked/resources/sounds/life_lost.mp3 differ diff --git a/src/de/bricked/resources/sounds/s.mp3 b/src/de/bricked/resources/sounds/s.mp3 deleted file mode 100644 index e036fa38c4199c308e5f75241d9cf324202a72d3..0000000000000000000000000000000000000000 Binary files a/src/de/bricked/resources/sounds/s.mp3 and /dev/null differ diff --git a/src/de/bricked/resources/sounds/tnt.mp3 b/src/de/bricked/resources/sounds/tnt.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..308c229c4fb80b2cceb8d98b78fe03ab06f35fba Binary files /dev/null and b/src/de/bricked/resources/sounds/tnt.mp3 differ diff --git a/src/de/bricked/ui/LevelController.java b/src/de/bricked/ui/LevelController.java index 44467afa71fa93870b0897454f6fd0cbb400ef99..c1e6bee2eb9f3c019ee8b731dd1e13c36d42bfad 100644 --- a/src/de/bricked/ui/LevelController.java +++ b/src/de/bricked/ui/LevelController.java @@ -19,6 +19,7 @@ import de.bricked.game.paddle.Paddle; import de.bricked.game.paddle.PaddleSize; import de.bricked.game.powerups.PowerUp; import de.bricked.game.powerups.PowerUpType; +import de.bricked.game.sound.SoundHandler; import de.bricked.utils.CountdownTimer; import fontAwesome.FontIcon; import fontAwesome.FontIconType; @@ -425,7 +426,7 @@ public class LevelController resetMultiplicator(); if(hitLocation.equals(HitLocation.LIFE_LOST)) - { + { game.setLivesRemaining(game.getLivesRemaining() - 1); Logger.log(LogLevel.DEBUG, "Life lost (" + game.getLivesRemaining() + " lives remaining)"); refreshLiveCounter(); @@ -435,9 +436,11 @@ public class LevelController // game over gameState = GameState.STOPPED; - timer.stop(); + timer.stop(); + + game.getSoundHandler().play("game_over"); - Platform.runLater(() -> { + Platform.runLater(() -> { Alert alert = new Alert(AlertType.INFORMATION); alert.setTitle("Game Over"); alert.setHeaderText(""); @@ -452,6 +455,8 @@ public class LevelController { gameState = GameState.WAITING; timer.stop(); + + game.getSoundHandler().play("life_lost"); // reset paddle and ball initPaddle(game.getLevel().getInitPadSize()); @@ -462,6 +467,8 @@ public class LevelController else { game.getBall().setDirection(game.reflectBall(hitLocation, game.getBall().getDirection())); + + game.getSoundHandler().play("hit_wall"); switch(hitLocation) { @@ -512,6 +519,8 @@ public class LevelController correctBallPosition(hitLocation, ballPosition, paddlePosition, paddle.getWidth(), paddle.getHeight()); resetMultiplicator(); + + game.getSoundHandler().play("hit_paddle"); } // ball doesn't collide with paddle --> check collision with bricks else @@ -777,7 +786,7 @@ public class LevelController int points = game.getBoard().hitBrick(i, k, game.getBall()); // brick has been destroyed if(points > 0) - { + { game.setTotalPoints(game.getTotalPoints() + points); labelPoints.setText(String.valueOf(game.getTotalPoints())); labelBlocksRemaining.setText(game.getBoard().getNumberOfRemainingBricks() + " Bricks remaining"); @@ -790,6 +799,8 @@ public class LevelController gameState = GameState.STOPPED; resetMultiplicator(); timer.stop(); + + game.getSoundHandler().play("finished_level"); Platform.runLater(() -> { Alert alert = new Alert(AlertType.INFORMATION);