From 95a82dc15a17a3fe16d34a1cc3c2ec5b46129c73 Mon Sep 17 00:00:00 2001 From: sowgro Date: Wed, 3 May 2023 22:50:43 -0400 Subject: more file management --- apcs/SongPlayer.java | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) (limited to 'apcs/SongPlayer.java') 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 + } } } } -- cgit v1.2.3