aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAidan Ross <aross02@fairport.org>2023-06-02 13:12:38 -0400
committerAidan Ross <aross02@fairport.org>2023-06-02 13:12:38 -0400
commit9567c39c55d8c5889126d03fccbbfed077b19d1b (patch)
tree1dbbed9a2d36f12f4b6f21ca1686fd3f11b841d3 /src
parent408c42dc788a7d9c218071dea34843b4196fa7c8 (diff)
downloadNPEhero-9567c39c55d8c5889126d03fccbbfed077b19d1b.tar.gz
NPEhero-9567c39c55d8c5889126d03fccbbfed077b19d1b.tar.bz2
NPEhero-9567c39c55d8c5889126d03fccbbfed077b19d1b.zip
SYNCING IS FIXED!!!!
Diffstat (limited to 'src')
-rw-r--r--src/assets/MenuMusicPlaceholder.wavbin0 -> 4064300 bytes
-rw-r--r--src/gameplay/SongPlayer.java29
-rw-r--r--src/gameplay/Timer.java4
-rw-r--r--src/gui/Driver.java19
4 files changed, 40 insertions, 12 deletions
diff --git a/src/assets/MenuMusicPlaceholder.wav b/src/assets/MenuMusicPlaceholder.wav
new file mode 100644
index 0000000..5ec4218
--- /dev/null
+++ b/src/assets/MenuMusicPlaceholder.wav
Binary files differ
diff --git a/src/gameplay/SongPlayer.java b/src/gameplay/SongPlayer.java
index 15dbf01..9010228 100644
--- a/src/gameplay/SongPlayer.java
+++ b/src/gameplay/SongPlayer.java
@@ -44,14 +44,12 @@ public class SongPlayer extends Pane {
private Double 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
- 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
+ final int TIME = 1000; //delay for notes falling down the screen
main.ScoreController scoreCounter = new ScoreController(); //used to keep track of the user's score
@@ -108,17 +106,27 @@ public class SongPlayer extends Pane {
}
}
+ public SongPlayer() {
+ }
+
public SongPlayer(main.Level lvl, Difficulty d, Pane p, ScoreController cntrl) {
+ try {
+ gui.Driver.mediaPlayer.stop();
+ } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
+ e.printStackTrace();
+ }
+ gui.Driver.mediaPlayer = new AudioFilePlayer(lvl.song.getPath());
+ gui.Driver.mediaPlayer.play();
+
bpm = d.bpm; //Reads the song's bpm from a metadata file
level = lvl;
difficulty = d;
pane = p;
- music = new AudioFilePlayer(level.song.getPath());
System.out.println(d.bpm + " " + d.numBeats);
- songLength = 28; //PLACEHOLDER BPM AND TIMER
- timer = new Timer(120); //Sets the timer's bpm to that of the song
+ songLength = d.numBeats;
+ timer = new Timer(bpm); //Sets the timer's bpm to that of the song
scoreCounter = cntrl; //Uses the song's designated scoreCounter
try {
@@ -189,7 +197,7 @@ public class SongPlayer extends Pane {
*/
public void sendNote(Queue<NoteInfo> sends, ArrayList<Block> lane, TButton button) {
if (sends.peek() != null && timer.time() > sends.peek().getTime()-(TIME*bpm/60000)) {
- TranslateTransition anim = new TranslateTransition(Duration.millis(TIME));
+ TranslateTransition anim = new TranslateTransition(Duration.millis(TIME+70));
lane.add(new Block(button.getColor(), 50, 50, 5));
int index = lane.size() - 1;
@@ -246,11 +254,11 @@ public class SongPlayer extends Pane {
sendNote(kSends, kLane, kButton);
if (timer.time() > songLength) {
try {
+ gui.Driver.setMenu(new GameOver(level, difficulty, pane, scoreCounter.getScore()));
cancel();
} catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
e.printStackTrace();
}
- gui.Driver.setMenu(new GameOver(level, difficulty, pane, scoreCounter.getScore()));
}
}
};
@@ -258,7 +266,6 @@ public class SongPlayer extends Pane {
//starts the gameLoop, a periodic backround task runner that runs the methods within it 60 times every second
public void start()
{
- music.play();
gameLoop.start();
}
@@ -270,7 +277,9 @@ public class SongPlayer extends Pane {
*/
public void cancel() throws UnsupportedAudioFileException, IOException, LineUnavailableException {
gameLoop.stop();
- music.stop();
+ gui.Driver.mediaPlayer.stop();
+ gui.Driver.mediaPlayer = new AudioFilePlayer("src/assets/MenuMusicPlaceholder.wav");
+ gui.Driver.mediaPlayer.play();
}
/**
diff --git a/src/gameplay/Timer.java b/src/gameplay/Timer.java
index 5ff3b16..e43ad19 100644
--- a/src/gameplay/Timer.java
+++ b/src/gameplay/Timer.java
@@ -19,10 +19,10 @@ public class Timer
}
public double time() {
- return ((double)(System.currentTimeMillis()-timeStart))*(bpm/60000.0);
+ return ((double)(System.currentTimeMillis()-timeStart)-1000)*(bpm/60000.0);
}
public String toString() {
- return ""+((double)(System.currentTimeMillis()-timeStart))*(bpm/60000.0);
+ return ""+((double)(System.currentTimeMillis()-timeStart)-1000)*(bpm/60000.0);
}
}
diff --git a/src/gui/Driver.java b/src/gui/Driver.java
index 1813e96..162d1fe 100644
--- a/src/gui/Driver.java
+++ b/src/gui/Driver.java
@@ -14,9 +14,15 @@ import javafx.scene.layout.BackgroundPosition;
import javafx.scene.layout.BackgroundRepeat;
import javafx.scene.layout.BackgroundSize;
import javafx.scene.layout.Pane;
+import javafx.scene.media.Media;
+import javafx.scene.media.MediaPlayer;
+import javafx.scene.media.MediaView;
import javafx.stage.Stage;
import main.LevelController;
import main.SettingsController;
+import sound.AudioFilePlayer;
+
+import javax.sound.sampled.AudioFileFormat;
// import javafx.scene.image.ImageView;
// import javafx.beans.property.Property;
@@ -26,10 +32,14 @@ import main.SettingsController;
// import javafx.animation.Timeline;
import devmenu.DebugMenu;
+import gameplay.SongPlayer;
public class Driver extends Application
{
+ gameplay.SongPlayer placeHolder = new gameplay.SongPlayer();
+ public static AudioFilePlayer mediaPlayer;
+
public static Stage primaryStage;
static Pane primaryPane = new Pane();
@@ -52,6 +62,9 @@ public class Driver extends Application
@Override
public void start(Stage newPrimaryStage)
{
+ mediaPlayer = new AudioFilePlayer("src/assets/MenuMusicPlaceholder.wav");
+ mediaPlayer.play();
+
primaryStage = newPrimaryStage;
Scene primaryScene = new Scene(primaryPane, 800, 600);
@@ -60,6 +73,7 @@ public class Driver extends Application
primaryStage.setScene(primaryScene);
primaryStage.setTitle("NPE Hero");
+ fixMenuSync();
setMenu(new MainMenu());
setBackground("assets/forest.png");
@@ -73,6 +87,11 @@ public class Driver extends Application
primaryStage.show();
}
+ private void fixMenuSync() {
+ primaryPane.getChildren().addAll(placeHolder);
+ primaryPane.getChildren().removeAll(placeHolder);
+ }
+
/**
* Replaces/adds a new pane to the primaryPane
* @param pane the new pane