aboutsummaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorZach Jordan <zjordan58@fairport.org>2023-05-18 08:21:57 -0400
committerZach Jordan <zjordan58@fairport.org>2023-05-18 08:21:57 -0400
commitbbad14a33c614ac3480c599dd72a06e14a86295c (patch)
treec66a48226ad8fc99cd8ebe8894646d6f14228ca7 /src/gui
parent6e58f0c2ea47c33555e236c5f3bcb64a89c633fc (diff)
parent33b5b82b1a2c511c6de0c1f744aec1f04bee12f7 (diff)
downloadNPEhero-bbad14a33c614ac3480c599dd72a06e14a86295c.tar.gz
NPEhero-bbad14a33c614ac3480c599dd72a06e14a86295c.tar.bz2
NPEhero-bbad14a33c614ac3480c599dd72a06e14a86295c.zip
Merge branch 'main' of
https://gitlab.sowgro.net/guitarheros/guitarhero.git into main Conflicts: .classpath
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/Driver.java16
-rw-r--r--src/gui/LevelDetails.java9
-rw-r--r--src/gui/LevelSurround.java97
-rw-r--r--src/gui/SongPlayer2.java232
4 files changed, 350 insertions, 4 deletions
diff --git a/src/gui/Driver.java b/src/gui/Driver.java
index 77fe0b0..59002c2 100644
--- a/src/gui/Driver.java
+++ b/src/gui/Driver.java
@@ -17,6 +17,7 @@ import javafx.stage.Stage;
public class Driver extends Application
{
+ static Stage primaryStage;
static HashMap<String,Pane> menus = new HashMap<String,Pane>();
static Pane primaryPane = new Pane();
@@ -26,8 +27,9 @@ public class Driver extends Application
}
@Override
- public void start(Stage primaryStage)
+ public void start(Stage newPrimaryStage)
{
+ primaryStage = newPrimaryStage;
menus.put("MainMenu", new MainMenu());
menus.put("LevelSelector", new LevelSelector());
menus.put("Settings", new Settings());
@@ -61,6 +63,18 @@ public class Driver extends Application
primaryPane.requestFocus();
}
+ public static void setCustomMenu(Pane pane)
+ {
+ if (! primaryPane.getChildren().isEmpty())
+ {
+ primaryPane.getChildren().remove(0);
+ }
+ pane.minWidthProperty().bind(primaryStage.widthProperty());
+ pane.minHeightProperty().bind(primaryStage.heightProperty());
+ primaryPane.getChildren().add(pane);
+ primaryPane.requestFocus();
+ }
+
public static void setBackground(String url)
{
primaryPane.setBackground(new Background(
diff --git a/src/gui/LevelDetails.java b/src/gui/LevelDetails.java
index dee2f00..5623261 100644
--- a/src/gui/LevelDetails.java
+++ b/src/gui/LevelDetails.java
@@ -1,5 +1,6 @@
package gui;
+import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.ListView;
@@ -22,6 +23,7 @@ public class LevelDetails extends VBox
details.maxWidthProperty().bind(super.widthProperty());
details.maxHeightProperty().bind(super.heightProperty().multiply(0.75));
details.getStyleClass().add("textBox");
+ details.setPadding(new Insets(10));
Button play = new Button();
play.setText("Play");
@@ -31,7 +33,7 @@ public class LevelDetails extends VBox
Text desc = new Text();
desc.setText("Select a level from the left pane");
desc.setFill(Color.WHITE);
- desc.wrappingWidthProperty().bind(super.widthProperty());
+ desc.wrappingWidthProperty().bind(super.widthProperty().subtract(10));
desc.setTextAlignment(TextAlignment.CENTER);
details.setAlignment(Pos.CENTER);
details.getChildren().addAll(desc);
@@ -44,12 +46,12 @@ public class LevelDetails extends VBox
title.setText("Test level 1");
title.setFill(Color.WHITE);
title.setFont(new Font(50));
- title.wrappingWidthProperty().bind(super.widthProperty());
+ title.wrappingWidthProperty().bind(super.widthProperty().subtract(10));
Text desc = new Text();
desc.setText("long description with lots of words. what we write does not actually need to be long i just wan t make sure it can word wrap");
desc.setFill(Color.WHITE);
- desc.wrappingWidthProperty().bind(super.widthProperty());
+ desc.wrappingWidthProperty().bind(super.widthProperty().subtract(10));
ImageView previewView = new ImageView();
Image preview = new Image("assets/pico.png");
@@ -58,6 +60,7 @@ public class LevelDetails extends VBox
previewView.fitWidthProperty().bind(super.widthProperty().multiply(0.5));
previewView.setPreserveRatio(true);
details.getChildren().addAll(title,desc,previewView);
+ play.setOnAction(e -> Driver.setCustomMenu(new LevelSurround()));
}
VBox rightBox = new VBox();
diff --git a/src/gui/LevelSurround.java b/src/gui/LevelSurround.java
new file mode 100644
index 0000000..bf71f2f
--- /dev/null
+++ b/src/gui/LevelSurround.java
@@ -0,0 +1,97 @@
+package gui;
+
+import fallTest.Hbox;
+import javafx.geometry.Insets;
+import javafx.geometry.Pos;
+import javafx.scene.control.Button;
+import javafx.scene.layout.BorderPane;
+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.text.Font;
+import javafx.scene.text.Text;
+
+public class LevelSurround extends Pane
+{
+ //will have param (Level l)
+ public LevelSurround()
+ {
+ Button exit = new Button();
+ exit.setText("Exit");
+ exit.setOnAction(e -> Driver.setMenu("LevelSelector"));
+
+ Button pause = new Button();
+ pause.setText("Pause");
+
+ HBox buttonBox = new HBox();
+ buttonBox.getChildren().addAll(exit,pause);
+ buttonBox.setAlignment(Pos.TOP_LEFT);
+ buttonBox.setSpacing(10);
+
+ Text title = new Text();
+ title.setText("Test level 1");
+ title.setFill(Color.WHITE);
+ title.setFont(new Font(50));
+
+ Text diff = new Text();
+ diff.setText("Easy");
+ diff.setFill(Color.WHITE);
+
+ VBox titleTextBox = new VBox();
+ titleTextBox.setAlignment(Pos.TOP_RIGHT);
+ titleTextBox.getChildren().addAll(title,diff);
+
+ BorderPane topBar = new BorderPane();
+ topBar.setLeft(buttonBox);
+ topBar.setRight(titleTextBox);
+ topBar.setPadding(new Insets(10));
+
+
+ Text scoreLabel = new Text();
+ scoreLabel.setText("Score:");
+ scoreLabel.setFill(Color.WHITE);
+
+ Text score = new Text();
+ score.setText("100000");
+ score.setFill(Color.WHITE);
+ score.setFont(new Font(50));
+
+ VBox scoreTextBox = new VBox();
+ scoreTextBox.setAlignment(Pos.BOTTOM_LEFT);
+ scoreTextBox.getChildren().addAll(scoreLabel,score);
+ scoreTextBox.setPadding(new Insets(10));
+
+
+ Text comboLabel = new Text();
+ comboLabel.setText("Combo:");
+ comboLabel.setFill(Color.WHITE);
+
+ Text combo = new Text();
+ combo.setText("100000");
+ combo.setFill(Color.WHITE);
+ combo.setFont(new Font(50));
+
+ VBox comboTextBox = new VBox();
+ comboTextBox.setAlignment(Pos.BOTTOM_RIGHT);
+ comboTextBox.getChildren().addAll(comboLabel,combo);
+ comboTextBox.setPadding(new Insets(10));
+
+ Pane game = new Pane();
+ game.minWidthProperty().bind(super.heightProperty().multiply(0.66));
+ game.minHeightProperty().bind(super.heightProperty());
+ game.getStyleClass().add("textBox");
+
+ HBox centerBox = new HBox();
+ centerBox.getChildren().addAll(comboTextBox,game, scoreTextBox);
+ centerBox.setAlignment(Pos.BOTTOM_CENTER);
+
+ StackPane root = new StackPane();
+ root.getChildren().addAll(centerBox, topBar);
+
+ super.getChildren().add(root);
+ root.minWidthProperty().bind(super.minWidthProperty());
+ root.minHeightProperty().bind(super.minHeightProperty());
+ }
+} \ No newline at end of file
diff --git a/src/gui/SongPlayer2.java b/src/gui/SongPlayer2.java
new file mode 100644
index 0000000..ed6476d
--- /dev/null
+++ b/src/gui/SongPlayer2.java
@@ -0,0 +1,232 @@
+/*Name: Guitar Hero Project
+ *Description: Contains the main game loop for gameplay
+ */
+package gui;
+
+import javafx.scene.control.Button;
+import javafx.scene.layout.HBox;
+import javafx.scene.layout.Pane;
+
+import java.util.*;
+
+import fallTest.NoteField;
+import fallTest.NoteInfo;
+import fallTest.Score;
+import fallTest.Timer;
+//test
+public class SongPlayer2 extends Pane
+{
+ 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;
+
+ Button d = new Button("D");
+ Button f = new Button("F");
+ Button space= new Button("...");
+ Button j = new Button("J");
+ Button k = new Button("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<Block> dVis = new ArrayList<Block>(); //Array list containing the visual representations of the notes in lanes
+
+ Queue<NoteInfo> fSends = new LinkedList<NoteInfo>();
+ ArrayList<NoteField> fLane = new ArrayList<NoteField>();
+ ArrayList<Block> fVis = new ArrayList<Block>();
+
+ Queue<NoteInfo> spaceSends = new LinkedList<NoteInfo>();
+ ArrayList<NoteField> spaceLane = new ArrayList<NoteField>();
+ ArrayList<Block> spaceVis = new ArrayList<Block>();
+
+ Queue<NoteInfo> jSends = new LinkedList<NoteInfo>();
+ ArrayList<NoteField> jLane = new ArrayList<NoteField>();
+ ArrayList<Block> jVis = new ArrayList<Block>();
+
+ Queue<NoteInfo> kSends = new LinkedList<NoteInfo>();
+ ArrayList<NoteField> kLane = new ArrayList<NoteField>();
+ ArrayList<Block> kVis = new ArrayList<Block>();
+
+ 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 SongPlayer2() {
+
+ // 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);
+
+
+ HBox bottom = new HBox();
+ bottom.getChildren().add(d); //adds the buttons to the frame
+ bottom.getChildren().add(f);
+ bottom.getChildren().add(space);
+ bottom.getChildren().add(j);
+ bottom.getChildren().add(k);
+ super.getChildren().add(bottom);
+ //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;
+ }
+ */
+}