diff options
author | Christopher Baines <cbaines8@gmail.com> | 2011-09-02 14:47:36 +0100 |
---|---|---|
committer | Christopher Baines <cbaines8@gmail.com> | 2011-09-02 14:47:36 +0100 |
commit | 02a7a115adde9ef8e250012578f97a3848de28fb (patch) | |
tree | 4df5bfab104057bd17d51243e44b5fca4964863c | |
parent | 7085d4fc9fa6510fb7d5d11d0567edb576193d04 (diff) | |
download | punchingbag-02a7a115adde9ef8e250012578f97a3848de28fb.tar punchingbag-02a7a115adde9ef8e250012578f97a3848de28fb.tar.gz |
Much improved Effect management
-rw-r--r-- | PunchingBag/src/PunchingBag.java | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/PunchingBag/src/PunchingBag.java b/PunchingBag/src/PunchingBag.java index f141c26..8408225 100644 --- a/PunchingBag/src/PunchingBag.java +++ b/PunchingBag/src/PunchingBag.java @@ -1,11 +1,18 @@ import javax.swing.event.EventListenerList; + +import java.util.ArrayList; import java.util.Arrays; +import java.util.Iterator; + +// TODO: Loads of threads in this class, make sure everything is thread safe. public class PunchingBag implements Runnable { private byte[] rawLeds = new byte[6 * 8]; private Colour[][] leds = new Colour[9][20]; private byte[] ledGridIntensities = new byte[6]; private boolean[][] buttons = new boolean[8][19]; + + private ArrayList<Effect> runningEffects = new ArrayList<Effect>(); enum Colour { None, Red, Yellow, Green @@ -37,10 +44,8 @@ public class PunchingBag implements Runnable { } void CircleExpand(int x, int y, int delay, Colour colour) { - for (int i = 0; i <= 15; i++) { - DrawEllipse(x, y, i, i, colour); - - } + // TODO: Adam correct CircleExpand constructor, or this method? + //runningEffects.add(new CircleExpand(x,y,delay,colour)); } class Effect implements Runnable { @@ -60,10 +65,10 @@ public class PunchingBag implements Runnable { e.printStackTrace(); } } + runningEffects.remove(this); } private void draw() { - } } @@ -105,16 +110,10 @@ public class PunchingBag implements Runnable { } - if (!drawnSomething) - stop = true; - currentWidth += 0.1 + (currentWidth / 10); - try { - Thread.sleep(1000 / 60); - } catch (InterruptedException e) { - e.printStackTrace(); - } + if (!drawnSomething) + stop = true; } } @@ -186,14 +185,18 @@ public class PunchingBag implements Runnable { } } + /* Clears the led grid and stops all running effects */ public void clearLEDGrid() { + for (Iterator<Effect> iter = runningEffects.iterator(); iter.hasNext(); ) { + ((Effect) iter.next()).stop(); + } Arrays.fill(leds, Boolean.FALSE); } public void setLEDGridIntensity(byte grid, byte intensity) { ledGridIntensities[grid] = intensity; } - + public void setLEDIntensities(byte intensity) { Arrays.fill(ledGridIntensities, intensity); } |