ajout de l'option pour désactiver la musique (son non fonctionnel

This commit is contained in:
heurtet 2021-05-13 21:48:49 +02:00
parent 92e714411c
commit ae2ab5b643
4 changed files with 26 additions and 1 deletions

Binary file not shown.

View file

@ -12,6 +12,8 @@ public class SagittariusGame extends Game {
public static float G = 100;
public static boolean debugMode = true;
public static Music music;
public static boolean disableSounds = false;
public static float soundsVolume = 0.5f;
private static Game game;
public SagittariusGame() {
@ -31,6 +33,7 @@ public class SagittariusGame extends Game {
// A welcome music is played
music = Gdx.audio.newMusic(Gdx.files.internal("core/assets/sounds/Ghostrifter-Deflector.mp3"));
music.setLooping(true);
music.play();
// Default volume

View file

@ -11,6 +11,7 @@ import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.files.*;
import sagittarius.view.GameScreen;
import sagittarius.SagittariusGame;
public class Bow extends Actor {
@ -50,7 +51,12 @@ public class Bow extends Actor {
Arrow arrowShot = new Arrow(angle, power, GameScreen.playerCurrent, false);
GameScreen.setFocus(arrowShot); // do not use constructor 2 times
GameScreen.arrows.addActor(arrowShot);
shotSound.play();
// Make a sound when an arrow is shot
if ( ! SagittariusGame.disableSounds){
long shotid = shotSound.play(SagittariusGame.soundsVolume);
shotSound.setPitch(shotid,1.5f);
}
} else {
pressed = false;
}

View file

@ -33,10 +33,18 @@ public class SettingsScreen extends BaseScreen {
debugModeBox.setChecked(SagittariusGame.debugMode);
// disable music checkbox
VisCheckBox disableMusic = new VisCheckBox("disable music");
// Change volume of the music
Spinner musicVolume= new Spinner("Music Volume:", new SimpleFloatSpinnerModel(SagittariusGame.music.getVolume(), 0f, 1.0f, 0.01f, 3));
// disable sound checkbox
VisCheckBox disableSounds= new VisCheckBox("disable sounds");
disableSounds.setChecked(SagittariusGame.disableSounds);
// Change volume of the sound
Spinner musicSounds= new Spinner("Sounds Volume:", new SimpleFloatSpinnerModel(SagittariusGame.soundsVolume, 0f, 1.0f, 0.01f, 3));
// save button
VisTextButton saveButton = new VisTextButton("Save");
@ -47,8 +55,10 @@ public class SettingsScreen extends BaseScreen {
SagittariusGame.G = Float.parseFloat(gConstField.getTextField().getText());
SagittariusGame.music.setVolume(Float.parseFloat(musicVolume.getTextField().getText()));
SagittariusGame.soundsVolume = Float.parseFloat(musicVolume.getTextField().getText());
SagittariusGame.debugMode = debugModeBox.isChecked();
}
});
@ -65,8 +75,14 @@ public class SettingsScreen extends BaseScreen {
// Table structure
table.add(gConstField).width(250);
table.row();
table.add(disableMusic).width(250);
table.row();
table.add(musicVolume).width(250);
table.row();
table.add(disableSounds).width(250);
table.row();
table.add(musicSounds).width(250);
table.row();
table.add(debugModeBox).align(Align.left);
table.row();
table.add(saveButton).width(250);