diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/Entity/GameplayObjects/Bomb.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/Entity/GameplayObjects/Bomb.java index f586f7f5c44945ff17e055d5436d47823c18e0fc..1296989db0e4e94746af4f3342737bc60099c93c 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/Entity/GameplayObjects/Bomb.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/Entity/GameplayObjects/Bomb.java @@ -3,15 +3,13 @@ package de.hdm_stuttgart.battlearena.Model.Entity.GameplayObjects; import de.hdm_stuttgart.battlearena.Controller.GameSceneController; import de.hdm_stuttgart.battlearena.Model.Entity.EntityDirection; import de.hdm_stuttgart.battlearena.Model.Entity.IEntity; - import de.hdm_stuttgart.battlearena.Model.Sound.SFX; import de.hdm_stuttgart.battlearena.Model.Sound.SoundEffects; import javafx.geometry.BoundingBox; import javafx.scene.canvas.GraphicsContext; import javafx.scene.image.Image; - -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.Objects; @@ -28,6 +26,7 @@ public class Bomb implements IEntity { private BoundingBox boxCollider; private final ObjectType OBJECT_TYPE = ObjectType.BOMB; private ObjectStatus OBJECT_STATUS = ObjectStatus.UNUSED; + private SoundEffects sfx = new SoundEffects(); //private SoundEffects soundEffects; public Bomb(int posX, int posY, GraphicsContext graphicsContext) { @@ -85,6 +84,7 @@ public class Bomb implements IEntity { } private void updateAnimation() { //Easily add more frames + sfx.playSoundEffectOnce(SFX.BOMB); frameCounter++; if (frameCounter > 17) { diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/Entity/Player.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/Entity/Player.java index 051bd8278abe858b23aa6377b0a7fa6e84b039b8..20f63337ae9a12ae70fd00e6e10557716a69a43f 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/Entity/Player.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/Entity/Player.java @@ -9,13 +9,11 @@ import de.hdm_stuttgart.battlearena.Model.Inputs.InputHandler; import de.hdm_stuttgart.battlearena.Model.Map.TileManager; import de.hdm_stuttgart.battlearena.Model.Sound.SFX; import de.hdm_stuttgart.battlearena.Model.Sound.SoundEffects; - import javafx.geometry.BoundingBox; import javafx.scene.canvas.GraphicsContext; import javafx.scene.image.Image; - -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.io.IOException; import java.util.List; @@ -42,6 +40,7 @@ class Player implements IEntity { private SoundEffects sfx = new SoundEffects(); + private Image directionDownOne, directionDownTwo, directionUpOne, @@ -288,13 +287,6 @@ class Player implements IEntity { private void performEntityMovement(boolean isWalkableTile) { lastMapPosX = mapPosX; lastMapPosY = mapPosY; - try { - sfx.playSoundEffect(gameSceneController); - } catch (IOException e) { - throw new RuntimeException(e); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } if (isWalkableTile) { switch (playerDirection) { case UP: @@ -610,6 +602,13 @@ class Player implements IEntity { @Override public void updateEntityWalkAnimation() { + try { + sfx.playSoundEffect(gameSceneController); + } catch (IOException e) { + throw new RuntimeException(e); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } spriteCounter++; if (spriteCounter > 10) { if (spriteNumber == 1) { diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/Sound/SoundEffects.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/Sound/SoundEffects.java index 7908e96f3c7a415dd7af73d402854031dba806c6..d01d6bc6ee70bf0d2baacdb27dea168581509dcd 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/Sound/SoundEffects.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/Sound/SoundEffects.java @@ -13,14 +13,14 @@ import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; public class SoundEffects { private static final Logger log = LogManager.getLogger(SoundEffects.class); - - - + private ExecutorService service = Executors.newCachedThreadPool(); private SoundFileManager fileManager = new SoundFileManager(); private Persistence persistence = Persistence.getInstance(); private boolean soundEffectPlayedTest = false; @@ -41,13 +41,14 @@ public class SoundEffects { List<Path> sfxPaths = fileManager.getFilePathsFromResources(path); String randomPath = fileManager.getRandomFilePath(sfxPaths); String resource = fileManager.convertPathToResourcePath(randomPath); - Thread sfxLoop = new Thread(() -> { + ///Thread sfxLoop = new Thread + service.execute(() -> { AudioClip effect = new AudioClip(getClass().getResource(resource).toString()); effect.setVolume((double) persistence.getSettings().getSfxVolume() /100); effect.play(); }); - sfxLoop.setDaemon(true); - sfxLoop.start(); + //sfxLoop.setDaemon(true); + //sfxLoop.start(); sfxPaths.clear(); } } @@ -57,13 +58,13 @@ public class SoundEffects { String path = soundEffect.getPath(); log.info(path); String resource = path.substring(18); // Begins at Ressource Folder - Thread sfx = new Thread(()->{ + service.execute(()->{ AudioClip audioClip = new AudioClip(getClass().getResource(resource).toExternalForm()); audioClip.setVolume((double) persistence.getSettings().getSfxVolume()/100); audioClip.play(); }); - sfx.setDaemon(true); - sfx.start(); + //sfx.setDaemon(true); + //sfx.start(); soundEffectPlayedTest = true; } @@ -72,9 +73,6 @@ public class SoundEffects { persistence.getSettings().setSfxVolume(volume); } - public int getVolume(){ - return Persistence.getInstance().getSettings().getSfxVolume(); - } public boolean isSoundEffectPlayedTest() { return soundEffectPlayedTest; diff --git a/src/main/resources/player/appSettings.json b/src/main/resources/player/appSettings.json index 7c4eba521367ea9ac5f8fe73885d10d9f7a606f3..c253782d6e6eba3463e66cde502d281427a2926b 100644 --- a/src/main/resources/player/appSettings.json +++ b/src/main/resources/player/appSettings.json @@ -1,4 +1,4 @@ { "sfxVolume": 16, - "musicVolume": 81 + "musicVolume": 16 } \ No newline at end of file