Skip to content
Snippets Groups Projects
Commit 2cc1c86d authored by Gehrung Jonas's avatar Gehrung Jonas
Browse files

UPDATE: player and Bomb sound

parent 18d4f4a5
No related branches found
No related tags found
5 merge requests!74V1,!73Initial commit,!71Merge DataBase into Development,!62Sound,!60Merge: Sound
...@@ -3,15 +3,13 @@ package de.hdm_stuttgart.battlearena.Model.Entity.GameplayObjects; ...@@ -3,15 +3,13 @@ package de.hdm_stuttgart.battlearena.Model.Entity.GameplayObjects;
import de.hdm_stuttgart.battlearena.Controller.GameSceneController; import de.hdm_stuttgart.battlearena.Controller.GameSceneController;
import de.hdm_stuttgart.battlearena.Model.Entity.EntityDirection; import de.hdm_stuttgart.battlearena.Model.Entity.EntityDirection;
import de.hdm_stuttgart.battlearena.Model.Entity.IEntity; import de.hdm_stuttgart.battlearena.Model.Entity.IEntity;
import de.hdm_stuttgart.battlearena.Model.Sound.SFX; import de.hdm_stuttgart.battlearena.Model.Sound.SFX;
import de.hdm_stuttgart.battlearena.Model.Sound.SoundEffects; import de.hdm_stuttgart.battlearena.Model.Sound.SoundEffects;
import javafx.geometry.BoundingBox; import javafx.geometry.BoundingBox;
import javafx.scene.canvas.GraphicsContext; import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Objects; import java.util.Objects;
...@@ -28,6 +26,7 @@ public class Bomb implements IEntity { ...@@ -28,6 +26,7 @@ public class Bomb implements IEntity {
private BoundingBox boxCollider; private BoundingBox boxCollider;
private final ObjectType OBJECT_TYPE = ObjectType.BOMB; private final ObjectType OBJECT_TYPE = ObjectType.BOMB;
private ObjectStatus OBJECT_STATUS = ObjectStatus.UNUSED; private ObjectStatus OBJECT_STATUS = ObjectStatus.UNUSED;
private SoundEffects sfx = new SoundEffects();
//private SoundEffects soundEffects; //private SoundEffects soundEffects;
public Bomb(int posX, int posY, GraphicsContext graphicsContext) { public Bomb(int posX, int posY, GraphicsContext graphicsContext) {
...@@ -85,6 +84,7 @@ public class Bomb implements IEntity { ...@@ -85,6 +84,7 @@ public class Bomb implements IEntity {
} }
private void updateAnimation() { //Easily add more frames private void updateAnimation() { //Easily add more frames
sfx.playSoundEffectOnce(SFX.BOMB);
frameCounter++; frameCounter++;
if (frameCounter > 17) { if (frameCounter > 17) {
......
...@@ -9,13 +9,11 @@ import de.hdm_stuttgart.battlearena.Model.Inputs.InputHandler; ...@@ -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.Map.TileManager;
import de.hdm_stuttgart.battlearena.Model.Sound.SFX; import de.hdm_stuttgart.battlearena.Model.Sound.SFX;
import de.hdm_stuttgart.battlearena.Model.Sound.SoundEffects; import de.hdm_stuttgart.battlearena.Model.Sound.SoundEffects;
import javafx.geometry.BoundingBox; import javafx.geometry.BoundingBox;
import javafx.scene.canvas.GraphicsContext; import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
...@@ -42,6 +40,7 @@ class Player implements IEntity { ...@@ -42,6 +40,7 @@ class Player implements IEntity {
private SoundEffects sfx = new SoundEffects(); private SoundEffects sfx = new SoundEffects();
private Image directionDownOne, private Image directionDownOne,
directionDownTwo, directionDownTwo,
directionUpOne, directionUpOne,
...@@ -288,13 +287,6 @@ class Player implements IEntity { ...@@ -288,13 +287,6 @@ class Player implements IEntity {
private void performEntityMovement(boolean isWalkableTile) { private void performEntityMovement(boolean isWalkableTile) {
lastMapPosX = mapPosX; lastMapPosX = mapPosX;
lastMapPosY = mapPosY; lastMapPosY = mapPosY;
try {
sfx.playSoundEffect(gameSceneController);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
if (isWalkableTile) { if (isWalkableTile) {
switch (playerDirection) { switch (playerDirection) {
case UP: case UP:
...@@ -610,6 +602,13 @@ class Player implements IEntity { ...@@ -610,6 +602,13 @@ class Player implements IEntity {
@Override @Override
public void updateEntityWalkAnimation() { public void updateEntityWalkAnimation() {
try {
sfx.playSoundEffect(gameSceneController);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
spriteCounter++; spriteCounter++;
if (spriteCounter > 10) { if (spriteCounter > 10) {
if (spriteNumber == 1) { if (spriteNumber == 1) {
......
...@@ -13,14 +13,14 @@ import java.io.IOException; ...@@ -13,14 +13,14 @@ import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class SoundEffects { public class SoundEffects {
private static final Logger log = LogManager.getLogger(SoundEffects.class); private static final Logger log = LogManager.getLogger(SoundEffects.class);
private ExecutorService service = Executors.newCachedThreadPool();
private SoundFileManager fileManager = new SoundFileManager(); private SoundFileManager fileManager = new SoundFileManager();
private Persistence persistence = Persistence.getInstance(); private Persistence persistence = Persistence.getInstance();
private boolean soundEffectPlayedTest = false; private boolean soundEffectPlayedTest = false;
...@@ -41,13 +41,14 @@ public class SoundEffects { ...@@ -41,13 +41,14 @@ public class SoundEffects {
List<Path> sfxPaths = fileManager.getFilePathsFromResources(path); List<Path> sfxPaths = fileManager.getFilePathsFromResources(path);
String randomPath = fileManager.getRandomFilePath(sfxPaths); String randomPath = fileManager.getRandomFilePath(sfxPaths);
String resource = fileManager.convertPathToResourcePath(randomPath); String resource = fileManager.convertPathToResourcePath(randomPath);
Thread sfxLoop = new Thread(() -> { ///Thread sfxLoop = new Thread
service.execute(() -> {
AudioClip effect = new AudioClip(getClass().getResource(resource).toString()); AudioClip effect = new AudioClip(getClass().getResource(resource).toString());
effect.setVolume((double) persistence.getSettings().getSfxVolume() /100); effect.setVolume((double) persistence.getSettings().getSfxVolume() /100);
effect.play(); effect.play();
}); });
sfxLoop.setDaemon(true); //sfxLoop.setDaemon(true);
sfxLoop.start(); //sfxLoop.start();
sfxPaths.clear(); sfxPaths.clear();
} }
} }
...@@ -57,13 +58,13 @@ public class SoundEffects { ...@@ -57,13 +58,13 @@ public class SoundEffects {
String path = soundEffect.getPath(); String path = soundEffect.getPath();
log.info(path); log.info(path);
String resource = path.substring(18); // Begins at Ressource Folder String resource = path.substring(18); // Begins at Ressource Folder
Thread sfx = new Thread(()->{ service.execute(()->{
AudioClip audioClip = new AudioClip(getClass().getResource(resource).toExternalForm()); AudioClip audioClip = new AudioClip(getClass().getResource(resource).toExternalForm());
audioClip.setVolume((double) persistence.getSettings().getSfxVolume()/100); audioClip.setVolume((double) persistence.getSettings().getSfxVolume()/100);
audioClip.play(); audioClip.play();
}); });
sfx.setDaemon(true); //sfx.setDaemon(true);
sfx.start(); //sfx.start();
soundEffectPlayedTest = true; soundEffectPlayedTest = true;
} }
...@@ -72,9 +73,6 @@ public class SoundEffects { ...@@ -72,9 +73,6 @@ public class SoundEffects {
persistence.getSettings().setSfxVolume(volume); persistence.getSettings().setSfxVolume(volume);
} }
public int getVolume(){
return Persistence.getInstance().getSettings().getSfxVolume();
}
public boolean isSoundEffectPlayedTest() { public boolean isSoundEffectPlayedTest() {
return soundEffectPlayedTest; return soundEffectPlayedTest;
......
{ {
"sfxVolume": 16, "sfxVolume": 16,
"musicVolume": 81 "musicVolume": 16
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment