Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion RhythmGame/src/Arrow.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@


import java.awt.Color;
import java.awt.Graphics2D;

Expand Down Expand Up @@ -35,7 +36,7 @@ public Arrow(ArrowLane al) {

/**
*
* Moves the arrow by its velocity
* Moves the arrow by its velocity and removes it if its off the screen
*/
public void move() {
yPos += YVEL;
Expand Down
20 changes: 8 additions & 12 deletions RhythmGame/src/ArrowLane.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ public class ArrowLane {

private final int xPos;

private static int goal;// change later
private static int goal;

private LinkedList<Arrow> arrows;

private final Direction direction;

/**
*
* @param xPos the xCoordinate of all arrows in the lane
* @param xPos the xCoordinate of all arrows in the lane
* @param direction the direction of all arrows in the lane
*/

Expand All @@ -38,7 +37,6 @@ public ArrowLane(int xPos, Direction direction, int screenSize) {
}

/**
*
* Adds an arrow to the end/top of the arrowLane
*/
public void add() {
Expand Down Expand Up @@ -67,11 +65,11 @@ public int compare() {
int score = 0;
if (arrow.getY() > goal - 100) {
diff = Math.abs(arrow.getY() - goal);
if (diff <= 27) { // TODO define perfect
score = 3; // FYI 3 is best
} else if (diff <= 60) { // TODO define ok
if (diff <= 27) {
score = 3;
} else if (diff <= 60) {
score = 2;
} else if (diff <= 100) { // TODO define bad
} else if (diff <= 100) {
score = 1;
}

Expand Down Expand Up @@ -114,10 +112,8 @@ public int getX() {
}

// There is an error when an arrow is removed due to the size of the list
// changing so if we make an array with the copy, the error dissapears since
// the program draws according to the array. There is a cast exception error
// when the code first starts but it dissapears which probably means that it
// might not be the best way
// changing so if we make an array with the copy, the error disappears since
// the program draws according to the array.
/**
*
* Moves all arrows in the lane by iterating through the linked list and calling
Expand Down
3 changes: 1 addition & 2 deletions RhythmGame/src/ArrowListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ public class ArrowListener extends AbstractAction implements ActionListener {
public ArrowListener(RhythmGame g, String k) {
game = g;
key = k;
System.out.println("constructed");
}

@Override // Aparently overrides don't need javadoc, they probably just have it
@Override
public void actionPerformed(ActionEvent arg0) {
game.recieveInput(key);

Expand Down
7 changes: 1 addition & 6 deletions RhythmGame/src/MenuBar.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
Expand Down Expand Up @@ -69,23 +70,17 @@ public MenuBar(RhythmGame g, JFrame window) {
public void actionPerformed(ActionEvent e) {
Object o = e.getSource();
if (selectFile == o) {
System.out.println("File Selected");
String path = System.getProperty("user.dir") + "\\music";
chooser = new JFileChooser("Select a file");
chooser.setCurrentDirectory(new File(path));
int result = chooser.showOpenDialog(game);
if (result == JFileChooser.APPROVE_OPTION) {
System.out.println("Haven't tested this part yet. I hope it works");
File file = chooser.getSelectedFile();
fileName = file;
}
System.out.println(
"I got the Absolute Path of the file, I have no clue " + "what to do with it, but I got it");
} else if (startGame == o && fileName != null) {
System.out.println("Game starts");
game.start(GameState.PLAY, fileName);
} else if (startRecord == o && fileName != null) {
System.out.println("Record starts");
game.start(GameState.RECORD, fileName);

} else if (quit == o) {
Expand Down
2 changes: 0 additions & 2 deletions RhythmGame/src/MusicPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public boolean defineSong(String path) {
if (clip != null) {
clip.close();
}
// https://www.geeksforgeeks.org/play-audio-file-using-java/
try {
// create AudioInputStream object
audioInputStream = AudioSystem.getAudioInputStream(new File(path).getAbsoluteFile());
Expand All @@ -57,7 +56,6 @@ public boolean defineSong(String path) {
System.out.println("The audio file selected is unsuported");
return false;
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("error occcured in retrieving the file");
e.printStackTrace();
return false;
Expand Down
5 changes: 5 additions & 0 deletions RhythmGame/src/Recorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
* new file
*
* @author Ryan Tai, David Choi
* @version May 18, 2020
* @author Period: 1
* @author Assignment: RhythmGame
*
* @author Sources: None
*
*/
public class Recorder {
Expand Down
11 changes: 1 addition & 10 deletions RhythmGame/src/RhythmGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class RhythmGame extends JPanel implements ActionListener {
private MenuBar menuBar;
private ArrowLane[] lanes;
private static final int SCREEN_WIDTH = 800;
private static final int SCREEN_HEIGHT = 1000; // kinda irrelevent
private static final int SCREEN_HEIGHT = 1000;
private int worldTime;
private Timer timer;
private String currentLine = "";
Expand Down Expand Up @@ -81,8 +81,6 @@ public RhythmGame() {
for (int i = 0; i < 4; i++) {
lanes[i] = new ArrowLane(100 + 200 * i, dir[i], window.getHeight());
}

// SetWorldTime to a negative number depending on velocity
}

/**
Expand Down Expand Up @@ -128,15 +126,12 @@ private void setKeyBindings() {
*/
public void recieveInput(String input) {

// TODO you need to define gameState as recording and playing when you create
// the menu
if (gameState == gameState.IDLE) {
return;
} else if (gameState == GameState.RECORD) {
recorder.record(input);
} else if (gameState == GameState.PLAY) {
int comparison = 0;
System.out.println("play");
if (input.equals("Left")) {
comparison = lanes[0].compare();
} else if (input.equals("Down")) {
Expand All @@ -146,7 +141,6 @@ public void recieveInput(String input) {
} else if (input.equals("Right")) {
comparison = lanes[3].compare();
}
System.out.println(comparison);

addScore(comparison);
}
Expand All @@ -171,7 +165,6 @@ public void addScore(int i) {
scoreColor = Color.GREEN;
break;
}
System.out.println('i');
g2d.fillRect(0, window.getContentPane().getHeight() - Arrow.getHalfHeight() * 3, SCREEN_WIDTH,
Arrow.getHalfHeight() * 2);

Expand Down Expand Up @@ -356,8 +349,6 @@ public static int getScreenHeight() {
*/
public static void main(String[] args) {
RhythmGame game = new RhythmGame();
// game.gameState = GameState.RECORD;
// game.recorder.startNewRecodring("song2");

}
}