diff options
-rw-r--r-- | PunchingBag/src/ButtonListener.java | 2 | ||||
-rw-r--r-- | PunchingBag/src/LEDListener.java | 7 | ||||
-rw-r--r-- | PunchingBag/src/PunchingBag.java | 86 | ||||
-rw-r--r-- | PunchingBag/src/PunchingBagGUI.java | 17 |
4 files changed, 79 insertions, 33 deletions
diff --git a/PunchingBag/src/ButtonListener.java b/PunchingBag/src/ButtonListener.java index c2a4961..3338a08 100644 --- a/PunchingBag/src/ButtonListener.java +++ b/PunchingBag/src/ButtonListener.java @@ -1,5 +1,7 @@ import java.util.EventListener; interface ButtonListener extends EventListener { + + void buttonPressed(int x, int y); } diff --git a/PunchingBag/src/LEDListener.java b/PunchingBag/src/LEDListener.java new file mode 100644 index 0000000..3031f58 --- /dev/null +++ b/PunchingBag/src/LEDListener.java @@ -0,0 +1,7 @@ +import java.util.EventListener; + +interface LEDListener extends EventListener { + + void LEDchanged(); + +} diff --git a/PunchingBag/src/PunchingBag.java b/PunchingBag/src/PunchingBag.java index 7e04d33..f141c26 100644 --- a/PunchingBag/src/PunchingBag.java +++ b/PunchingBag/src/PunchingBag.java @@ -28,6 +28,10 @@ public class PunchingBag implements Runnable { buttonListenerList.add(ButtonListener.class, l); } + public void addLEDChangeListener(LEDListener l) { + ledListenerList.add(LEDListener.class, l); + } + public void setLED(int i, int j, Colour colour) { leds[i][j] = colour; } @@ -39,11 +43,36 @@ public class PunchingBag implements Runnable { } } - class CircleExpand implements Runnable { + class Effect implements Runnable { + boolean stop = false; + int refreshRate = 60; // Times per second to refresh + + public void stop() { + stop = true; + } + + public void run() { + while (!stop) { + draw(); + try { + Thread.sleep(1000 / 60); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + + private void draw() { + + } + } + + class CircleExpand extends Effect { double currentWidth; final byte x; final byte y; byte intensity; + boolean drawnSomething = true; public CircleExpand(byte x, byte y, byte intensity) { this.x = x; @@ -52,41 +81,40 @@ public class PunchingBag implements Runnable { new Thread(this).start(); } - @Override - public void run() { + public void draw() { Colour colour; - boolean drawnSomething = true; - while (drawnSomething) { + if (intensity >= 10) { + colour = Colour.Red; + } else if (intensity >= 5) { + colour = Colour.Yellow; + } else { + colour = Colour.Green; + } - if (intensity >= 10) { - colour = Colour.Red; - } else if (intensity >= 5) { - colour = Colour.Yellow; - } else { - colour = Colour.Green; - } + drawnSomething = false; - drawnSomething = false; + for (double i = 0; i < 360; i++) { + // int x = x + (int) Math.round(currentWidth * Math.cos(i)); + // int y = y + (int) Math.round(currentWidth * Math.sin(i)); - for (double i = 0; i < 360; i++) { - // int x = x + (int) Math.round(currentWidth * Math.cos(i)); - // int y = y + (int) Math.round(currentWidth * Math.sin(i)); + if (x >= 0 && x <= 8 && y >= 0 && y <= 19) { + setLED(x, y, colour); + drawnSomething = true; + } - if (x >= 0 && x <= 8 && y >= 0 && y <= 19) { - setLED(x, y, colour); - drawnSomething = true; - } + } - } + if (!drawnSomething) + stop = true; - currentWidth += 0.1 + (currentWidth / 10); - try { - Thread.sleep(1000 / 60); - } catch (InterruptedException e) { - e.printStackTrace(); - } + currentWidth += 0.1 + (currentWidth / 10); + try { + Thread.sleep(1000 / 60); + } catch (InterruptedException e) { + e.printStackTrace(); } + } } @@ -124,10 +152,6 @@ public class PunchingBag implements Runnable { } } - public void addLEDChangeListener(ButtonListener l) { - ledListenerList.add(ButtonListener.class, l); - } - private void calculateRawLeds() { for (int y = 0; y <= 18; y++) { for (int x = 0; x <= 6; x++) { diff --git a/PunchingBag/src/PunchingBagGUI.java b/PunchingBag/src/PunchingBagGUI.java index d7f4f9a..a999bad 100644 --- a/PunchingBag/src/PunchingBagGUI.java +++ b/PunchingBag/src/PunchingBagGUI.java @@ -10,7 +10,7 @@ import java.awt.geom.Area; import javax.swing.JFrame;
import javax.swing.JPanel;
-public class PunchingBagGUI implements MouseListener, MouseMotionListener, ButtonListener {
+public class PunchingBagGUI implements MouseListener, MouseMotionListener, ButtonListener, LEDListener {
public static enum Mode {
Menu, Interactive, Game
@@ -58,7 +58,8 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener, Butto + bagSimFrame.getY());
bag.addButtonListener(this);
-
+ bag.addLEDChangeListener(this);
+
draw();
}
@@ -115,4 +116,16 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener, Butto }
+ @Override
+ public void buttonPressed(int x, int y) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void LEDchanged() {
+ // TODO Auto-generated method stub
+
+ }
+
}
|