Add missle sound

This commit is contained in:
Felix Koppe
2024-10-13 08:02:24 +02:00
parent 34929b40f1
commit 5cb0843819
4 changed files with 17 additions and 1 deletions

View File

@@ -34,6 +34,7 @@ public class GameSound extends AbstractAppState implements GameEventListener {
private AudioNode splashSound;
private AudioNode shipDestroyedSound;
private AudioNode explosionSound;
private AudioNode missleSound;
/**
* Checks if sound is enabled in the preferences.
@@ -78,6 +79,7 @@ public void initialize(AppStateManager stateManager, Application app) {
shipDestroyedSound = loadSound(app, "Sound/Effects/sunken.wav"); //NON-NLS
splashSound = loadSound(app, "Sound/Effects/splash.wav"); //NON-NLS
explosionSound = loadSound(app, "Sound/Effects/explosion.wav"); //NON-NLS
missleSound = loadSound(app, "Sound/Effects/missle.wav");
}
/**
@@ -108,6 +110,14 @@ public void splash() {
splashSound.playInstance();
}
/**
* Plays the missle flyby sound effect.
*/
public void flyBy() {
if (isEnabled() && missleSound != null)
missleSound.playInstance();
}
/**
* Plays the explosion sound effect.
*/
@@ -130,6 +140,7 @@ public void receivedEvent(SoundEvent event) {
case EXPLOSION -> explosion();
case SPLASH -> splash();
case DESTROYED_SHIP -> shipDestroyed();
case MISSLE_FLYBY -> flyBy();
}
}
}

View File

@@ -33,6 +33,7 @@ public AnimationState(ClientGameLogic logic, boolean myTurn, IntPoint position)
logic.getOpponentMap().add(shell);
} else {
logic.getOwnMap().add(shell);
logic.playSound(Sound.MISSLE_FLYBY);
}
}

View File

@@ -22,5 +22,9 @@ public enum Sound {
/**
* Sound of a ship being destroyed.
*/
DESTROYED_SHIP
DESTROYED_SHIP,
/**
* Sound of an incomming missle.
*/
MISSLE_FLYBY,
}