diff options
Diffstat (limited to 'src/main/java/net/sowgro/npehero/gameplay')
-rwxr-xr-x | src/main/java/net/sowgro/npehero/gameplay/ScoreController.java | 117 | ||||
-rwxr-xr-x | src/main/java/net/sowgro/npehero/gameplay/SongPlayer.java | 20 |
2 files changed, 129 insertions, 8 deletions
diff --git a/src/main/java/net/sowgro/npehero/gameplay/ScoreController.java b/src/main/java/net/sowgro/npehero/gameplay/ScoreController.java new file mode 100755 index 0000000..1865a56 --- /dev/null +++ b/src/main/java/net/sowgro/npehero/gameplay/ScoreController.java @@ -0,0 +1,117 @@ +package net.sowgro.npehero.gameplay; + +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; +import net.sowgro.npehero.main.Sound; + +public class ScoreController{ + + private int score = 0; + private int combo = 0; + private int comboMultiplier=1; + public StringProperty scoreProperty = new SimpleStringProperty("0"); + public StringProperty comboProperty = new SimpleStringProperty("0"); + + /** + * Called when the user performs a perfect hit + */ + public void perfect() { + combo(); + score += 300*comboMultiplier; + scoreProperty.setValue(score+""); + comboProperty.setValue(combo +""); + // System.out.println("Perfect!"); + } + + /** + * called when the user performs an okay hit + */ + public void good() { + combo(); + score += 100*comboMultiplier; + scoreProperty.setValue(score+""); + comboProperty.setValue(combo+""); + // System.out.println("Good"); + } + + /** + * Called when the user misses a note + */ + public void miss(boolean muted) { + if (!muted) { + Sound.playSfx(Sound.MISS); + } + combo = 0; + comboMultiplier = 1; + scoreProperty.setValue(score+""); + comboProperty.setValue(combo+""); + // System.out.println("Miss"); + } + + /* + * Increments the combo by one + */ + private void combo() { + Sound.playSfx(Sound.HIT); + combo++; + + if (combo == 2) { + comboMultiplier = 2; + } + + if (combo == 4) { + comboMultiplier = 4; + } + + if (combo == 8) { + comboMultiplier = 8; + } + } + + /** + * @return current score + */ + public int getScore() + { + return score; + } + + /** + * @return current combo + */ + public int getCombo() + { + return combo; + } + + /** + * @param newScore: the score to be set, only used in debug + */ + public void setScore(int newScore) + { + score = newScore; + scoreProperty.setValue(newScore+""); + } + + /** + * @param newCombo: the combo to be set, only used in debug + */ + public void setCombo(int newCombo) + { + combo = newCombo; + comboProperty.setValue(newCombo+""); + } + + /** + * prints values into console + */ + public void print() + { + System.out.println("--"); + System.out.println(combo); + System.out.println(score); + System.out.println(""); + System.out.println(scoreProperty); + System.out.println(comboProperty); + } +} diff --git a/src/main/java/net/sowgro/npehero/gameplay/SongPlayer.java b/src/main/java/net/sowgro/npehero/gameplay/SongPlayer.java index dc74b30..b025c06 100755 --- a/src/main/java/net/sowgro/npehero/gameplay/SongPlayer.java +++ b/src/main/java/net/sowgro/npehero/gameplay/SongPlayer.java @@ -10,6 +10,7 @@ import java.util.Queue; import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.UnsupportedAudioFileException; +import javafx.event.EventHandler; import javafx.scene.input.KeyEvent; import javafx.scene.media.Media; import net.sowgro.npehero.Driver; @@ -26,8 +27,7 @@ import javafx.animation.*; import javafx.util.*; import net.sowgro.npehero.main.Difficulty; import net.sowgro.npehero.main.Level; -import net.sowgro.npehero.main.ScoreController; -import net.sowgro.npehero.main.SoundController; +import net.sowgro.npehero.main.Sound; //hi aidan here are some objects you can use @@ -47,6 +47,8 @@ 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 + private EventHandler<KeyEvent> eventHandler; + private File song; private boolean songIsPlaying = false; private boolean missMute = false; @@ -100,7 +102,7 @@ public class SongPlayer extends Pane { } public SongPlayer(Level lvl, Difficulty d, Pane p, ScoreController cntrl) { - SoundController.endSong(); + Sound.stopSong(); song = lvl.song; if (lvl.background != null) { @@ -134,7 +136,7 @@ public class SongPlayer extends Pane { genButton(jButton); genButton(kButton); - Driver.primaryStage.addEventFilter(KeyEvent.KEY_PRESSED, e -> { + eventHandler = e -> { /** * The keyboard detection for the game: when a key is pressed it * calls the checkNote() method for the corresponding lane @@ -164,7 +166,8 @@ public class SongPlayer extends Pane { e.consume(); //prints the user's current score and combo, for debugging purposes //System.out.println("Score: " + scoreCounter.getScore() + "\nCombo: " + scoreCounter.getCombo() + "\n"); - }); + }; + Driver.primaryStage.addEventFilter(KeyEvent.KEY_PRESSED, eventHandler); buttonBox.setAlignment(Pos.CENTER); //puts the buttons in the center of the screen buttonBox.getChildren().addAll(dButton, fButton, sButton, jButton, kButton); //places the buttons in the correct row order @@ -255,7 +258,7 @@ public class SongPlayer extends Pane { } if (!songIsPlaying && timer.time() > 0.0) { songIsPlaying = true; - SoundController.playSong(new Media(song.toURI().toString())); + Sound.playSong(new Media(song.toURI().toString())); } } }; @@ -273,9 +276,10 @@ public class SongPlayer extends Pane { * @throws UnsupportedAudioFileException */ public void cancel() { + Driver.primaryStage.removeEventFilter(KeyEvent.KEY_PRESSED, eventHandler); missMute = true; - SoundController.endSong(); - SoundController.playSong(SoundController.MENUSONG); + Sound.stopSong(); + Sound.playSong(Sound.MENU_SONG); Driver.setMenuBackground(); gameLoop.stop(); } |