Added sound to rocket firing

This commit is contained in:
Fleischer Hanno hanno.fleischer@unibw.de
2024-10-13 08:58:48 +02:00
parent 487305dccc
commit 9e591e37c3
3 changed files with 21 additions and 1 deletions

View File

@@ -38,6 +38,7 @@ public class GameSound extends AbstractAppState implements GameEventListener {
private AudioNode splashSound;
private AudioNode shipDestroyedSound;
private AudioNode explosionSound;
private AudioNode rocketSound;
private BattleshipApp app;
@@ -85,6 +86,8 @@ public void initialize(AppStateManager stateManager, Application app) {
shipDestroyedSound = loadSound(app, "Sound/Effects/sunken.wav", 1); //NON-NLS
splashSound = loadSound(app, "Sound/Effects/splash.wav", 2); //NON-NLS
explosionSound = loadSound(app, "Sound/Effects/explosion.wav",3); //NON-NLS
rocketSound = loadSound(app, "Sound/Effects/rocket.wav",4);
volume = PREFERENCES.getFloat(SOUND_VOLUME_PREF, 1.0f);
}
@@ -133,6 +136,14 @@ public void shipDestroyed() {
shipDestroyedSound.playInstance();
}
/**
* Plays sound effect when a rocket starts
*/
public void rocket() {
if (isEnabled() && rocketSound != null)
rocketSound.playInstance();
}
/**
* this method sets the sound volume of the sounds
*
@@ -156,6 +167,7 @@ public void setSoundVolume() {
shipDestroyedSound.setVolume(volume * mainVolume);
splashSound.setVolume(volume * mainVolume);
explosionSound.setVolume(volume * mainVolume);
rocketSound.setVolume(volume * mainVolume);
PREFERENCES.putFloat(SOUND_VOLUME_PREF, volume);
}
@@ -180,6 +192,9 @@ public void receivedEvent(SoundEvent event) {
case DESTROYED_SHIP:
shipDestroyed();
break;
case ROCKET_FIRED:
rocket();
break;
}
}
}

View File

@@ -22,6 +22,7 @@ public class AnimatonState extends ClientState {
public AnimatonState(ClientGameLogic logic, boolean myTurn, IntPoint position) {
super(logic);
logic.playMusic(Music.BATTLE_THEME);
logic.playSound(Sound.ROCKET_FIRED);
this.myTurn = myTurn;
if(myTurn) {
logic.getOpponentMap().add(new Shell(position));

View File

@@ -22,5 +22,9 @@ public enum Sound {
/**
* Sound of a ship being destroyed.
*/
DESTROYED_SHIP
DESTROYED_SHIP,
/**
* Sound of a rocket
*/
ROCKET_FIRED
}