From 86cec9936725d9a63cc312dab2d4420512ee7cff Mon Sep 17 00:00:00 2001 From: Kenneth van Ewijk Date: Thu, 9 Jul 2015 16:48:54 +0200 Subject: [PATCH] Added LedStrip effects --- model/GameModel.java | 102 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 88 insertions(+), 14 deletions(-) diff --git a/model/GameModel.java b/model/GameModel.java index 0abfafd..b6841bb 100644 --- a/model/GameModel.java +++ b/model/GameModel.java @@ -5,11 +5,12 @@ import java.awt.Color; import main.Window; import control.GameStateManager; import control.NetworkHandler; -import control.button.ButtonHandler; +import control.SongHandler; public class GameModel { public static Color[] colors = { Color.GREEN, Color.YELLOW, Color.RED, Color.MAGENTA, Color.CYAN, Color.BLUE }; + private static String[] ledStripModes = {"full", "half", "quarter", "random"}; private GameStateManager gsm; private NetworkHandler ntw; private int count = 0; @@ -17,28 +18,101 @@ public class GameModel { public GameModel(SongHandler sh, GameStateManager gsm, NetworkHandler ntw) { this.gsm = gsm; this.ntw = ntw; - - for (int i = 1; i < ButtonHandler.getButtons().size(); i++) { - ButtonHandler.getButtons().get(i).setColor(colors[i - 1]); - ; - } } public void update(float factor) { gsm.update(factor); - - Color c = colors[(int) (Math.random() * (colors.length - 1) + 1)]; - - if (Window.ON_RASP) { - count++; - if(count>15) + if (Window.ON_ARCADE) + updateLedStrip(factor); + } + + private void updateLedStrip(float factor) + { + + count += factor; + if(count > 400) + { + String mode = ledStripModes[(int) (Math.random() * (ledStripModes.length - 1) + 1)]; + + switch(mode) { - for (int i = 7; i < 54; i++) { + default: + case "full": + + Color c = colors[(int) (Math.random() * (colors.length - 1) + 1)]; + + for (int i = 6; i < 36; i++) { //TODO ntw.setLed(i, c.getRed(), c.getGreen(), c.getBlue()); } + ntw.show(); - count = 0; + + break; + + case "half": + + Color c1 = colors[(int) (Math.random() * (colors.length - 1) + 1)]; + Color c2 = colors[(int) (Math.random() * (colors.length - 1) + 1)]; + while(c1==c2) + c2 = colors[(int) (Math.random() * (colors.length - 1) + 1)]; + + for (int i = 6; i < 21; i++) { //TODO + ntw.setLed(i, c1.getRed(), c1.getGreen(), c1.getBlue()); + } + for (int i = 22; i < 36; i++) { //TODO + ntw.setLed(i, c2.getRed(), c2.getGreen(), c2.getBlue()); + } + + ntw.show(); + + break; + + case "quarter": + + Color c3 = colors[(int) (Math.random() * (colors.length - 1) + 1)]; + Color c4 = colors[(int) (Math.random() * (colors.length - 1) + 1)]; + Color c5 = colors[(int) (Math.random() * (colors.length - 1) + 1)]; + Color c6 = colors[(int) (Math.random() * (colors.length - 1) + 1)]; + + while(c3==c4) + c4 = colors[(int) (Math.random() * (colors.length - 1) + 1)]; + while(c4==c5) + c5 = colors[(int) (Math.random() * (colors.length - 1) + 1)]; + while(c5==c6) + c6 = colors[(int) (Math.random() * (colors.length - 1) + 1)]; + + for (int i = 6; i < 14; i++) { //TODO + ntw.setLed(i, c3.getRed(), c3.getGreen(), c3.getBlue()); + } + for (int i = 15; i < 21; i++) { //TODO + ntw.setLed(i, c4.getRed(), c4.getGreen(), c4.getBlue()); + } + for (int i = 22; i < 28; i++) { //TODO + ntw.setLed(i, c5.getRed(), c5.getGreen(), c5.getBlue()); + } + for (int i = 28; i <36; i++) { //TODO + ntw.setLed(i, c6.getRed(), c6.getGreen(), c6.getBlue()); + } + + ntw.show(); + + break; + + case "random": + + Color c7; + + for (int i = 6; i < 36; i++) { //TODO + c7 = colors[(int) (Math.random() * (colors.length - 1) + 1)]; + ntw.setLed(i, c7.getRed(), c7.getGreen(), c7.getBlue()); + } + + ntw.show(); + + break; } + + count = 0; } } }