diff options
| author | Zach Jordan <zxjordan5@gmail.com> | 2023-05-30 09:39:45 -0400 | 
|---|---|---|
| committer | Zach Jordan <zxjordan5@gmail.com> | 2023-05-30 09:39:45 -0400 | 
| commit | c19cbf5cd9a4186fb94ba90361505d8dc71b04ab (patch) | |
| tree | 036f916058e0248019132d78dffd5f7e98b2425c | |
| parent | 042685d2230a164a0da9e68e2cc881ec8b087a27 (diff) | |
| parent | 8dc661c2da567cfd7beea9ce0e1bb557962e654c (diff) | |
| download | NPEhero-c19cbf5cd9a4186fb94ba90361505d8dc71b04ab.tar.gz NPEhero-c19cbf5cd9a4186fb94ba90361505d8dc71b04ab.tar.bz2 NPEhero-c19cbf5cd9a4186fb94ba90361505d8dc71b04ab.zip | |
Merge branch 'main' of https://gitlab.sowgro.net/guitarheros/guitarhero
Diffstat (limited to '')
| -rw-r--r-- | src/gameplay/SongPlayer.java | 43 | ||||
| -rw-r--r-- | src/main/Difficulty.java | 2 | 
2 files changed, 41 insertions, 4 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 diff --git a/src/main/Difficulty.java b/src/main/Difficulty.java index 30b81d4..03460ee 100644 --- a/src/main/Difficulty.java +++ b/src/main/Difficulty.java @@ -20,7 +20,7 @@ public class Difficulty      public String title;      private ObservableList<LeaderboardEntry> leaderboard;      public File notes; -    public int bpm; +    public int bpm = 28;      public File song;      public int numBeats;      public JSONObject diffStuff; | 
