diff options
| author | sowgro <tpoke.ferrari@gmail.com> | 2023-05-03 22:50:43 -0400 | 
|---|---|---|
| committer | sowgro <tpoke.ferrari@gmail.com> | 2023-05-03 22:50:43 -0400 | 
| commit | 95a82dc15a17a3fe16d34a1cc3c2ec5b46129c73 (patch) | |
| tree | af87cffaf5009a055351a1210723ca579e6d2bcc /apcs | |
| parent | 291cf3bbfbd316f6acdb6d686470113ab91f53b6 (diff) | |
| download | NPEhero-95a82dc15a17a3fe16d34a1cc3c2ec5b46129c73.tar.gz NPEhero-95a82dc15a17a3fe16d34a1cc3c2ec5b46129c73.tar.bz2 NPEhero-95a82dc15a17a3fe16d34a1cc3c2ec5b46129c73.zip  | |
more file management
Diffstat (limited to 'apcs')
| -rw-r--r-- | apcs/NoteTest.java | 35 | ||||
| -rw-r--r-- | apcs/SongPlayer.java | 43 | 
2 files changed, 69 insertions, 9 deletions
diff --git a/apcs/NoteTest.java b/apcs/NoteTest.java new file mode 100644 index 0000000..310325b --- /dev/null +++ b/apcs/NoteTest.java @@ -0,0 +1,35 @@ +/*Name:	 + *Date: + *Period: + *Teacher: + *Description: + */ +package apcs; +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/apcs/SongPlayer.java b/apcs/SongPlayer.java index f17534b..50e06aa 100644 --- a/apcs/SongPlayer.java +++ b/apcs/SongPlayer.java @@ -4,7 +4,7 @@   *Teacher:   *Description:   */ -package apcs; +package cs;  import java.awt.*;  import java.awt.event.*; @@ -16,16 +16,19 @@ 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() { -        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");          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);      @@ -64,9 +67,31 @@ public class SongPlayer      }      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 (true) { -            a.gameTick(); +        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 +            }          }      }  }  | 
