From 864cc31d4672a77bb6f0adc0906a66b9f0c4ff15 Mon Sep 17 00:00:00 2001 From: Aidan Ross Date: Tue, 30 May 2023 08:46:54 -0400 Subject: add cancel() to songPlayer class, which can be called to stop the music and the gameloop --- src/gameplay/SongPlayer.java | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/src/gameplay/SongPlayer.java b/src/gameplay/SongPlayer.java index 67b21a4..671fad9 100644 --- a/src/gameplay/SongPlayer.java +++ b/src/gameplay/SongPlayer.java @@ -2,10 +2,15 @@ package gameplay; import java.io.File; import java.io.FileNotFoundException; +import java.io.IOException; import java.util.ArrayList; import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; +import java.util.logging.Level; + +import javax.sound.sampled.LineUnavailableException; +import javax.sound.sampled.UnsupportedAudioFileException; import gui.GameOver; import javafx.geometry.Pos; @@ -34,6 +39,13 @@ import sound.AudioFilePlayer; public class SongPlayer extends Pane { private int bpm; //initializes the bpm of the song, to be read in from a metadata file later + private int songLength; //initializes the length of the song in terms of the song's bpm, to be read in later + + sound.AudioFilePlayer music; + private main.Level level; + private Difficulty difficulty; + private Pane pane; + Timer timer; //the timer that determines when notes will fall, counted in terms of the song's bpm final int TIME = 1500; //delay for notes falling down the screen @@ -94,6 +106,12 @@ public class SongPlayer extends Pane { public SongPlayer(main.Level lvl, Difficulty d, Pane p, ScoreController cntrl) { bpm = d.bpm; //Reads the song's bpm from a metadata file + + level = lvl; + difficulty = d; + pane = p; + + songLength = 28; timer = new Timer(120); //Sets the timer's bpm to that of the song scoreCounter = cntrl; //Uses the song's designated scoreCounter @@ -153,9 +171,9 @@ public class SongPlayer extends Pane { super.getChildren().addAll(root); //puts all of the combonents in the pane to be rendered - sound.AudioFilePlayer music = new AudioFilePlayer("src/assets/TestSync120bpm.wav"); - music.play(); gameLoop.start(); //starts the gameLoop, a periodic backround task runner that runs the methods within it 60 times every second + music = new AudioFilePlayer("src/assets/TestSync120bpm.wav"); + music.play(); } /** @@ -224,9 +242,28 @@ public class SongPlayer extends Pane { sendNote(spaceSends, spaceLane, sButton); sendNote(jSends, jLane, jButton); sendNote(kSends, kLane, kButton); + if (timer.time() > songLength) { + try { + cancel(); + } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) { + e.printStackTrace(); + } + gui.Driver.setMenu(new GameOver(level, difficulty, pane, scoreCounter.getScore())); + } } }; + /** + * Stops the gameloop and the music + * @throws LineUnavailableException + * @throws IOException + * @throws UnsupportedAudioFileException + */ + public void cancel() throws UnsupportedAudioFileException, IOException, LineUnavailableException { + gameLoop.stop(); + music.stop(); + } + /** * returns the pos in the lane array of the closest note to the goal * -- cgit v1.2.3 From a18f74388dee9e92e3c7165d440b778a79b65a1c Mon Sep 17 00:00:00 2001 From: sowgro Date: Tue, 30 May 2023 08:49:49 -0400 Subject: add placeholder bpm --- src/main/Difficulty.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/Difficulty.java b/src/main/Difficulty.java index 24480e4..f0b7391 100644 --- a/src/main/Difficulty.java +++ b/src/main/Difficulty.java @@ -10,7 +10,7 @@ public class Difficulty public String title; private ObservableList leaderboard = FXCollections.observableArrayList(); public File notes; - public int bpm; + public int bpm = 28; public File song; public int numBeats; -- cgit v1.2.3 From 8dc661c2da567cfd7beea9ce0e1bb557962e654c Mon Sep 17 00:00:00 2001 From: Aidan Ross Date: Tue, 30 May 2023 08:51:59 -0400 Subject: Bit of progress on reading in the bpm and nuimbeats --- src/gameplay/SongPlayer.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gameplay/SongPlayer.java b/src/gameplay/SongPlayer.java index 7ea6bfa..acf9d6b 100644 --- a/src/gameplay/SongPlayer.java +++ b/src/gameplay/SongPlayer.java @@ -115,8 +115,8 @@ public class SongPlayer extends Pane { difficulty = d; pane = p; - songLength = 28; - timer = new Timer(120); //Sets the timer's bpm to that of the song + songLength = d.numBeats; + timer = new Timer(d.bpm); //Sets the timer's bpm to that of the song scoreCounter = cntrl; //Uses the song's designated scoreCounter try { @@ -176,7 +176,7 @@ public class SongPlayer extends Pane { super.getChildren().addAll(root); //puts all of the combonents in the pane to be rendered gameLoop.start(); //starts the gameLoop, a periodic backround task runner that runs the methods within it 60 times every second - music = new AudioFilePlayer("src/assets/TestSync120bpm.wav"); + music = new AudioFilePlayer(d.song.getPath()); music.play(); } -- cgit v1.2.3