diff options
Diffstat (limited to 'src/main/java/net/sowgro/npehero/gameplay')
| -rwxr-xr-x | src/main/java/net/sowgro/npehero/gameplay/ScoreController.java | 112 | ||||
| -rwxr-xr-x | src/main/java/net/sowgro/npehero/gameplay/SongPlayer.java | 9 | 
2 files changed, 27 insertions, 94 deletions
diff --git a/src/main/java/net/sowgro/npehero/gameplay/ScoreController.java b/src/main/java/net/sowgro/npehero/gameplay/ScoreController.java index 4c603c1..a03bab6 100755 --- a/src/main/java/net/sowgro/npehero/gameplay/ScoreController.java +++ b/src/main/java/net/sowgro/npehero/gameplay/ScoreController.java @@ -1,115 +1,43 @@  package net.sowgro.npehero.gameplay; -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.property.StringProperty; -import net.sowgro.npehero.main.Sound; +import javafx.beans.property.IntegerProperty; +import javafx.beans.property.SimpleIntegerProperty; -public class ScoreController{ +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"); +    public IntegerProperty combo = new SimpleIntegerProperty(0); +    public IntegerProperty comboMultiplier = new SimpleIntegerProperty(1); +    public IntegerProperty score = new SimpleIntegerProperty(0); + +    public ScoreController() { +        combo.addListener((_, _, _) -> { +            if      (combo.get() >= 30) { comboMultiplier.set(4); } +            else if (combo.get() >= 20) { comboMultiplier.set(3); } +            else if (combo.get() >= 10) { comboMultiplier.set(2); } +            else                        { comboMultiplier.set(1); } +        }); +    }      /**       * 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!"); +        combo.set(combo.get() + 1); +        score.set(score.get() + 300 * comboMultiplier.get());      }      /**       * 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"); +        combo.set(combo.get() + 1); +        score.set(score.get() + 100 * comboMultiplier.get());      }      /**       * Called when the user misses a note       */      public void miss() { -        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); +        combo.set(0);      }  } diff --git a/src/main/java/net/sowgro/npehero/gameplay/SongPlayer.java b/src/main/java/net/sowgro/npehero/gameplay/SongPlayer.java index f3abf91..22dea09 100755 --- a/src/main/java/net/sowgro/npehero/gameplay/SongPlayer.java +++ b/src/main/java/net/sowgro/npehero/gameplay/SongPlayer.java @@ -80,7 +80,7 @@ public class SongPlayer extends HBox {          }));          // schedule the game over screen to show at the end          timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(songLength + FALL_TIME + START_DELAY), _ -> { -            Driver.setMenu(new GameOver(level, diff, prev, scoreCounter.getScore())); +            Driver.setMenu(new GameOver(level, diff, prev, scoreCounter));              cancel();          })); @@ -89,12 +89,13 @@ public class SongPlayer extends HBox {              for (int i = 0; i < lanes.length; i++) {                  if (e.getCode() == Control.lanes[i].getKey()) {                      checkNote(lanes[i]); +                    e.consume();                  }              }              if (e.getCode() == Control.LEGACY_PRINT.getKey()) {                  System.out.println("" + timeline.getCurrentTime()); +                e.consume();              } -            e.consume();          };          Driver.primaryStage.addEventFilter(KeyEvent.KEY_PRESSED, eventHandler); @@ -142,6 +143,7 @@ public class SongPlayer extends HBox {          anim.setOnFinished(_ -> {              if (lane.pane.getChildren().remove(block) && !done) {                  scoreCounter.miss(); +                Sound.playSfx(Sound.MISS);                  FillTransition ft = new FillTransition(Duration.millis(500), lane.target.rect);                  ft.setFromValue(Color.RED);                  ft.setToValue(lane.target.getFillColor()); @@ -236,17 +238,20 @@ public class SongPlayer extends HBox {                  ft.setFromValue(Color.WHITE);                  ft.play();                  scoreCounter.perfect(); +                Sound.playSfx(Sound.HIT);                  return 2;              }              if (distance < super.getHeight() / 4) {                  ft.setFromValue(Color.CYAN);                  ft.play();                  scoreCounter.good(); +                Sound.playSfx(Sound.HIT);                  return 1;              }              ft.setFromValue(Color.RED);              ft.play();              scoreCounter.miss(); +            Sound.playSfx(Sound.MISS);              return 0;          }          return -1;  | 
