diff options
Diffstat (limited to 'src/gameplay/SongPlayer.java')
-rw-r--r-- | src/gameplay/SongPlayer.java | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/src/gameplay/SongPlayer.java b/src/gameplay/SongPlayer.java index c770b8a..acf9d6b 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; @@ -38,6 +43,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 @@ -98,7 +110,13 @@ 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 - timer = new Timer(120); //Sets the timer's bpm to that of the song + + level = lvl; + difficulty = d; + pane = p; + + 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 { @@ -157,9 +175,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(d.song.getPath()); + music.play(); } /** @@ -228,10 +246,29 @@ 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 * * @param searchLane |