From 6a0315bbf5cfaa57b47ef6db88c7f80ce0143657 Mon Sep 17 00:00:00 2001 From: jg175 <jg175@hdm-stuttgart.de> Date: Sat, 20 Jan 2024 13:32:05 +0100 Subject: [PATCH] ADD: Soundeffect for Tiletypes in Tileset --- .../battlearena/Model/Map/BackgroundTile.java | 11 ++++++++++- .../hdm_stuttgart/battlearena/Model/Map/ITile.java | 2 ++ .../battlearena/Model/Map/TileFactory.java | 11 ++++++----- .../battlearena/Model/Map/TileManager.java | 13 +++++++------ .../battlearena/Model/Sound/SFXLoop.java | 7 ++++--- .../battlearena/Model/Sound/SoundEffects.java | 2 +- 6 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/Map/BackgroundTile.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/Map/BackgroundTile.java index b17fb79d..75ec8fc3 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/Map/BackgroundTile.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/Map/BackgroundTile.java @@ -1,5 +1,6 @@ package de.hdm_stuttgart.battlearena.Model.Map; +import de.hdm_stuttgart.battlearena.Model.Sound.SFXLoop; import javafx.scene.image.Image; import org.apache.logging.log4j.Logger; @@ -11,11 +12,13 @@ class BackgroundTile implements ITile{ private final Image tileSprite; private final boolean isWalkable, isDestructible; + private SFXLoop soundeffect; - public BackgroundTile(Image tileSprite, boolean isWalkable, boolean isDestructible) { + public BackgroundTile(Image tileSprite, boolean isWalkable, boolean isDestructible, SFXLoop sfx) { this.tileSprite = tileSprite; this.isWalkable = isWalkable; this.isDestructible = isDestructible; + this.soundeffect = sfx; } @Override @@ -34,4 +37,10 @@ class BackgroundTile implements ITile{ log.debug("Image returned"); return tileSprite; } + + @Override + public SFXLoop getSoundeffect(){ + log.debug("SFX returned"); + return soundeffect; + } } \ No newline at end of file diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/Map/ITile.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/Map/ITile.java index 58f71108..f0290e1b 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/Map/ITile.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/Map/ITile.java @@ -1,9 +1,11 @@ package de.hdm_stuttgart.battlearena.Model.Map; +import de.hdm_stuttgart.battlearena.Model.Sound.SFXLoop; import javafx.scene.image.Image; public interface ITile { boolean getCollision(); boolean getDestruction(); Image getTileSprite(); + SFXLoop getSoundeffect(); } \ No newline at end of file diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/Map/TileFactory.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/Map/TileFactory.java index 0da1a155..d3168970 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/Map/TileFactory.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/Map/TileFactory.java @@ -1,5 +1,6 @@ package de.hdm_stuttgart.battlearena.Model.Map; +import de.hdm_stuttgart.battlearena.Model.Sound.SFXLoop; import javafx.scene.image.Image; import org.apache.logging.log4j.Logger; @@ -9,19 +10,19 @@ public class TileFactory { private static final Logger log = LogManager.getLogger(TileFactory.class); - public static ITile createTile(TileType tileType, TileType tileType2, Image tileSprite) { + public static ITile createTile(TileType tileType, TileType tileType2, Image tileSprite, SFXLoop sfx) { if (tileType == TileType.WALKABLE && tileType2 == TileType.DESTRUCTIBLE) { log.info("Tile with type: " + tileType + " " + tileType2 + " created."); - return new BackgroundTile(tileSprite, true, true); + return new BackgroundTile(tileSprite, true, true, sfx); }else if (tileType == TileType.WALKABLE && tileType2 == TileType.NON_DESTRUCTIBLE) { log.info("Tile with type: " + tileType + " " + tileType2 +" created."); - return new BackgroundTile(tileSprite, true, false); + return new BackgroundTile(tileSprite, true, false, sfx); }else if (tileType == TileType.NON_WALKABLE && tileType2 == TileType.DESTRUCTIBLE) { log.info("Tile with type: " + tileType + " " + tileType2 +" created."); - return new BackgroundTile(tileSprite, false, true); + return new BackgroundTile(tileSprite, false, true, sfx); }else if (tileType == TileType.NON_WALKABLE && tileType2 == TileType.NON_DESTRUCTIBLE) { log.info("Tile with type: " + tileType + " " + tileType2 +" created."); - return new BackgroundTile(tileSprite, false, false); + return new BackgroundTile(tileSprite, false, false, sfx); } log.error("TileType: " + tileType + " not supported!"); diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/Map/TileManager.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/Map/TileManager.java index 0ac687da..4e7ebadc 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/Map/TileManager.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/Map/TileManager.java @@ -1,5 +1,6 @@ package de.hdm_stuttgart.battlearena.Model.Map; +import de.hdm_stuttgart.battlearena.Model.Sound.SFXLoop; import javafx.scene.canvas.GraphicsContext; import javafx.scene.image.Image; @@ -35,17 +36,17 @@ public class TileManager { private void createTiles() { try { tileSet[0] = TileFactory.createTile(TileType.WALKABLE, TileType.NON_DESTRUCTIBLE, - new Image(Objects.requireNonNull(getClass().getResourceAsStream("/textures/map/Grass01.png")))); + new Image(Objects.requireNonNull(getClass().getResourceAsStream("/textures/map/Grass01.png"))), SFXLoop.GRASS); tileSet[1] = TileFactory.createTile(TileType.WALKABLE, TileType.NON_DESTRUCTIBLE, - new Image(Objects.requireNonNull(getClass().getResourceAsStream("/textures/map/Grass02.png")))); + new Image(Objects.requireNonNull(getClass().getResourceAsStream("/textures/map/Grass02.png"))),SFXLoop.GRASS); tileSet[2] = TileFactory.createTile(TileType.WALKABLE, TileType.NON_DESTRUCTIBLE, - new Image(Objects.requireNonNull(getClass().getResourceAsStream("/textures/map/Grass04.png")))); + new Image(Objects.requireNonNull(getClass().getResourceAsStream("/textures/map/Grass04.png"))), SFXLoop.STONE); tileSet[3] = TileFactory.createTile(TileType.NON_WALKABLE, TileType.DESTRUCTIBLE, - new Image(Objects.requireNonNull(getClass().getResourceAsStream("/textures/map/Stone01.png")))); + new Image(Objects.requireNonNull(getClass().getResourceAsStream("/textures/map/Stone01.png"))), SFXLoop.STONE); tileSet[4] = TileFactory.createTile(TileType.NON_WALKABLE, TileType.DESTRUCTIBLE, - new Image(Objects.requireNonNull(getClass().getResourceAsStream("/textures/map/Stone02.png")))); + new Image(Objects.requireNonNull(getClass().getResourceAsStream("/textures/map/Stone02.png"))), SFXLoop.STONE); tileSet[5] = TileFactory.createTile(TileType.WALKABLE,TileType.NON_DESTRUCTIBLE, - new Image(Objects.requireNonNull(getClass().getResourceAsStream("/textures/map/finalheart.png")))); + new Image(Objects.requireNonNull(getClass().getResourceAsStream("/textures/map/finalheart.png"))), SFXLoop.GRASS); } catch (Exception e) { log.error(e); } diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/Sound/SFXLoop.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/Sound/SFXLoop.java index 8f8dec58..248e94be 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/Sound/SFXLoop.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/Sound/SFXLoop.java @@ -1,10 +1,11 @@ package de.hdm_stuttgart.battlearena.Model.Sound; public enum SFXLoop { + NONE(""), GRASS("/sound/sfx/steps/grass"), - STONE("/sound/sfx/steps/stone"), - COLLISION("/sound/sfx/collision"), - ATTACK("/sound/sfx/attack"); + STONE("/sound/sfx/steps/stone"); + + private String path; SFXLoop(String path){ 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 4bf503b1..20860c61 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 @@ -6,7 +6,7 @@ import org.apache.logging.log4j.LogManager; public class SoundEffects { private static final Logger log = LogManager.getLogger(SoundEffects.class); - + boolean stopSoundeffect = false; public void playSoundEffect(SFXLoop soundeffect){ -- GitLab