aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTyler Ferrari <tpoke.ferrari@gmail.com>2023-05-04 02:37:34 +0000
committerTyler Ferrari <tpoke.ferrari@gmail.com>2023-05-04 02:37:34 +0000
commit291cf3bbfbd316f6acdb6d686470113ab91f53b6 (patch)
tree72ad28111d5c53e47dc5a825730bc88e6f7e638f
parent6a10a65a0dbcd0540202479a02e4f91881791d6b (diff)
parenta52f89a5092d347797cfd0893fc163233160e9e1 (diff)
downloadNPEhero-291cf3bbfbd316f6acdb6d686470113ab91f53b6.tar.gz
NPEhero-291cf3bbfbd316f6acdb6d686470113ab91f53b6.tar.bz2
NPEhero-291cf3bbfbd316f6acdb6d686470113ab91f53b6.zip
Merge branch 'revert-6a10a65a' into 'main'
Revert "rearange some files" See merge request guitarheros/guitarhero!2
-rw-r--r--.vscode/settings.json3
-rw-r--r--KeyDetection.java28
-rw-r--r--NoteTest.java35
-rw-r--r--SongPlayer.java97
-rw-r--r--apcs/Driver.java4
-rw-r--r--apcs/Gui.java6
6 files changed, 162 insertions, 11 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json
deleted file mode 100644
index c995aa5..0000000
--- a/.vscode/settings.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "java.debug.settings.onBuildFailureProceed": true
-} \ No newline at end of file
diff --git a/KeyDetection.java b/KeyDetection.java
new file mode 100644
index 0000000..98f96e4
--- /dev/null
+++ b/KeyDetection.java
@@ -0,0 +1,28 @@
+/*Name:
+ *Date:
+ *Period:
+ *Teacher:
+ *Description:
+ */
+package cs;
+
+import javax.swing.*;
+import java.awt.event.ActionEvent;
+
+public class KeyDetection extends AbstractAction
+{
+ long timeStart = System.currentTimeMillis();
+ private char key;
+ public KeyDetection(char ch){
+ key = ch;
+ }
+
+ public void actionPerformed(ActionEvent e)
+ {
+ // TODO Auto-generated method stub
+ int time = (int)((System.currentTimeMillis()-timeStart));
+ System.out.println(key + ": " + time);
+
+ }
+
+}
diff --git a/NoteTest.java b/NoteTest.java
new file mode 100644
index 0000000..dd38b72
--- /dev/null
+++ b/NoteTest.java
@@ -0,0 +1,35 @@
+/*Name:
+ *Date:
+ *Period:
+ *Teacher:
+ *Description:
+ */
+package cs;
+import java.awt.*;
+
+public class NoteTest
+{
+ private boolean failed = false;
+ private int lane;
+ private final int NOTESPEED = 1;
+ private int yPos = SongPlayer.HEIGHT;
+
+ public void gameTick() {
+ if (!failed) {
+ if (yPos > 0) {
+ yPos -= NOTESPEED;
+ }
+ else {
+ failed = true;
+ }
+ }
+ }
+
+ public boolean getFailed() {
+ return failed;
+ }
+
+ public int getY() {
+ return yPos;
+ }
+}
diff --git a/SongPlayer.java b/SongPlayer.java
new file mode 100644
index 0000000..50e06aa
--- /dev/null
+++ b/SongPlayer.java
@@ -0,0 +1,97 @@
+/*Name:
+ *Date:
+ *Period:
+ *Teacher:
+ *Description:
+ */
+package cs;
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+
+public class SongPlayer
+{
+ public static final int HEIGHT = 650;
+ public static final int LENGTH = 400;
+
+
+ private final int BLENGTH = LENGTH/6;
+ private final int BHEIGHT = HEIGHT/20;
+ JFrame frame = new JFrame("Guitar Hero"); //creates the frame
+
+
+ JButton d = new JButton("D"); //creates the four button lanes
+ JButton f = new JButton("F");
+ JButton h = new JButton("H");
+ JButton j = new JButton("J");
+
+
+ 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);
+ h.setBounds(3*BLENGTH, (5*HEIGHT)/6, BLENGTH, BHEIGHT);
+ j.setBounds(4*BLENGTH, (5*HEIGHT)/6, BLENGTH, BHEIGHT);
+
+
+ frame.add(d); //adds the buttons to the frame
+ frame.add(f);
+ frame.add(h);
+ frame.add(j);
+
+ frame.setSize(LENGTH, HEIGHT); //sets the size of the frame
+ frame.setLayout(null); //???
+ frame.setVisible(true); //makes the frame visible
+
+ KeyDetection dAction = new KeyDetection('d'); //creates an action for each char
+ d.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke('d'), "dPress"); //Input map and Action map setting
+ d.getActionMap().put("dPress", dAction);
+ d.setFocusable(false); //makes it so you can't highlight the button
+
+ KeyDetection fAction = new KeyDetection('f');
+ f.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke('f'), "fPress");
+ f.getActionMap().put("fPress", fAction);
+ f.setFocusable(false);
+
+ KeyDetection hAction = new KeyDetection('h');
+ h.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke('h'), "hPress");
+ h.getActionMap().put("hPress", hAction);
+ h.setFocusable(false);
+
+ KeyDetection jAction = new KeyDetection('j');
+ j.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke('j'), "jPress");
+ j.getActionMap().put("jPress", jAction);
+ j.setFocusable(false);
+ }
+
+ public void loop() {
+ JButton note = new JButton();
+ JButton test = new JButton();
+ test.setBounds(200, 200, 100, 100);
+ note.setBounds(BLENGTH, 0, BLENGTH, BHEIGHT);
+ frame.add(note);
+ frame.add(test);
+
+ NoteTest a = new NoteTest();
+ while (!a.getFailed()) {
+ if (!a.getFailed()) {
+ a.gameTick();
+ note.setBounds(BLENGTH, HEIGHT-a.getY(), BLENGTH, BHEIGHT); //moves the note down every frame
+ System.out.println(a.getFailed());
+ //the computer runs too fast normally, force it to run at a certain fps
+ try {
+ Thread.sleep(2);
+ } catch (InterruptedException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ if (a.getFailed()) {
+ frame.remove(note); //removes the note once its off the screen
+ }
+ }
+ }
+}
diff --git a/apcs/Driver.java b/apcs/Driver.java
index 0b9fba4..a3b4c6c 100644
--- a/apcs/Driver.java
+++ b/apcs/Driver.java
@@ -12,9 +12,7 @@ public class Driver
public static void main(String[] args)
{
-
- SongPlayer s = new SongPlayer();
- s.createAndShowGui();
+ new Gui();
}
}
diff --git a/apcs/Gui.java b/apcs/Gui.java
index b6fb5a1..934c371 100644
--- a/apcs/Gui.java
+++ b/apcs/Gui.java
@@ -5,8 +5,6 @@
*Description:
*/
package apcs;
-import java.awt.Graphics;
-import java.awt.geom.RoundRectangle2D;
import javax.swing.JButton;
import javax.swing.JFrame;
@@ -19,7 +17,7 @@ public class Gui {
JFrame frame=new JFrame();
// Creating Button
- JButton b=new TButton("Click Me..");
+ JButton b=new JButton("Click Me..");
/* This method specifies the location and size
* of button. In method setBounds(x, y, width, height)
* x,y) are cordinates from the top left
@@ -30,8 +28,6 @@ public class Gui {
//Adding button onto the frame
frame.add(b);
-
-
// Setting Frame size. This is the window size
frame.setSize(600,500);