diff options
author | Zach Jordan <zjordan58@fairport.org> | 2023-05-18 08:21:57 -0400 |
---|---|---|
committer | Zach Jordan <zjordan58@fairport.org> | 2023-05-18 08:21:57 -0400 |
commit | bbad14a33c614ac3480c599dd72a06e14a86295c (patch) | |
tree | c66a48226ad8fc99cd8ebe8894646d6f14228ca7 | |
parent | 6e58f0c2ea47c33555e236c5f3bcb64a89c633fc (diff) | |
parent | 33b5b82b1a2c511c6de0c1f744aec1f04bee12f7 (diff) | |
download | NPEhero-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
-rw-r--r-- | .vscode/launch.json | 3 | ||||
-rw-r--r-- | src/fallTest/Block.java | 27 | ||||
-rw-r--r-- | src/fallTest/Driver.java | 45 | ||||
-rw-r--r-- | src/fallTest/Hbox.java | 5 | ||||
-rw-r--r-- | src/fallTest/LaneInfo.java | 28 | ||||
-rw-r--r-- | src/fallTest/Level.java | 106 | ||||
-rw-r--r-- | src/fallTest/NoteNode.java | 20 | ||||
-rw-r--r-- | src/fallTest/TButton.java | 27 | ||||
-rw-r--r-- | src/fallTest/newSongPlayer.java | 110 | ||||
-rw-r--r-- | src/gui/Driver.java | 16 | ||||
-rw-r--r-- | src/gui/LevelDetails.java | 9 | ||||
-rw-r--r-- | src/gui/LevelSurround.java | 97 | ||||
-rw-r--r-- | src/gui/SongPlayer2.java | 232 |
13 files changed, 714 insertions, 11 deletions
diff --git a/.vscode/launch.json b/.vscode/launch.json index 9596ad3..257652c 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -49,7 +49,8 @@ "name": "Driver", "request": "launch", "mainClass": "fallTest.Driver", - "projectName": "GuitarHero" + "projectName": "GuitarHero", + "vmArgs": "--module-path lib/linux --add-modules javafx.base,javafx.media,javafx.graphics,javafx.controls,javafx.fxml" }, { "type": "java", diff --git a/src/fallTest/Block.java b/src/fallTest/Block.java new file mode 100644 index 0000000..ab2f902 --- /dev/null +++ b/src/fallTest/Block.java @@ -0,0 +1,27 @@ +//glowing block of color c (jfx node) + +package fallTest; + +import javafx.scene.effect.BlurType; +import javafx.scene.effect.DropShadow; +import javafx.scene.paint.Color; +import javafx.scene.shape.Rectangle; + +public class Block extends Rectangle +{ + public Block(Color c, double a, double b, int r) + { + super(); + DropShadow dropShadow = new DropShadow(); + dropShadow.setRadius(200.0); + dropShadow.setColor(c); + dropShadow.setBlurType(BlurType.GAUSSIAN); + + super.setFill(c); + super.setWidth(a); + super.setHeight(b); + super.setArcHeight(r); + super.setArcWidth(r); + super.setEffect(dropShadow); + } +}
\ No newline at end of file diff --git a/src/fallTest/Driver.java b/src/fallTest/Driver.java index 0ad60f0..3bc7c25 100644 --- a/src/fallTest/Driver.java +++ b/src/fallTest/Driver.java @@ -6,16 +6,49 @@ */ package fallTest; +import javafx.application.*; +import javafx.geometry.Side; +import javafx.scene.Scene; +import javafx.scene.image.Image; +import javafx.scene.layout.Background; +import javafx.scene.layout.BackgroundImage; +import javafx.scene.layout.BackgroundPosition; +import javafx.scene.layout.BackgroundRepeat; +import javafx.scene.layout.BackgroundSize; +import javafx.scene.layout.Pane; +import javafx.stage.Stage; -public class Driver +public class Driver extends Application { + static Pane primaryPane = new Pane(); + public static void main(String[] args) { - // TODO Auto-generated method stub - SongPlayer g = new SongPlayer(); - g.loadSong(); - g.createAndShowGui(); - } + launch(args); + } + @Override + public void start(Stage primaryStage) throws Exception { + Scene primaryScene = new Scene(primaryPane, 800, 600); + primaryScene.getStylesheets().add("gui/style.css"); + primaryStage.setScene(primaryScene); + newSongPlayer player = new newSongPlayer(); + primaryStage.setTitle("TEST"); + primaryPane.getChildren().add(player); + setBackground("assets/water.png"); + player.init(); + primaryStage.show(); + } + + public static void setBackground(String url) + { + primaryPane.setBackground(new Background( + new BackgroundImage( + new Image(url), + BackgroundRepeat.REPEAT, BackgroundRepeat.NO_REPEAT, + new BackgroundPosition(Side.LEFT, 0, true, Side.BOTTOM, 0, true), + new BackgroundSize(BackgroundSize.AUTO, BackgroundSize.AUTO, true, true, false, true) + ))); + } } diff --git a/src/fallTest/Hbox.java b/src/fallTest/Hbox.java new file mode 100644 index 0000000..a7a97a7 --- /dev/null +++ b/src/fallTest/Hbox.java @@ -0,0 +1,5 @@ +package fallTest; + +public class Hbox { + +} diff --git a/src/fallTest/LaneInfo.java b/src/fallTest/LaneInfo.java new file mode 100644 index 0000000..7fe5567 --- /dev/null +++ b/src/fallTest/LaneInfo.java @@ -0,0 +1,28 @@ +package fallTest;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.Queue;
+
+import javax.swing.JButton;
+
+public class LaneInfo {
+ //test
+ Queue<NoteInfo> sends = new LinkedList<NoteInfo>(); //Queue that dictates when to send the notes
+ ArrayList<Block> nodes = new ArrayList<Block>(); //Array list containing all the notes currently on the field
+ public void addSends(int t) {
+ sends.add(new NoteInfo(t));
+ }
+
+ public void addNodes(int t) {
+ nodes.add(new Block());
+ }
+
+ public ArrayList<Block> getNodes() {
+ return nodes;
+ }
+
+ public Queue<NoteInfo> getSends() {
+ return sends;
+ }
+}
diff --git a/src/fallTest/Level.java b/src/fallTest/Level.java new file mode 100644 index 0000000..71ee0a8 --- /dev/null +++ b/src/fallTest/Level.java @@ -0,0 +1,106 @@ +package fallTest; + +import javafx.application.Application; +import javafx.event.ActionEvent; +import javafx.event.EventHandler; +import javafx.geometry.Insets; +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.scene.effect.BlurType; +import javafx.scene.effect.DropShadow; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.Background; +import javafx.scene.layout.BackgroundFill; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.CornerRadii; +import javafx.scene.layout.GridPane; +import javafx.scene.layout.Pane; +import javafx.scene.layout.StackPane; +import javafx.scene.paint.Color; +import javafx.scene.shape.Rectangle; +import javafx.scene.text.Font; +import javafx.scene.text.FontWeight; +import javafx.scene.text.Text; +import javafx.stage.Stage; + +// will eventually extend pane +public class Level extends Pane { + + + public Level() { + + BorderPane background = new BorderPane(); + Scene game = new Scene(background, 800, 600); + GridPane blockGrid = new GridPane(); + blockGrid.setBackground(new Background(new BackgroundFill(Color.BLACK, CornerRadii.EMPTY, Insets.EMPTY))); + background.setCenter(blockGrid); + + blockGrid.maxWidthProperty().bind(game.heightProperty().multiply(0.53)); + blockGrid.maxHeightProperty().bind(game.heightProperty()); + System.out.println(game.heightProperty()); + + //blockGrid.setMaxHeight(700); + //blockGrid.setMaxWidth(500); + //blockGrid.setScaleX(1); + //blockGrid.setScaleY(1); + //blockGrid.scaleXProperty().bind(game.heightProperty().divide(1000)); + //blockGrid.scaleYProperty().bind(game.heightProperty().divide(1000)); + //blockGrid.hgapProperty().bind(blockGrid.heightProperty().divide(11)); + //blockGrid.vgapProperty().bind(blockGrid.widthProperty().divide(21)); + blockGrid.setVgap(10); + blockGrid.setHgap(25); + + int blocksize = 50; + //AnchorPane b11 = new AnchorPane(); + //b11.getChildren().add(new Block(Color.ORANGE, b11, 10)); + Block b1 = new Block(Color.RED, blocksize, blocksize, 10); + //b1.heightProperty().bind(blockGrid.heightProperty().divide((blockGrid.getColumnCount()*2)+1)); + //b1.widthProperty().bind(blockGrid.widthProperty().divide((blockGrid.getRowCount()*2)+1)); + + Block b2 = new Block(Color.BLUE, blocksize, blocksize, 10); + //b2.heightProperty().bind(blockGrid.heightProperty().divide(21)); + //b2.widthProperty().bind(blockGrid.widthProperty().divide(11)); + + Block b3 = new Block(Color.GREEN, blocksize, blocksize, 10); + //b3.heightProperty().bind(blockGrid.heightProperty().divide(21)); + //b3.widthProperty().bind(blockGrid.widthProperty().divide(11)); + + Block b4 = new Block(Color.YELLOW, blocksize, blocksize, 10); + //b4.heightProperty().bind(blockGrid.heightProperty().divide(21)); + //b4.widthProperty().bind(blockGrid.widthProperty().divide(11)); + + Pane test = new Pane(); + + Block b5 = new Block(Color.ORANGE, blocksize, blocksize, 10); + DropShadow dropShadow = new DropShadow(); + dropShadow.setRadius(200.0); + dropShadow.setColor(Color.ORANGE); + dropShadow.setBlurType(BlurType.GAUSSIAN); + test.getChildren().add(b5); + test.setEffect(dropShadow); + + + + blockGrid.add(b1, 0, 0); + blockGrid.add(b2, 1, 0); + blockGrid.add(b3, 0, 1); + blockGrid.add(b4, 1, 1); + blockGrid.add(test, 1, 2); + + Button btn = new Button(); + btn.setText("Test"); + btn.setOnAction(new EventHandler<ActionEvent>() + { + @Override + public void handle(ActionEvent event) + { + System.out.println("test"); + } + }); + + background.setLeft(btn); + + + + } +}
\ No newline at end of file diff --git a/src/fallTest/NoteNode.java b/src/fallTest/NoteNode.java new file mode 100644 index 0000000..64e1b8a --- /dev/null +++ b/src/fallTest/NoteNode.java @@ -0,0 +1,20 @@ +package fallTest;
+
+import javafx.animation.*;
+import javafx.util.Duration;
+
+public class NoteNode {
+ private final int TIME = 20;
+ private NoteField info;
+ private Block vis;
+ TranslateTransition anim = new TranslateTransition(Duration.millis(TIME));
+ public NoteNode(NoteField newInfo, Block newVis) {
+ vis=newVis;
+ info = newInfo;
+ anim.setNode(vis);
+ anim.setByY(height);
+ anim.setCycleCount(1);
+ anim.setAutoReverse(false);
+ anim.play();
+ }
+}
diff --git a/src/fallTest/TButton.java b/src/fallTest/TButton.java new file mode 100644 index 0000000..d18771f --- /dev/null +++ b/src/fallTest/TButton.java @@ -0,0 +1,27 @@ +//glowing block of color c (jfx node) + +package fallTest; + +import javafx.scene.effect.BlurType; +import javafx.scene.effect.DropShadow; +import javafx.scene.paint.Color; +import javafx.scene.shape.Rectangle; +import javafx.scene.text.Text; +import javafx.scene.paint.*; + +public class TButton extends Rectangle +{ + 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.25); + super.setFill(newCol); + super.setWidth(a); + super.setHeight(b); + super.setArcHeight(r); + super.setArcWidth(r); + super.setStroke(c); + super.setStrokeWidth(5); + } +}
\ No newline at end of file diff --git a/src/fallTest/newSongPlayer.java b/src/fallTest/newSongPlayer.java new file mode 100644 index 0000000..3f6d4ed --- /dev/null +++ b/src/fallTest/newSongPlayer.java @@ -0,0 +1,110 @@ +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;
+
+public class newSongPlayer extends Pane
+{
+ Timer time = new Timer();
+
+ private double dLaneX = 0;
+ TButton dButton = new TButton(Color.RED, 50, 50, 5);
+
+ public void init() {
+ 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
+
+ Rectangle field = new Rectangle(50, 50, new Color(0, 0, 0, 0.7));
+ field.heightProperty().bind(this.getScene().getWindow().heightProperty().multiply(0.95));
+ field.widthProperty().bind(this.getScene().getWindow().widthProperty().divide(2.7).add(50));
+ genButton(dButton);
+ /*dButton.setOnKeyPressed(e -> {
+ if (e.getCode() == KeyCode.D) {
+ System.out.println("D");
+ }
+ });*/
+
+ TButton fButton = new TButton(Color.BLUE, 50, 50, 5);
+ genButton(fButton);
+
+ TButton sButton = new TButton(Color.GREEN, 50, 50, 5);
+ genButton(sButton);
+
+ TButton jButton = new TButton(Color.PURPLE, 50, 50, 5);
+ genButton(jButton);
+
+ TButton kButton = new TButton(Color.YELLOW, 50, 50, 5);
+ genButton(kButton);
+
+
+ HBox buttonBox = new HBox();
+ 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;");
+ buttonBox.setAlignment(Pos.CENTER);
+ buttonBox.getChildren().addAll(dButton, fButton, sButton, jButton, kButton);
+ buttonBox.setSpacing(10);
+
+ VBox polish = new VBox();
+ polish.getChildren().addAll(field);
+ polish.setAlignment(Pos.TOP_CENTER);
+
+ VBox place = new VBox();
+ place.prefWidthProperty().bind(this.getScene().widthProperty());
+ place.prefHeightProperty().bind(this.getScene().heightProperty());
+ place.setAlignment(Pos.BOTTOM_CENTER);
+ place.getChildren().addAll(buttonBox);
+ place.setSpacing(10);
+
+ StackPane root = new StackPane();
+ root.getChildren().addAll(polish, place);
+
+ super.getChildren().add(root);
+ sendNote(dLane, buttonBox.getLayoutX());
+ }
+
+ public void sendNote(ArrayList<Block> lane, double pos) {
+ lane.add(new Block(Color.PINK, 50, 50, 5));
+ 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);
+ System.out.println(pos);
+ super.getChildren().add(lane.get(lane.size()-1));
+ }
+
+ public void genButton(TButton button) {
+ button.heightProperty().bind(this.getScene().getWindow().widthProperty().divide(16));
+ button.widthProperty().bind(this.getScene().getWindow().widthProperty().divide(16));
+ button.arcHeightProperty().bind(this.getScene().getWindow().widthProperty().divide(50));
+ button.arcWidthProperty().bind(this.getScene().getWindow().widthProperty().divide(50));
+ button.strokeWidthProperty().bind(this.getScene().getWindow().widthProperty().divide(210));
+ }
+}
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; + } + */ +} |