Skip to content

Commit

Permalink
sound now plays when currency is gained
Browse files Browse the repository at this point in the history
  • Loading branch information
nawal-0 committed Sep 11, 2023
1 parent 0af0866 commit db07558
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
Binary file added source/core/assets/sounds/economy/click.wav
Binary file not shown.
Binary file added source/core/assets/sounds/economy/click_1.wav
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -30,13 +31,15 @@ public class CurrencyDisplay extends UIComponent {
private Camera camera;
private TextButton scrapsTb;
private TextButton crystalsTb;
private Sound clickSound;

/**
* Adds actors to stage
*/
@Override
public void create() {
super.create();
clickSound = ServiceLocator.getResourceService().getAsset("sounds/economy/click.wav", Sound.class);
addActors();
}

Expand Down Expand Up @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@
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;

import static org.junit.jupiter.api.Assertions.assertEquals;

@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();
Expand Down

0 comments on commit db07558

Please sign in to comment.