diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/Level.java | 2 | ||||
-rw-r--r-- | src/main/ScoreController.java | 8 | ||||
-rw-r--r-- | src/main/SettingsController.java | 9 | ||||
-rw-r--r-- | src/main/SoundController.java | 69 |
4 files changed, 78 insertions, 10 deletions
diff --git a/src/main/Level.java b/src/main/Level.java index a173191..eb1d92c 100644 --- a/src/main/Level.java +++ b/src/main/Level.java @@ -76,7 +76,7 @@ public class Level System.out.println(thisDir+" is missing background.png, though it is not required"); } - if (! new File(thisDir, "preview.png").exists()) + if (new File(thisDir, "preview.png").exists()) { preview = new Image(new File(thisDir,"preview.png").toURI().toString()); } 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..0d2061c --- /dev/null +++ b/src/main/SoundController.java @@ -0,0 +1,69 @@ +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(); + } + + public void playMenuSong() + { + playSong(mainMenuSong); + songMediaPlayer.setCycleCount(MediaPlayer.INDEFINITE); + songMediaPlayer.play(); + } + + public void endSong() + { + if (songMediaPlayer != null) + { + songMediaPlayer.stop(); + } + } + + 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 |