diff options
author | sowgro <tpoke.ferrari@gmail.com> | 2023-06-05 00:34:16 -0400 |
---|---|---|
committer | sowgro <tpoke.ferrari@gmail.com> | 2023-06-05 00:34:16 -0400 |
commit | a14862a6bc0dbb1ae78cd4e2e4795d4194772583 (patch) | |
tree | 88db04cdcc76454ae0f0025a9249270fab45ee22 /src/main | |
parent | d87a87aabde8b4011910dfed731362b7cf0b6b24 (diff) | |
download | NPEhero-a14862a6bc0dbb1ae78cd4e2e4795d4194772583.tar.gz NPEhero-a14862a6bc0dbb1ae78cd4e2e4795d4194772583.tar.bz2 NPEhero-a14862a6bc0dbb1ae78cd4e2e4795d4194772583.zip |
rewrote everything related to sound
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/ScoreController.java | 8 | ||||
-rw-r--r-- | src/main/SettingsController.java | 9 | ||||
-rw-r--r-- | src/main/SoundController.java | 66 |
3 files changed, 74 insertions, 9 deletions
diff --git a/src/main/ScoreController.java b/src/main/ScoreController.java index d2606a4..54dd960 100644 --- a/src/main/ScoreController.java +++ b/src/main/ScoreController.java @@ -1,8 +1,8 @@ package main; +import gui.Driver; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; -import sound.ShortAudioPlayer; public class ScoreController{ @@ -12,8 +12,6 @@ public class ScoreController{ public StringProperty scoreProperty = new SimpleStringProperty("0"); public StringProperty comboProperty = new SimpleStringProperty("0"); - sound.ShortAudioPlayer fx = new ShortAudioPlayer(); - /** * Called when the user performs a perfect hit */ @@ -40,7 +38,7 @@ public class ScoreController{ * Called when the user misses a note */ public void miss() { - fx.play("src/assets/Miss.wav"); + Driver.soundController.playSfx("miss"); combo = 0; comboMultiplier = 1; scoreProperty.setValue(score+""); @@ -52,7 +50,7 @@ public class ScoreController{ * Increments the combo by one */ private void combo() { - fx.play("src/assets/Hitsound.wav"); + Driver.soundController.playSfx("hit"); combo++; if (combo == 2) { diff --git a/src/main/SettingsController.java b/src/main/SettingsController.java index 4bd2b24..36fda40 100644 --- a/src/main/SettingsController.java +++ b/src/main/SettingsController.java @@ -9,12 +9,13 @@ import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
+import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleIntegerProperty;
public class SettingsController
{
- public SimpleIntegerProperty effectsVol = new SimpleIntegerProperty(0);
- public SimpleIntegerProperty musicVol = new SimpleIntegerProperty(0);
+ public SimpleDoubleProperty effectsVol = new SimpleDoubleProperty(1);
+ public SimpleDoubleProperty musicVol = new SimpleDoubleProperty(1);
private JSONObject settings;
public void read() throws ParseException
@@ -27,8 +28,8 @@ public class SettingsController settings = (JSONObject)(obj); //converts read object to a JSONObject
- effectsVol.set((int) settings.get("effectsVol"));
- musicVol.set((int) settings.get("musicVol"));
+ effectsVol.set((double) settings.get("effectsVol"));
+ musicVol.set((double) settings.get("musicVol"));
}
catch (FileNotFoundException e)
{
diff --git a/src/main/SoundController.java b/src/main/SoundController.java new file mode 100644 index 0000000..55d40f4 --- /dev/null +++ b/src/main/SoundController.java @@ -0,0 +1,66 @@ +package main; + +import java.io.File; +import java.util.HashMap; + +import gui.Driver; +import javafx.scene.media.Media; +import javafx.scene.media.MediaPlayer; + +public class SoundController +{ + public MediaPlayer songMediaPlayer; + public MediaPlayer sfxMediaPlayer; + private HashMap<String,File> presets = new HashMap<>(); + private File mainMenuSong = new File("src/assets/MenuMusicPlaceholder.wav"); + + public SoundController() + { + presets.put("forward", new File("src/assets/MenuForward.wav")); + presets.put("backward", new File("src/assets/MenuBackward.wav")); + presets.put("hit", new File("src/assets/Hitsound.wav")); + presets.put("miss", new File("src/assets/Miss.wav")); + playMenuSong(); + } + + public void playSong(File songFile) + { + if (songMediaPlayer != null) + { + songMediaPlayer.stop(); + } + Media song = new Media(songFile.toURI().toString()); + songMediaPlayer = new MediaPlayer(song); + songMediaPlayer.volumeProperty().bind(Driver.settingsController.musicVol); + songMediaPlayer.play(); + } + + private void playMenuSong() + { + playSong(mainMenuSong); + songMediaPlayer.setCycleCount(MediaPlayer.INDEFINITE); + songMediaPlayer.play(); + } + + public void endSong() + { + playMenuSong(); + } + + public void playSfx(File sfxFile) + { + if (sfxMediaPlayer != null) + { + sfxMediaPlayer.stop(); + } + Media sound = new Media(sfxFile.toURI().toString()); + sfxMediaPlayer = new MediaPlayer(sound); + sfxMediaPlayer.volumeProperty().bind(Driver.settingsController.effectsVol); //not working yet + sfxMediaPlayer.play(); + } + + public void playSfx(String preset) + { + playSfx(presets.get(preset)); + } +}
\ No newline at end of file |