diff options
Diffstat (limited to 'src/GamePlay')
| -rw-r--r-- | src/GamePlay/Block.java | 27 | ||||
| -rw-r--r-- | src/GamePlay/Driver.java | 54 | ||||
| -rw-r--r-- | src/GamePlay/Level.java | 106 | ||||
| -rw-r--r-- | src/GamePlay/NoteField.java | 25 | ||||
| -rw-r--r-- | src/GamePlay/NoteInfo.java | 28 | ||||
| -rw-r--r-- | src/GamePlay/Score.java | 51 | ||||
| -rw-r--r-- | src/GamePlay/SongPlayer.java | 281 | ||||
| -rw-r--r-- | src/GamePlay/TButton.java | 28 | ||||
| -rw-r--r-- | src/GamePlay/Timer.java | 24 | ||||
| -rw-r--r-- | src/GamePlay/newSongPlayer.java | 289 | 
10 files changed, 913 insertions, 0 deletions
diff --git a/src/GamePlay/Block.java b/src/GamePlay/Block.java new file mode 100644 index 0000000..c8940ec --- /dev/null +++ b/src/GamePlay/Block.java @@ -0,0 +1,27 @@ +//glowing block of color c (jfx node) + +package GamePlay; + +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/GamePlay/Driver.java b/src/GamePlay/Driver.java new file mode 100644 index 0000000..8825426 --- /dev/null +++ b/src/GamePlay/Driver.java @@ -0,0 +1,54 @@ +/*Name:	 + *Date: + *Period: + *Teacher: + *Description: + */ +package GamePlay; + +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 extends Application +{ + +    static Pane primaryPane = new Pane(); + +    public static void main(String[] args) +    { +        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");   +        primaryStage.show(); +        player.init(); +	} +	 +	  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/GamePlay/Level.java b/src/GamePlay/Level.java new file mode 100644 index 0000000..25be35c --- /dev/null +++ b/src/GamePlay/Level.java @@ -0,0 +1,106 @@ +package GamePlay; + +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/GamePlay/NoteField.java b/src/GamePlay/NoteField.java new file mode 100644 index 0000000..4713ece --- /dev/null +++ b/src/GamePlay/NoteField.java @@ -0,0 +1,25 @@ +/*Name:	Guitar Hero Project + *Description: Contains the information for a single note on the field + */ +package GamePlay; + +import javafx.animation.TranslateTransition; + +public class NoteField +{ +    private Block note; +    private TranslateTransition anim; + +    public NoteField(Block newNote, TranslateTransition newAnim) { +        note = newNote; +        anim = newAnim; +    } + +    public Block getNote() { +        return note; +    } + +    public TranslateTransition getAnim() { +        return anim; +    } +} diff --git a/src/GamePlay/NoteInfo.java b/src/GamePlay/NoteInfo.java new file mode 100644 index 0000000..f6b1018 --- /dev/null +++ b/src/GamePlay/NoteInfo.java @@ -0,0 +1,28 @@ +/*Name:	Guitar Hero Project + *Description: Contains the info for when to send a note + */ +package GamePlay; + +import javafx.scene.paint.Color; + +public class NoteInfo +{ +    private double sendTime; +    private Color col; + +    public NoteInfo(double t) { +        sendTime = t; +    } +     +    public double getTime() { +        return sendTime; +    } +     +    public Color getColor() { +        return col; +    } + +    public double compareTo(NoteInfo other) { +        return sendTime - other.sendTime; +    } +} diff --git a/src/GamePlay/Score.java b/src/GamePlay/Score.java new file mode 100644 index 0000000..af3af25 --- /dev/null +++ b/src/GamePlay/Score.java @@ -0,0 +1,51 @@ +/*Name:	Guitar Hero Project + *Description: Handles all the scoring for playing songs + */ +package GamePlay; + + +public class Score +{ +    private int combo=0; +    private int comboMultiplier=1; +    private int score=0; +     +    public void perfect() { +        score += 300*comboMultiplier; +        System.out.println("Perfect!"); +    } +     +    public void good() { +        score += 100*comboMultiplier; +        System.out.println("Good"); +    } +     +    public void miss() { +        combo = 0; +        comboMultiplier = 1; +        System.out.println("Miss"); +    } +    public void combo() { +        combo++; +         +        if (combo == 2) { +            comboMultiplier = 2; +        } +         +        if (combo == 4) { +            comboMultiplier = 4; +        } +         +        if (combo == 8) { +            comboMultiplier = 8; +        } +    } +     +    public int getScore() { +        return score; +    } +     +    public int getCombo() { +        return combo; +    } +} diff --git a/src/GamePlay/SongPlayer.java b/src/GamePlay/SongPlayer.java new file mode 100644 index 0000000..8ddde3a --- /dev/null +++ b/src/GamePlay/SongPlayer.java @@ -0,0 +1,281 @@ +package GamePlay; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.Queue; + +import javafx.geometry.Pos; +import javafx.scene.input.KeyCode; +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.animation.*; +import javafx.util.*; +import main.Difficulty; +import main.ScoreController; + +public class SongPlayer extends Pane { +	Timer timer = new Timer(60); +	final int TIME = 1500; // delay for notes falling down the screen + +	Score scoreCounter = new Score(); + +	Rectangle goalPerfect = new Rectangle(); +	HBox buttonBox = new HBox(); +	VBox polish = new VBox(); +	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 + +	TButton fButton = new TButton(Color.BLUE, 50, 50, 5); +	Queue<NoteInfo> fSends = new LinkedList<NoteInfo>(); +	ArrayList<Block> fLane = new ArrayList<Block>(); + +	TButton sButton = new TButton(Color.GREEN, 50, 50, 5); +	Queue<NoteInfo> spaceSends = new LinkedList<NoteInfo>(); +	ArrayList<Block> spaceLane = new ArrayList<Block>(); + +	TButton jButton = new TButton(Color.PURPLE, 50, 50, 5); +	Queue<NoteInfo> jSends = new LinkedList<NoteInfo>(); +	ArrayList<Block> jLane = new ArrayList<Block>(); + +	TButton kButton = new TButton(Color.YELLOW, 50, 50, 5); +	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(4.000)); +		dSends.add(new NoteInfo(4.333)); +		dSends.add(new NoteInfo(4.666)); +		fSends.add(new NoteInfo(5.000)); +		kSends.add(new NoteInfo(5.500)); +		spaceSends.add(new NoteInfo(6.000)); +		jSends.add(new NoteInfo(6.000)); +		jSends.add(new NoteInfo(6.250)); +		dSends.add(new NoteInfo(6.500)); +		jSends.add(new NoteInfo(6.750)); +		spaceSends.add(new NoteInfo(7.000)); +		fSends.add(new NoteInfo(7.500)); +		jSends.add(new NoteInfo(7.750)); +		spaceSends.add(new NoteInfo(8.000)); +		fSends.add(new NoteInfo(8.500)); +		jSends.add(new NoteInfo(8.500)); +		dSends.add(new NoteInfo(9.000)); +		spaceSends.add(new NoteInfo(9.000)); +		kSends.add(new NoteInfo(9.000)); +		spaceSends.add(new NoteInfo(9.500)); + +		kSends.add(new NoteInfo(10.000)); +		dSends.add(new NoteInfo(10.000)); +		kSends.add(new NoteInfo(10.333)); +		fSends.add(new NoteInfo(10.333)); +		kSends.add(new NoteInfo(10.666)); +		spaceSends.add(new NoteInfo(10.666)); +		dSends.add(new NoteInfo(11.000)); +		spaceSends.add(new NoteInfo(11.000)); +		dSends.add(new NoteInfo(11.333)); + +		jSends.add(new NoteInfo(11.333)); +		dSends.add(new NoteInfo(11.666)); +		kSends.add(new NoteInfo(11.666)); +		spaceSends.add(new NoteInfo(12.000)); +	} + +	public SongPlayer(main.Level lvl, Difficulty d, Pane p, ScoreController cntrl) { +		loadSong(); + +		Rectangle field = new Rectangle(50, 50, new Color(0, 0, 0, 0.7)); +		field.heightProperty().bind(super.heightProperty()); +		field.widthProperty().bind(super.widthProperty()); + +		goalPerfect.heightProperty().bind(super.heightProperty().divide(32)); +		goalPerfect.heightProperty().bind(super.widthProperty()); + +		genButton(dButton); +		genButton(fButton); +		genButton(sButton); +		genButton(jButton); +		genButton(kButton); +		 +		super.requestFocus(); +		super.setOnKeyPressed(e -> { +			if (e.getCode() == KeyCode.D) { +				checkNote(dLane, dButton); +			} +			if (e.getCode() == KeyCode.F) { +				checkNote(fLane, fButton); +			} +			if (e.getCode() == KeyCode.SPACE) { +				checkNote(spaceLane, sButton); +			} +			if (e.getCode() == KeyCode.J) { +				checkNote(jLane, jButton); +			} +			if (e.getCode() == KeyCode.K) { +				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;"); +		buttonBox.setAlignment(Pos.CENTER); +		buttonBox.getChildren().addAll(dButton, fButton, sButton, jButton, kButton); +		buttonBox.setSpacing(10); + +		polish.getChildren().addAll(field); +		polish.setAlignment(Pos.BASELINE_CENTER); + +		place.prefWidthProperty().bind(super.widthProperty()); +		place.prefHeightProperty().bind(super.heightProperty()); +		place.getChildren().addAll(buttonBox); +		place.setAlignment(Pos.BOTTOM_CENTER); +		place.setSpacing(10); + +		StackPane root = new StackPane(); +		root.getChildren().addAll(place); + +		goalPerfect.setY(dButton.getY()); +		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; +			sends.remove(); +			lane.get(index).heightProperty().bind(super.widthProperty().divide(8)); +			lane.get(index).widthProperty().bind(super.widthProperty().divide(8)); +			lane.get(index).arcHeightProperty().bind(super.widthProperty().divide(25)); +			lane.get(index).arcWidthProperty().bind(super.widthProperty().divide(25)); +			lane.get(index).setX(pos); +			lane.get(index).setY(-lane.get(index).getHeight()); +			anim.setByY(super.getHeight() + lane.get(index).getHeight()); +			anim.setCycleCount(1); +			anim.setAutoReverse(false); +			anim.setNode(lane.get(lane.size() - 1)); +			anim.play(); + +			anim.setOnFinished(e -> { +				if (super.getChildren().removeAll(anim.getNode())){ +					scoreCounter.miss(); +				} +			}); +			super.getChildren().add(lane.get(lane.size() - 1)); +		} +	} + +	/** +	 * Sets up the given button +	 *  +	 * @param button +	 */ +	public void genButton(TButton button) { +		button.heightProperty().bind(super.widthProperty().divide(8)); +		button.widthProperty().bind(super.widthProperty().divide(8)); +		button.arcHeightProperty().bind(super.widthProperty().divide(25)); +		button.arcWidthProperty().bind(super.widthProperty().divide(25)); +		button.setStrokeWidth(3); +	} + +	/** +	 * The background test that is run on every frame of the game +	 */ +	AnimationTimer gameLoop = new AnimationTimer() { + +		@Override +		public void handle(long arg0) { +			sendNote(dSends, dLane, dButton.getLayoutX(), Color.RED); +			sendNote(fSends, fLane, fButton.getLayoutX(), Color.BLUE); +			sendNote(spaceSends, spaceLane, sButton.getLayoutX(), Color.GREEN); +			sendNote(jSends, jLane, jButton.getLayoutX(), Color.PURPLE); +			sendNote(kSends, kLane, kButton.getLayoutX(), Color.YELLOW); +		} +	}; + +	/** +	 * 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; +	} + +	/** +	 * Returns the distance to the goal of the given note +	 *  +	 * @param note +	 * @return +	 */ +	private double distanceToGoal(Block note) { +		return Math.abs((super.getHeight() - note.getTranslateY()) - dButton.getY()); +	} + +	/** +	 * 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 < super.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))); +			if (distance < super.getHeight() / 16) { +				ft.setFromValue(Color.WHITE); +				ft.play(); +				scoreCounter.combo(); +				scoreCounter.perfect(); +				return 2; +			} +			if (distance < super.getHeight() / 5) { +				ft.setFromValue(Color.CYAN); +				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 diff --git a/src/GamePlay/TButton.java b/src/GamePlay/TButton.java new file mode 100644 index 0000000..a8ae338 --- /dev/null +++ b/src/GamePlay/TButton.java @@ -0,0 +1,28 @@ +//glowing block of color c (jfx node) + +package GamePlay; + +import javafx.scene.paint.Color; +import javafx.scene.shape.Rectangle; + +public class TButton extends Rectangle +{ +    private Color col; +    public TButton(Color c, double a, double b, int r) +    { +        super(); +         +        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); +        super.setArcWidth(r); +        super.setStroke(c); +        super.setStrokeWidth(5); +    } + +    public Color getColor() { +        return col; +    } +}
\ No newline at end of file diff --git a/src/GamePlay/Timer.java b/src/GamePlay/Timer.java new file mode 100644 index 0000000..5d1ddae --- /dev/null +++ b/src/GamePlay/Timer.java @@ -0,0 +1,24 @@ +/*Name:	Guitar Hero Project + *Description: Contains the method used to determine how long the user has been playing,  + *             used to determine when to send notes + */ +package GamePlay; + + +public class Timer +{ +    private long timeStart = System.currentTimeMillis(); +    private int bpm; + +    public Timer(int newBpm) { +        bpm = newBpm; +    } + +    public Timer() { +        bpm = 60000; +    } + +    public double time() { +        return ((double)(System.currentTimeMillis()-timeStart))*(bpm/60000.0); +    } +} diff --git a/src/GamePlay/newSongPlayer.java b/src/GamePlay/newSongPlayer.java new file mode 100644 index 0000000..6460dcf --- /dev/null +++ b/src/GamePlay/newSongPlayer.java @@ -0,0 +1,289 @@ +package GamePlay; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.Queue; + +import javafx.geometry.Pos; +import javafx.scene.input.KeyCode; +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.animation.*; +import javafx.util.*; +import main.Difficulty; +import main.ScoreController; + +public class newSongPlayer extends Pane { +	final int BPM = 80; //TEMPORARY BPM, this will be eventually read in from the metadata of the song + +	Timer timer = new Timer(BPM); +	final int TIME = 1500; // delay for notes falling down the screen + +	Score scoreCounter = new Score(); + +	Rectangle goalPerfect = new Rectangle(); +	HBox buttonBox = new HBox(); +	VBox polish = new VBox(); +	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 + +	TButton fButton = new TButton(Color.BLUE, 50, 50, 5); +	Queue<NoteInfo> fSends = new LinkedList<NoteInfo>(); +	ArrayList<Block> fLane = new ArrayList<Block>(); + +	TButton sButton = new TButton(Color.GREEN, 50, 50, 5); +	Queue<NoteInfo> spaceSends = new LinkedList<NoteInfo>(); +	ArrayList<Block> spaceLane = new ArrayList<Block>(); + +	TButton jButton = new TButton(Color.PURPLE, 50, 50, 5); +	Queue<NoteInfo> jSends = new LinkedList<NoteInfo>(); +	ArrayList<Block> jLane = new ArrayList<Block>(); + +	TButton kButton = new TButton(Color.YELLOW, 50, 50, 5); +	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(4.000)); +		dSends.add(new NoteInfo(4.333)); +		dSends.add(new NoteInfo(4.666)); +		fSends.add(new NoteInfo(5.000)); +		kSends.add(new NoteInfo(5.500)); +		spaceSends.add(new NoteInfo(6.000)); +		jSends.add(new NoteInfo(6.000)); +		jSends.add(new NoteInfo(6.250)); +		dSends.add(new NoteInfo(6.500)); +		jSends.add(new NoteInfo(6.750)); +		spaceSends.add(new NoteInfo(7.000)); +		fSends.add(new NoteInfo(7.500)); +		jSends.add(new NoteInfo(7.750)); +		spaceSends.add(new NoteInfo(8.000)); +		fSends.add(new NoteInfo(8.500)); +		jSends.add(new NoteInfo(8.500)); +		dSends.add(new NoteInfo(9.000)); +		spaceSends.add(new NoteInfo(9.000)); +		kSends.add(new NoteInfo(9.000)); +		spaceSends.add(new NoteInfo(9.500)); + +		kSends.add(new NoteInfo(10.000)); +		dSends.add(new NoteInfo(10.000)); +		kSends.add(new NoteInfo(10.333)); +		fSends.add(new NoteInfo(10.333)); +		kSends.add(new NoteInfo(10.666)); +		spaceSends.add(new NoteInfo(10.666)); +		dSends.add(new NoteInfo(11.000)); +		spaceSends.add(new NoteInfo(11.000)); +		dSends.add(new NoteInfo(11.333)); + +		jSends.add(new NoteInfo(11.333)); +		dSends.add(new NoteInfo(11.666)); +		kSends.add(new NoteInfo(11.666)); +		spaceSends.add(new NoteInfo(12.000)); +	} + +	public newSongPlayer(main.Level lvl, Difficulty d, Pane p, ScoreController cntrl) { +	} + +	public newSongPlayer() { +	} + +	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)); + +		goalPerfect.heightProperty().bind(this.getScene().getWindow().heightProperty().divide(32)); +		goalPerfect.heightProperty().bind(this.getScene().getWindow().widthProperty()); + +		genButton(dButton); +		genButton(fButton); +		genButton(sButton); +		genButton(jButton); +		genButton(kButton); + +		this.getScene().setOnKeyPressed(e -> { +			if (e.getCode() == KeyCode.D) { +				checkNote(dLane, dButton); +			} +			if (e.getCode() == KeyCode.F) { +				checkNote(fLane, fButton); +			} +			if (e.getCode() == KeyCode.SPACE) { +				checkNote(spaceLane, sButton); +			} +			if (e.getCode() == KeyCode.J) { +				checkNote(jLane, jButton); +			} +			if (e.getCode() == KeyCode.K) { +				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;"); +		buttonBox.setAlignment(Pos.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.setAlignment(Pos.BOTTOM_CENTER); +		place.setSpacing(10); + +		StackPane root = new StackPane(); +		root.getChildren().addAll(polish, place); + +		goalPerfect.setY(dButton.getY()); +		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; +			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(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.play(); + +			anim.setOnFinished(e -> { +				if (super.getChildren().removeAll(anim.getNode())){ +					scoreCounter.miss(); +					System.out.println(); +				} +			}); +			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)); +		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)); +	} + +	/** +	 * The background test that is run on every frame of the game +	 */ +	AnimationTimer gameLoop = new AnimationTimer() { + +		@Override +		public void handle(long arg0) { +			sendNote(dSends, dLane, dButton.getLayoutX(), Color.RED); +			sendNote(fSends, fLane, fButton.getLayoutX(), Color.BLUE); +			sendNote(spaceSends, spaceLane, sButton.getLayoutX(), Color.GREEN); +			sendNote(jSends, jLane, jButton.getLayoutX(), Color.PURPLE); +			sendNote(kSends, kLane, kButton.getLayoutX(), Color.YELLOW); +		} +	}; + +	/** +	 * 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; +	} + +	/** +	 * Returns the distance to the goal of the given note +	 *  +	 * @param note +	 * @return +	 */ +	private double distanceToGoal(Block note) { +		return Math.abs((this.getScene().getHeight() - note.getTranslateY()) - dButton.getY()); +	} + +	/** +	 * 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))); +			if (distance < this.getScene().getHeight() / 18) { +				ft.setFromValue(Color.WHITE); +				ft.play(); +				scoreCounter.combo(); +				scoreCounter.perfect(); +				return 2; +			} +			if (distance < this.getScene().getHeight() / 6) { +				ft.setFromValue(Color.CYAN); +				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  | 
