diff --git a/source/core/assets/sounds/economy/click.wav b/source/core/assets/sounds/economy/click.wav new file mode 100644 index 000000000..efd2dd9c7 Binary files /dev/null and b/source/core/assets/sounds/economy/click.wav differ diff --git a/source/core/assets/sounds/economy/click_1.wav b/source/core/assets/sounds/economy/click_1.wav new file mode 100644 index 000000000..804512167 Binary files /dev/null and b/source/core/assets/sounds/economy/click_1.wav differ diff --git a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java index f93c6c5f4..5ba12caf0 100644 --- a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java +++ b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java @@ -138,6 +138,8 @@ public class ForestGameArea extends GameArea { }; private static final String[] forestSounds = { "sounds/Impact4.ogg", + "sounds/economy/click.wav", + "sounds/economy/click_1.wav", "sounds/towers/gun_shot_trimmed.mp3", "sounds/towers/deploy.mp3", "sounds/towers/stow.mp3", diff --git a/source/core/src/main/com/csse3200/game/components/gamearea/CurrencyDisplay.java b/source/core/src/main/com/csse3200/game/components/gamearea/CurrencyDisplay.java index 1071d486c..b64a2511d 100644 --- a/source/core/src/main/com/csse3200/game/components/gamearea/CurrencyDisplay.java +++ b/source/core/src/main/com/csse3200/game/components/gamearea/CurrencyDisplay.java @@ -1,6 +1,7 @@ package com.csse3200.game.components.gamearea; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.audio.Sound; import com.badlogic.gdx.graphics.Camera; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.BitmapFont; @@ -30,6 +31,7 @@ public class CurrencyDisplay extends UIComponent { private Camera camera; private TextButton scrapsTb; private TextButton crystalsTb; + private Sound clickSound; /** * Adds actors to stage @@ -37,6 +39,7 @@ public class CurrencyDisplay extends UIComponent { @Override public void create() { super.create(); + clickSound = ServiceLocator.getResourceService().getAsset("sounds/economy/click.wav", Sound.class); addActors(); } @@ -101,12 +104,17 @@ public void updateCrystalsStats() { /** * A label that appears once currency is gained, to give the player visual feedback + * Also plays sound * @param x Screen x coordinate * @param y Screen y coordinate * @param amount value to display on the pop-up * @param offset value to offset the height of the label by */ public void currencyPopUp(float x , float y, int amount, int offset) { + // play sound and set the volume + long soundId = clickSound.play(); + clickSound.setVolume(soundId, 0.4f); + Label label = new Label(String.format("+%d", amount), skin); // remove label after it fades out label.addAction(new SequenceAction(Actions.fadeOut(1.5f), Actions.removeActor())); diff --git a/source/core/src/test/com/csse3200/game/services/CurrencyServiceTest.java b/source/core/src/test/com/csse3200/game/services/CurrencyServiceTest.java index 2d51fa6f7..4bc9ce9e3 100644 --- a/source/core/src/test/com/csse3200/game/services/CurrencyServiceTest.java +++ b/source/core/src/test/com/csse3200/game/services/CurrencyServiceTest.java @@ -3,6 +3,7 @@ import com.csse3200.game.components.gamearea.CurrencyDisplay; import com.csse3200.game.currency.Scrap; import com.csse3200.game.extensions.GameExtension; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -10,6 +11,14 @@ @ExtendWith(GameExtension.class) class CurrencyServiceTest { + @BeforeEach + void setUp() { + ResourceService resourceService = new ResourceService(); + ServiceLocator.registerResourceService(resourceService); + resourceService.loadSounds(new String[]{"sounds/economy/click.wav"}); + resourceService.loadAll(); + + } @Test void shouldReturnScrap() { CurrencyService currencyService = new CurrencyService();