From 9b7cad1006eced84d3b81d52173759ba709245a2 Mon Sep 17 00:00:00 2001 From: sowgro Date: Tue, 6 Jun 2023 23:22:47 -0400 Subject: fix sound and project cleanup --- src/assets/BookBetrayal.mp3 | Bin 5624404 -> 0 bytes src/assets/BookBetrayal.wav | Bin 41328718 -> 0 bytes src/assets/MenuMusicPlaceholder.wav | Bin 4064300 -> 0 bytes src/assets/TestSync120bpm.wav | Bin 16865024 -> 0 bytes src/assets/forest.jpg | Bin 145696 -> 0 bytes src/assets/forest.png | Bin 624396 -> 0 bytes src/assets/mountains-1412683.svg | 5 ----- src/assets/mountains-1412683_1920.png | Bin 1115601 -> 0 bytes src/assets/pico.png | Bin 9072089 -> 0 bytes src/assets/trees.png | Bin 1405559 -> 0 bytes src/assets/water.png | Bin 1009759 -> 0 bytes src/devmenu/DebugMenu.java | 14 +------------- src/gameplay/SongPlayer.java | 7 +++++-- src/gui/Driver.java | 12 +++++++++--- src/main/SettingsController.java | 6 ++++++ src/main/SoundController.java | 22 +++++++++++++++++++++- 16 files changed, 42 insertions(+), 24 deletions(-) delete mode 100644 src/assets/BookBetrayal.mp3 delete mode 100644 src/assets/BookBetrayal.wav delete mode 100644 src/assets/MenuMusicPlaceholder.wav delete mode 100644 src/assets/TestSync120bpm.wav delete mode 100644 src/assets/forest.jpg delete mode 100644 src/assets/forest.png delete mode 100644 src/assets/mountains-1412683.svg delete mode 100644 src/assets/mountains-1412683_1920.png delete mode 100644 src/assets/pico.png delete mode 100644 src/assets/trees.png delete mode 100644 src/assets/water.png (limited to 'src') diff --git a/src/assets/BookBetrayal.mp3 b/src/assets/BookBetrayal.mp3 deleted file mode 100644 index cf274a6..0000000 Binary files a/src/assets/BookBetrayal.mp3 and /dev/null differ diff --git a/src/assets/BookBetrayal.wav b/src/assets/BookBetrayal.wav deleted file mode 100644 index 0634a41..0000000 Binary files a/src/assets/BookBetrayal.wav and /dev/null differ diff --git a/src/assets/MenuMusicPlaceholder.wav b/src/assets/MenuMusicPlaceholder.wav deleted file mode 100644 index 5ec4218..0000000 Binary files a/src/assets/MenuMusicPlaceholder.wav and /dev/null differ diff --git a/src/assets/TestSync120bpm.wav b/src/assets/TestSync120bpm.wav deleted file mode 100644 index 3e92d3e..0000000 Binary files a/src/assets/TestSync120bpm.wav and /dev/null differ diff --git a/src/assets/forest.jpg b/src/assets/forest.jpg deleted file mode 100644 index 88d7311..0000000 Binary files a/src/assets/forest.jpg and /dev/null differ diff --git a/src/assets/forest.png b/src/assets/forest.png deleted file mode 100644 index cbc4e98..0000000 Binary files a/src/assets/forest.png and /dev/null differ diff --git a/src/assets/mountains-1412683.svg b/src/assets/mountains-1412683.svg deleted file mode 100644 index a6f5585..0000000 --- a/src/assets/mountains-1412683.svg +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/assets/mountains-1412683_1920.png b/src/assets/mountains-1412683_1920.png deleted file mode 100644 index 39d560e..0000000 Binary files a/src/assets/mountains-1412683_1920.png and /dev/null differ diff --git a/src/assets/pico.png b/src/assets/pico.png deleted file mode 100644 index 002ad9e..0000000 Binary files a/src/assets/pico.png and /dev/null differ diff --git a/src/assets/trees.png b/src/assets/trees.png deleted file mode 100644 index 113907f..0000000 Binary files a/src/assets/trees.png and /dev/null differ diff --git a/src/assets/water.png b/src/assets/water.png deleted file mode 100644 index 0113819..0000000 Binary files a/src/assets/water.png and /dev/null differ diff --git a/src/devmenu/DebugMenu.java b/src/devmenu/DebugMenu.java index 654d15b..0d55e69 100644 --- a/src/devmenu/DebugMenu.java +++ b/src/devmenu/DebugMenu.java @@ -18,23 +18,11 @@ public class DebugMenu VBox primaryPane = new VBox(); public DebugMenu() { - Button wallpaperTest = new Button(); - wallpaperTest.setText("wallpaper trees"); - wallpaperTest.setOnAction(e -> Driver.setBackground("assets/trees.png")); - - Button wallpaperTest2 = new Button(); - wallpaperTest2.setText("wallpaper water"); - wallpaperTest2.setOnAction(e -> Driver.setBackground("assets/water.png")); - - Button wallpaperTest3 = new Button(); - wallpaperTest3.setText("wallpaper pico"); - wallpaperTest3.setOnAction(e -> Driver.setBackground("assets/pico.png")); - Button testVol = new Button(); testVol.setText("print volumes"); testVol.setOnAction(e -> System.out.println("setc:"+Driver.settingsController.effectsVol+" sndc:"+Driver.soundController.songMediaPlayer.getVolume())); - primaryPane.getChildren().addAll(wallpaperTest,wallpaperTest2,wallpaperTest3,testVol); + primaryPane.getChildren().addAll(testVol); Scene primaryScene = new Scene(primaryPane); primaryStage.setScene(primaryScene); diff --git a/src/gameplay/SongPlayer.java b/src/gameplay/SongPlayer.java index d06535f..6145f14 100644 --- a/src/gameplay/SongPlayer.java +++ b/src/gameplay/SongPlayer.java @@ -14,6 +14,7 @@ import javax.sound.sampled.UnsupportedAudioFileException; import gui.Driver; import gui.GameOver; import javafx.geometry.Pos; +import javafx.scene.CacheHint; import javafx.scene.input.KeyCode; import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; @@ -115,7 +116,7 @@ public class SongPlayer extends Pane { song = lvl.song; if (lvl.background != null) { - Driver.setBackground(lvl.background.getUrl()); + Driver.setBackground(lvl.background); } bpm = d.bpm; //Reads the song's bpm from a metadata file level = lvl; @@ -208,6 +209,8 @@ public class SongPlayer extends Pane { lane.add(new Block(button.getColor(), 50, 50, 5)); int index = lane.size() - 1; sends.remove(); + lane.get(index).setCache(true); //added by tbone to try to improve performance + lane.get(index).setCacheHint(CacheHint.SPEED); //this too lane.get(index).heightProperty().bind(super.widthProperty().divide(8)); lane.get(index).widthProperty().bind(super.widthProperty().divide(8)); lane.get(index).arcHeightProperty().bind(super.widthProperty().divide(25)); @@ -286,7 +289,7 @@ public class SongPlayer extends Pane { public void cancel() { Driver.soundController.endSong(); Driver.soundController.playMenuSong(); - gui.Driver.setBackground("assets/mountains.png"); + gui.Driver.setMenuBackground(); gameLoop.stop(); } diff --git a/src/gui/Driver.java b/src/gui/Driver.java index 9e09860..fd18933 100644 --- a/src/gui/Driver.java +++ b/src/gui/Driver.java @@ -18,6 +18,7 @@ import javafx.stage.Stage; import main.LevelController; import main.SettingsController; import main.SoundController; +import java.io.File; import devmenu.DebugMenu; @@ -56,7 +57,7 @@ public class Driver extends Application setMenu(new MainMenu()); - setBackground("assets/mountains.png"); + setMenuBackground(); primaryStage.addEventHandler(KeyEvent.KEY_PRESSED, event -> { //full screen stuff if (KeyCode.F11.equals(event.getCode())) { @@ -95,17 +96,22 @@ public class Driver extends Application * replaces the background image with a new one * @param url the url of the image to set */ - public static void setBackground(String url) //replaces background with a new one + public static void setBackground(Image image) //replaces background with a new one { primaryPane.setBackground(new Background( new BackgroundImage( - new Image(url), + image, BackgroundRepeat.REPEAT, BackgroundRepeat.NO_REPEAT, new BackgroundPosition(Side.LEFT, 0, true, Side.BOTTOM, 0, true), new BackgroundSize(BackgroundSize.AUTO, BackgroundSize.AUTO, true, true, false, true) ))); } + public static void setMenuBackground() + { + setBackground(new Image(new File("src/assets/mountains.png").toURI().toString())); + } + /** * quits the application */ diff --git a/src/main/SettingsController.java b/src/main/SettingsController.java index b7b2cb9..3304dd4 100644 --- a/src/main/SettingsController.java +++ b/src/main/SettingsController.java @@ -19,6 +19,9 @@ public class SettingsController read(); } + /** + * reads json data from settings.json + */ public void read() { JSONParser jsonParser = new JSONParser(); //parser to read the file @@ -37,6 +40,9 @@ public class SettingsController } } + /** + * writes json data to settings.json + */ public void write() { FileWriter fileWriter; diff --git a/src/main/SoundController.java b/src/main/SoundController.java index c8e6c8a..8f255da 100644 --- a/src/main/SoundController.java +++ b/src/main/SoundController.java @@ -6,6 +6,7 @@ import java.util.HashMap; import gui.Driver; import javafx.scene.media.Media; import javafx.scene.media.MediaPlayer; +import javafx.util.Duration; public class SoundController { @@ -14,6 +15,9 @@ public class SoundController private HashMap effects = new HashMap<>(); private File mainMenuSong = new File("src/assets/fairyfountain.wav"); + /** + * creates a new sound controller and starts playing the main menu music + */ public SoundController() { effects.put("hit", new MediaPlayer(new Media(new File("src/assets/hit.wav").toURI().toString()))); @@ -26,6 +30,10 @@ public class SoundController playMenuSong(); } + /** + * plays the song that is passed in. + * @param songFile: the song + */ public void playSong(File songFile) { if (songMediaPlayer != null) @@ -38,6 +46,9 @@ public class SoundController songMediaPlayer.play(); } + /** + * plays the main menu song + */ public void playMenuSong() { playSong(mainMenuSong); @@ -45,6 +56,9 @@ public class SoundController songMediaPlayer.play(); } + /** + * stops the currently playing song + */ public void endSong() { if (songMediaPlayer != null) @@ -53,9 +67,15 @@ public class SoundController } } + /** + * plays a sound effect + * for the volume slider to take affect each mediaplayer needs to be pre loaded. + * this rewinds and played the proper mediaplayer for the sound + * @param preset: a string of the name of the sound. possible sounds assigned in the constructor + */ public void playSfx(String preset) { - effects.get(preset).stop(); + effects.get(preset).seek(new Duration(0)); effects.get(preset).play(); } } \ No newline at end of file -- cgit v1.2.3