aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAidan Ross <aross02@fairport.org>2023-05-24 13:33:59 -0400
committerAidan Ross <aross02@fairport.org>2023-05-24 13:33:59 -0400
commit33a969310a788ae5c10be87f04dd0ff5cbcc6399 (patch)
tree2ced563256888a01eedf259a6dde06dafe01e165
parentb47c8be84cc5b269e32dc44f7e67a1dd426d5349 (diff)
downloadNPEhero-33a969310a788ae5c10be87f04dd0ff5cbcc6399.tar.gz
NPEhero-33a969310a788ae5c10be87f04dd0ff5cbcc6399.tar.bz2
NPEhero-33a969310a788ae5c10be87f04dd0ff5cbcc6399.zip
Scoring now almost works, and finished the visuals for hitting a note
-rw-r--r--src/fallTest/Driver.java5
-rw-r--r--src/fallTest/NoteField.java37
-rw-r--r--src/fallTest/Score.java2
-rw-r--r--src/fallTest/SongPlayer.java225
-rw-r--r--src/fallTest/TButton.java9
-rw-r--r--src/fallTest/newSongPlayer.java289
6 files changed, 179 insertions, 388 deletions
diff --git a/src/fallTest/Driver.java b/src/fallTest/Driver.java
index bb1d73e..7e08e46 100644
--- a/src/fallTest/Driver.java
+++ b/src/fallTest/Driver.java
@@ -33,11 +33,12 @@ public class Driver extends Application
Scene primaryScene = new Scene(primaryPane, 800, 600);
primaryScene.getStylesheets().add("gui/style.css");
primaryStage.setScene(primaryScene);
- //newSongPlayer player = new newSongPlayer();
+ newSongPlayer player = new newSongPlayer();
primaryStage.setTitle("TEST");
- //primaryPane.getChildren().add(player);
+ primaryPane.getChildren().add(player);
setBackground("assets/water.png");
primaryStage.show();
+ player.init();
}
public static void setBackground(String url)
diff --git a/src/fallTest/NoteField.java b/src/fallTest/NoteField.java
index a24fea0..956acd2 100644
--- a/src/fallTest/NoteField.java
+++ b/src/fallTest/NoteField.java
@@ -3,32 +3,23 @@
*/
package fallTest;
+import javafx.animation.TranslateTransition;
+
public class NoteField
{
- private boolean failed = false;
- private final int NOTESPEED = 5;
- private int yPos = SongPlayer.HEIGHT;
-
- public void gameTick() {
- if (!failed) {
- if (yPos > 0) {
- yPos -= NOTESPEED;
- }
- else {
- failed = true;
- }
- }
- }
-
- public int goalDistance() {
- return (yPos-((SongPlayer.HEIGHT)/6));
+ private Block note;
+ private TranslateTransition anim;
+
+ public NoteField(Block newNote, TranslateTransition newAnim) {
+ note = newNote;
+ anim = newAnim;
}
-
- public boolean getFailed() {
- return failed;
+
+ public Block getNote() {
+ return note;
}
-
- public int getY() {
- return yPos;
+
+ public TranslateTransition getAnim() {
+ return anim;
}
}
diff --git a/src/fallTest/Score.java b/src/fallTest/Score.java
index 7965261..bf0d698 100644
--- a/src/fallTest/Score.java
+++ b/src/fallTest/Score.java
@@ -15,7 +15,7 @@ public class Score
System.out.println("Perfect!");
}
- public void close() {
+ public void good() {
score += 100*comboMultiplier;
System.out.println("Good");
}
diff --git a/src/fallTest/SongPlayer.java b/src/fallTest/SongPlayer.java
deleted file mode 100644
index a1b9142..0000000
--- a/src/fallTest/SongPlayer.java
+++ /dev/null
@@ -1,225 +0,0 @@
-/*Name: Guitar Hero Project
- *Description: Contains the main game loop for gameplay
- */
-package fallTest;
-
-import java.awt.*;
-import java.awt.event.*;
-import javax.swing.*;
-import java.util.*;
-//test
-public class SongPlayer
-{
- Timer time = new Timer();
-
- public static final int HEIGHT = 650;
- public static final int LENGTH = 400;
-
- private final int BLENGTH = LENGTH/7;
- private final int BHEIGHT = HEIGHT/20;
-
- JFrame frame = new JFrame("Guitar Hero"); //creates the frame
-
- JButton d = new JButton("D"); //button declarations
- JButton f = new JButton("F");
- JButton space= new JButton("SPC");
- JButton j = new JButton("J");
- JButton k = new JButton("K");
-
- Queue<NoteInfo> dSends = new LinkedList<NoteInfo>(); //Queue that dictates when to send the notes
- ArrayList<NoteField> dLane = new ArrayList<NoteField>(); //Array list containing all the notes currently on the field
- ArrayList<JButton> dVis = new ArrayList<JButton>(); //Array list containing the visual representations of the notes in lanes
-
- Queue<NoteInfo> fSends = new LinkedList<NoteInfo>();
- ArrayList<NoteField> fLane = new ArrayList<NoteField>();
- ArrayList<JButton> fVis = new ArrayList<JButton>();
-
- Queue<NoteInfo> spaceSends = new LinkedList<NoteInfo>();
- ArrayList<NoteField> spaceLane = new ArrayList<NoteField>();
- ArrayList<JButton> spaceVis = new ArrayList<JButton>();
-
- Queue<NoteInfo> jSends = new LinkedList<NoteInfo>();
- ArrayList<NoteField> jLane = new ArrayList<NoteField>();
- ArrayList<JButton> jVis = new ArrayList<JButton>();
-
- Queue<NoteInfo> kSends = new LinkedList<NoteInfo>();
- ArrayList<NoteField> kLane = new ArrayList<NoteField>();
- ArrayList<JButton> kVis = new ArrayList<JButton>();
-
- Score score = new Score();
-
- /**
- * Establishes what the chart for the song is going to look like
- */
- public void loadSong() {
- dSends.add(new NoteInfo(4000));
- dSends.add(new NoteInfo(4333));
- dSends.add(new NoteInfo(4666));
- fSends.add(new NoteInfo(5000));
- kSends.add(new NoteInfo(5500));
- spaceSends.add(new NoteInfo(6000));
- jSends.add(new NoteInfo(6000));
- jSends.add(new NoteInfo(6250));
- dSends.add(new NoteInfo(6500));
- jSends.add(new NoteInfo(6750));
- spaceSends.add(new NoteInfo(7000));
- fSends.add(new NoteInfo(7500));
- jSends.add(new NoteInfo(7750));
- spaceSends.add(new NoteInfo(8000));
- fSends.add(new NoteInfo(8500));
- jSends.add(new NoteInfo(8500));
- dSends.add(new NoteInfo(9000));
- spaceSends.add(new NoteInfo(9000));
- kSends.add(new NoteInfo(9000));
- spaceSends.add(new NoteInfo(9500));
-
- kSends.add(new NoteInfo(10000));
- dSends.add(new NoteInfo(10000));
- kSends.add(new NoteInfo(10333));
- fSends.add(new NoteInfo(10333));
- kSends.add(new NoteInfo(10666));
- spaceSends.add(new NoteInfo(10666));
- dSends.add(new NoteInfo(11000));
- spaceSends.add(new NoteInfo(11000));
- dSends.add(new NoteInfo(11333));
- jSends.add(new NoteInfo(11333));
- dSends.add(new NoteInfo(11666));
- kSends.add(new NoteInfo(11666));
- spaceSends.add(new NoteInfo(12000));
- }
-
-
- /**
- * Creates the GUI used to play the game
- */
- public void createAndShowGui() {
-
- d.setBounds(1*BLENGTH, (5*HEIGHT)/6, BLENGTH, BHEIGHT); //makes the button bounds for each button
- f.setBounds(2*BLENGTH, (5*HEIGHT)/6, BLENGTH, BHEIGHT);
- space.setBounds(3*BLENGTH, (5*HEIGHT)/6, BLENGTH, BHEIGHT);
- j.setBounds(4*BLENGTH, (5*HEIGHT)/6, BLENGTH, BHEIGHT);
- k.setBounds(5*BLENGTH, (5*HEIGHT)/6, BLENGTH, BHEIGHT);
- d.setFocusable(false); //makes it so you can't focus on the button
- f.setFocusable(false);
- space.setFocusable(false);
- j.setFocusable(false);
- k.setFocusable(false);
-
-
- frame.add(d); //adds the buttons to the frame
- frame.add(f);
- frame.add(space);
- frame.add(j);
- frame.add(k);
-
- frame.setSize(LENGTH, HEIGHT); //sets the size of the frame
- frame.setLayout(null);
- frame.setVisible(true); //makes the frame visible
-
-
- while (true) { //TRY TO FIND A BETTER SOLUTION FOR THIS?? maybe something like sends.size() > 0 || lanes.size() > 0
-
- update(d, dSends, dLane, dVis, 'd', "dPress", 1); //updates the provided lane
- update(f, fSends, fLane, fVis, 'f', "fPress", 2);
- update(space, spaceSends, spaceLane, spaceVis, ' ', "spacePress", 3);
- update(j, jSends, jLane, jVis, 'j', "jPress", 4);
- update(k, kSends, kLane, kVis, 'k', "kPress", 5);
-
- frame.repaint(); //updates the visuals every frame
-
- try {
- Thread.sleep(10); //THIS IS PROBABLY NOT THE BEST WAY TO DO THIS
- } catch (InterruptedException e)
- {
- e.printStackTrace();
- }
- }
- }
-
- /**
- * Updates a lane. An update involves:
- * Checking to see if a note needs to be sent down a lane
- * Checking to see if the user hit the button
- * Checking to see if any notes have moved past the lane
- * @param sends The sending queue for the given lane
- * @param lane The place where note information is stored for notes currently in that lane
- * @param vis The place where the visual representation for a note is stored in that lane
- * @param key The button on the keyboard corresponding to the button for the lane being updated
- * @param id The id for the action map
- * @param k The lane number
- */
- private void update(JButton button, Queue<NoteInfo> sends, ArrayList<NoteField> lane, ArrayList<JButton> vis, char key, String id, int k) {
- if (!sends.isEmpty() && sends.peek().getTime()-time.time()<3) { //checks if any notes in the queue need to be sent at this time
- lane.add(new NoteField()); //adds that note's information to the lane list
-
- vis.add(new JButton()); //creates a visual representation of that note in the visualizer list
- frame.add(vis.get(vis.size()-1));
-
- sends.remove(); //removes the note just sent from the sending queue
- }
-
- if (lane.size() > 0) { //if there are any notes in the lanes, tests for a button press
- button.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(key), id); //Input map and Action map setting
- button.getActionMap().put(id, new AbstractAction() { //Defines what happens when the proper button is pressed
- public void actionPerformed(ActionEvent e)
- {
- if (lane.size() > 0) {
- int i = getClosestNote(lane);
- int dist = (int)Math.abs(lane.get(i).goalDistance());
-
- lane.remove(i); //removes the notes and visual representation from the playing field when the button is pressed
- frame.remove(vis.get(i));
- vis.remove(i);
-
- if (dist > 2*BHEIGHT) { //Determines what to add to the score depending on the proximity of the note
- score.miss();
- }
- else if (dist > BHEIGHT) {
- score.combo();
- score.close();
- }
- else {
- score.combo();
- score.perfect();
- }
-
- System.out.println("Score: " + score.getScore() + " Combo: " + score.getCombo());
- }
- }
- });
- }
-
- for (int i=0; i<lane.size(); i++) { //goes through every note on the field
- lane.get(i).gameTick(); //moves every note down
- vis.get(i).setBounds(k*BLENGTH, HEIGHT-lane.get(i).getY(), BLENGTH, BHEIGHT);
-
- if (lane.size() > 0 && lane.get(i).getFailed()) { //if the note has passed into the fail boundary, removes the note from the field
- score.miss();
- System.out.println(score.getScore() + " Combo: " + score.getCombo());
-
-
- lane.remove(i);
- frame.remove(vis.get(i));
- vis.remove(i);
-
- i--;
- }
- }
- }
-
- /**
- * Finds the note closest to the goal
- * @return the location in the array list of the closest note
- */
- private int getClosestNote(ArrayList<NoteField> searchLane) {
- int pos = 0;
-
- for (int i=0; i<searchLane.size(); i++) {
- if (Math.abs(searchLane.get(i).goalDistance()) < Math.abs(searchLane.get(pos).goalDistance())) {
- pos = i;
- }
- }
-
- return pos;
- }
-}
diff --git a/src/fallTest/TButton.java b/src/fallTest/TButton.java
index 117a8e1..172e810 100644
--- a/src/fallTest/TButton.java
+++ b/src/fallTest/TButton.java
@@ -11,12 +11,13 @@ import javafx.scene.paint.*;
public class TButton extends Rectangle
{
+ private Color col;
public TButton(Color c, double a, double b, int r)
{
super();
- Color newCol = new Color(c.darker().getRed(), c.darker().getGreen(), c.darker().getBlue(), 0.45);
- super.setFill(newCol);
+ col = new Color(c.darker().getRed(), c.darker().getGreen(), c.darker().getBlue(), 0.45);
+ super.setFill(col);
super.setWidth(a);
super.setHeight(b);
super.setArcHeight(r);
@@ -24,4 +25,8 @@ public class TButton extends Rectangle
super.setStroke(c);
super.setStrokeWidth(5);
}
+
+ public Color getColor() {
+ return col;
+ }
} \ No newline at end of file
diff --git a/src/fallTest/newSongPlayer.java b/src/fallTest/newSongPlayer.java
index d93d098..423355f 100644
--- a/src/fallTest/newSongPlayer.java
+++ b/src/fallTest/newSongPlayer.java
@@ -1,43 +1,27 @@
package fallTest;
-import javafx.event.EventHandler;
-
-import java.awt.Insets;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
-import javafx.beans.property.DoubleProperty;
-import javafx.event.*;
-import javafx.event.ActionEvent;
import javafx.geometry.Pos;
-import javafx.scene.control.Button;
-import javafx.scene.effect.BlurType;
-import javafx.scene.effect.DropShadow;
import javafx.scene.input.KeyCode;
-import javafx.scene.layout.Border;
-import javafx.scene.layout.BorderStroke;
-import javafx.scene.layout.BorderStrokeStyle;
-import javafx.scene.layout.BorderWidths;
-import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
-import javafx.scene.text.Font;
-import javafx.scene.text.Text;
import javafx.animation.*;
-import javafx.animation.KeyFrame;
import javafx.util.*;
import main.Difficulty;
import main.ScoreController;
-public class newSongPlayer extends Pane
-{
+public class newSongPlayer extends Pane {
Timer timer = new Timer();
- final int TIME = 1500; //delay for notes falling down the screen
+ final int TIME = 1500; // delay for notes falling down the screen
+
+ Score scoreCounter = new Score();
Rectangle goalPerfect = new Rectangle();
HBox buttonBox = new HBox();
@@ -45,8 +29,8 @@ public class newSongPlayer extends Pane
VBox place = new VBox();
TButton dButton = new TButton(Color.RED, 50, 50, 5);
- Queue<NoteInfo> dSends = new LinkedList<NoteInfo>(); //Queue that dictates when to send the notes
- ArrayList<Block> dLane = new ArrayList<Block>(); //Array list containing all the notes currently on the field
+ Queue<NoteInfo> dSends = new LinkedList<NoteInfo>(); // Queue that dictates when to send the notes
+ ArrayList<Block> dLane = new ArrayList<Block>(); // Array list containing all the notes currently on the field
TButton fButton = new TButton(Color.BLUE, 50, 50, 5);
Queue<NoteInfo> fSends = new LinkedList<NoteInfo>();
@@ -64,55 +48,56 @@ public class newSongPlayer extends Pane
Queue<NoteInfo> kSends = new LinkedList<NoteInfo>();
ArrayList<Block> kLane = new ArrayList<Block>();
+ /**
+ * Establishes what the chart for the song is going to look like
+ */
+ public void loadSong() {
+ dSends.add(new NoteInfo(4000));
+ dSends.add(new NoteInfo(4333));
+ dSends.add(new NoteInfo(4666));
+ fSends.add(new NoteInfo(5000));
+ kSends.add(new NoteInfo(5500));
+ spaceSends.add(new NoteInfo(6000));
+ jSends.add(new NoteInfo(6000));
+ jSends.add(new NoteInfo(6250));
+ dSends.add(new NoteInfo(6500));
+ jSends.add(new NoteInfo(6750));
+ spaceSends.add(new NoteInfo(7000));
+ fSends.add(new NoteInfo(7500));
+ jSends.add(new NoteInfo(7750));
+ spaceSends.add(new NoteInfo(8000));
+ fSends.add(new NoteInfo(8500));
+ jSends.add(new NoteInfo(8500));
+ dSends.add(new NoteInfo(9000));
+ spaceSends.add(new NoteInfo(9000));
+ kSends.add(new NoteInfo(9000));
+ spaceSends.add(new NoteInfo(9500));
+ kSends.add(new NoteInfo(10000));
+ dSends.add(new NoteInfo(10000));
+ kSends.add(new NoteInfo(10333));
+ fSends.add(new NoteInfo(10333));
+ kSends.add(new NoteInfo(10666));
+ spaceSends.add(new NoteInfo(10666));
+ dSends.add(new NoteInfo(11000));
+ spaceSends.add(new NoteInfo(11000));
+ dSends.add(new NoteInfo(11333));
- /**
- * Establishes what the chart for the song is going to look like
- */
- public void loadSong() {
- dSends.add(new NoteInfo(4000));
- dSends.add(new NoteInfo(4333));
- dSends.add(new NoteInfo(4666));
- fSends.add(new NoteInfo(5000));
- kSends.add(new NoteInfo(5500));
- spaceSends.add(new NoteInfo(6000));
- jSends.add(new NoteInfo(6000));
- jSends.add(new NoteInfo(6250));
- dSends.add(new NoteInfo(6500));
- jSends.add(new NoteInfo(6750));
- spaceSends.add(new NoteInfo(7000));
- fSends.add(new NoteInfo(7500));
- jSends.add(new NoteInfo(7750));
- spaceSends.add(new NoteInfo(8000));
- fSends.add(new NoteInfo(8500));
- jSends.add(new NoteInfo(8500));
- dSends.add(new NoteInfo(9000));
- spaceSends.add(new NoteInfo(9000));
- kSends.add(new NoteInfo(9000));
- spaceSends.add(new NoteInfo(9500));
-
- kSends.add(new NoteInfo(10000));
- dSends.add(new NoteInfo(10000));
- kSends.add(new NoteInfo(10333));
- fSends.add(new NoteInfo(10333));
- kSends.add(new NoteInfo(10666));
- spaceSends.add(new NoteInfo(10666));
- dSends.add(new NoteInfo(11000));
- spaceSends.add(new NoteInfo(11000));
- dSends.add(new NoteInfo(11333));
- jSends.add(new NoteInfo(11333));
- dSends.add(new NoteInfo(11666));
- kSends.add(new NoteInfo(11666));
- spaceSends.add(new NoteInfo(12000));
- }
-
- public newSongPlayer(main.Level lvl, Difficulty d, Pane p, ScoreController cntrl){
-
+ jSends.add(new NoteInfo(11333));
+ dSends.add(new NoteInfo(11666));
+ kSends.add(new NoteInfo(11666));
+ spaceSends.add(new NoteInfo(12000));
+ }
+
+ public newSongPlayer(main.Level lvl, Difficulty d, Pane p, ScoreController cntrl) {
+ }
+
+ public newSongPlayer() {
}
- public void init() {
+ public void init() {
loadSong();
-
+
Rectangle field = new Rectangle(50, 50, new Color(0, 0, 0, 0.7));
field.heightProperty().bind(this.getScene().getWindow().heightProperty());
field.widthProperty().bind(this.getScene().getWindow().widthProperty().divide(2.7).add(50));
@@ -125,102 +110,92 @@ public class newSongPlayer extends Pane
genButton(sButton);
genButton(jButton);
genButton(kButton);
-
- this.getScene().setOnKeyPressed(e -> {
+
+ this.getScene().setOnKeyPressed(e -> {
if (e.getCode() == KeyCode.D) {
- System.out.println("D");
- if (dLane.size() > 0 && distanceToGoal(dLane.get(getClosestNote(dLane))) < 20) {
- super.getChildren().removeAll(dLane.get(getClosestNote(dLane)));
- dLane.remove(dLane.get(getClosestNote(dLane)));
- System.out.println("Hit");
- }
+ checkNote(dLane, dButton);
}
if (e.getCode() == KeyCode.F) {
- System.out.println("F");
- if (fLane.size() > 0 && fLane.get(getClosestNote(fLane)).intersects(buttonBox.getBoundsInLocal())) {
- super.getChildren().removeAll(fLane.get(getClosestNote(fLane)));
- fLane.remove(fLane.get(getClosestNote(fLane)));
- System.out.println("Hit");
- }
+ checkNote(fLane, fButton);
}
if (e.getCode() == KeyCode.SPACE) {
- System.out.println("SPC");
- if (spaceLane.size() > 0 && spaceLane.get(getClosestNote(spaceLane)).intersects(buttonBox.getBoundsInLocal())) {
- super.getChildren().removeAll(spaceLane.get(getClosestNote(spaceLane)));
- spaceLane.remove(spaceLane.get(getClosestNote(spaceLane)));
- System.out.println("Hit");
- }
+ checkNote(spaceLane, sButton);
}
if (e.getCode() == KeyCode.J) {
- System.out.println("J");
- if (jLane.size() > 0 && jLane.get(getClosestNote(jLane)).intersects(buttonBox.getBoundsInLocal())) {
- super.getChildren().removeAll(jLane.get(getClosestNote(jLane)));
- jLane.remove(jLane.get(getClosestNote(jLane)));
- System.out.println("Hit");
- }
+ checkNote(jLane, jButton);
}
if (e.getCode() == KeyCode.K) {
- System.out.println("K");
- if (kLane.size() > 0 && kLane.get(getClosestNote(kLane)).intersects(buttonBox.getBoundsInLocal())) {
- super.getChildren().removeAll(kLane.get(getClosestNote(kLane)));
- kLane.remove(kLane.get(getClosestNote(kLane)));
- System.out.println("Hit");
- }
+ checkNote(kLane, kButton);
}
+ System.out.println("Score: " + scoreCounter.getScore() + "\nCombo: " + scoreCounter.getCombo() + "\n");
});
buttonBox.setStyle("-fx-padding: 0;" + "-fx-border-style: solid inside;"
- + "-fx-border-width: 0;" + "-fx-border-insets: 20;"
- + "-fx-background-color: black;" + "-fx-opacity: 0.67;");
+ + "-fx-border-width: 0;" + "-fx-border-insets: 20;"
+ + "-fx-background-color: black;" + "-fx-opacity: 0.67;");
buttonBox.setAlignment(Pos.CENTER);
- buttonBox.getChildren().addAll(dButton, fButton, sButton, jButton, kButton);
- buttonBox.setSpacing(10);
-
- polish.getChildren().addAll(field);
- polish.setAlignment(Pos.BASELINE_CENTER);
-
+ buttonBox.getChildren().addAll(dButton, fButton, sButton, jButton, kButton);
+ buttonBox.setSpacing(10);
+
+ polish.getChildren().addAll(field);
+ polish.setAlignment(Pos.BASELINE_CENTER);
+
place.prefWidthProperty().bind(this.getScene().widthProperty());
place.prefHeightProperty().bind(this.getScene().heightProperty());
- place.getChildren().addAll(buttonBox);
+ place.getChildren().addAll(buttonBox);
place.setAlignment(Pos.BOTTOM_CENTER);
- place.setSpacing(10);
-
- StackPane root = new StackPane();
- root.getChildren().addAll(polish, place);
+ place.setSpacing(10);
+
+ StackPane root = new StackPane();
+ root.getChildren().addAll(polish, place);
goalPerfect.setY(dButton.getY());
- super.getChildren().addAll(root, goalPerfect);
+ super.getChildren().addAll(root, goalPerfect);
gameLoop.start();
}
-
+
+ /**
+ * Checks if a note should be sent at the current time, and sends the note if it
+ * needs to be
+ *
+ * @param sends the queue to check
+ * @param lane the lane to send the note to
+ * @param pos the x pos of the note to be sent
+ * @param c the color of the sent note
+ */
public void sendNote(Queue<NoteInfo> sends, ArrayList<Block> lane, double pos, Color c) {
if (sends.peek() != null && timer.time() > sends.peek().getTime()) {
TranslateTransition anim = new TranslateTransition(Duration.millis(TIME));
lane.add(new Block(c, 50, 50, 5));
- int index = lane.size()-1;
+ int index = lane.size() - 1;
sends.remove();
- lane.get(lane.size()-1).heightProperty().bind(this.getScene().getWindow().widthProperty().divide(16));
- lane.get(lane.size()-1).widthProperty().bind(this.getScene().getWindow().widthProperty().divide(16));
- lane.get(lane.size()-1).arcHeightProperty().bind(this.getScene().getWindow().widthProperty().divide(50));
- lane.get(lane.size()-1).arcWidthProperty().bind(this.getScene().getWindow().widthProperty().divide(50));
- lane.get(lane.size()-1).setX(pos);
+ lane.get(lane.size() - 1).heightProperty().bind(this.getScene().getWindow().widthProperty().divide(16));
+ lane.get(lane.size() - 1).widthProperty().bind(this.getScene().getWindow().widthProperty().divide(16));
+ lane.get(lane.size() - 1).arcHeightProperty().bind(this.getScene().getWindow().widthProperty().divide(50));
+ lane.get(lane.size() - 1).arcWidthProperty().bind(this.getScene().getWindow().widthProperty().divide(50));
+ lane.get(lane.size() - 1).setX(pos);
lane.get(index).setY(-lane.get(index).getHeight());
anim.setByY(this.getScene().getHeight() + lane.get(index).getHeight());
anim.setCycleCount(1);
anim.setAutoReverse(false);
- anim.setNode(lane.get(lane.size()-1));
+ anim.setNode(lane.get(lane.size() - 1));
anim.play();
anim.setOnFinished(e -> {
super.getChildren().removeAll(anim.getNode());
+
});
- super.getChildren().add(lane.get(lane.size()-1));
+ super.getChildren().add(lane.get(lane.size() - 1));
}
}
-
+ /**
+ * Sets up the given button
+ *
+ * @param button
+ */
public void genButton(TButton button) {
button.heightProperty().bind(this.getScene().getWindow().widthProperty().divide(16));
button.widthProperty().bind(this.getScene().getWindow().widthProperty().divide(16));
@@ -229,6 +204,9 @@ public class newSongPlayer extends Pane
button.strokeWidthProperty().bind(this.getScene().getWindow().widthProperty().divide(210));
}
+ /**
+ * The background test that is run on every frame of the game
+ */
AnimationTimer gameLoop = new AnimationTimer() {
@Override
@@ -241,26 +219,67 @@ public class newSongPlayer extends Pane
}
};
+ /**
+ * returns the pos in the lane array of the closest note to the goal
+ *
+ * @param searchLane
+ * @return the position of the note
+ */
private int getClosestNote(ArrayList<Block> searchLane) {
- int pos = 0;
-
- for (int i=0; i<searchLane.size(); i++) {
- if (distanceToGoal(searchLane.get(i)) < distanceToGoal(searchLane.get(pos))) {
- pos = i;
- }
- }
- return pos;
- }
+ int pos = 0;
+
+ for (int i = 0; i < searchLane.size(); i++) {
+ if (distanceToGoal(searchLane.get(i)) < distanceToGoal(searchLane.get(pos))) {
+ pos = i;
+ }
+ }
+ return pos;
+ }
+ /**
+ * Returns the distance to the goal of the given note
+ *
+ * @param note
+ * @return
+ */
private double distanceToGoal(Block note) {
- return Math.abs(note.getY()-dButton.getY());
+ return Math.abs((this.getScene().getHeight() - note.getTranslateY()) - dButton.getY());
}
- private void checkForNote(ArrayList<Block> lane) {
- if (lane.size() > 0 && distanceToGoal(lane.get(getClosestNote(lane))) < 50) {
+ /**
+ * When the player hits the key, checks the quality of the hit
+ * @param lane the lane checking for a hit
+ * @param button the button checking for a hit
+ * @return 2 for a perfect hit, 1 for a good hit, 0 for a miss, and -1 if there are no notes to hit
+ */
+ private int checkNote(ArrayList<Block> lane, TButton button) {
+ double distance = distanceToGoal(lane.get(getClosestNote(lane)));
+ if (lane.size() > 0 && distance < this.getScene().getHeight() / 3) {
+
+ FillTransition ft = new FillTransition(Duration.millis(500), button);
+ ft.setToValue(button.getColor());
+
super.getChildren().removeAll(lane.get(getClosestNote(lane)));
lane.remove(lane.get(getClosestNote(lane)));
- System.out.println("Hit");
+ if (distance < this.getScene().getHeight() / 16) {
+ ft.setFromValue(Color.WHITE);
+ ft.play();
+ scoreCounter.combo();
+ scoreCounter.perfect();
+ return 2;
+ }
+ if (distance < this.getScene().getHeight() / 5) {
+ ft.setFromValue(Color.PINK);
+ ft.play();
+ scoreCounter.combo();
+ scoreCounter.good();
+ return 1;
+ }
+ ft.setFromValue(Color.RED);
+ ft.play();
+ scoreCounter.miss();
+ return 0;
}
+ return -1;
}
} \ No newline at end of file