private static List <int> alreadyTouchedLeds = new List <int>(); // fixes a weird flickering bug private static void HealthBar(LEDData data, LEDData lastFrame, GameState gameState) { if (lastFrame != null) { data.Keyboard = lastFrame.Keyboard; } float maxHealth = gameState.ActivePlayer.Stats.MaxHealth; float currentHealth = gameState.ActivePlayer.Stats.CurrentHealth; float healthPercentage = currentHealth / maxHealth; alreadyTouchedLeds.Clear(); // KEYBOARD LIGHTING int greenHPLeds = Math.Max((int)Utils.Scale(healthPercentage, 0, 1, 0, 16), 1); // at least one led active when player is alive for (int i = 0; i < 16; i++) { List <int> listLedsToTurnOn = new List <int>(6); // light the whole column for (int j = 0; j < 6; j++) { listLedsToTurnOn.Add(KeyUtils.PointToKey(new Point(i, j))); } if (i < greenHPLeds) { foreach (int idx in listLedsToTurnOn.Where(x => x != -1)) { if (alreadyTouchedLeds.Contains(idx)) { continue; } data.Keyboard[idx].MixNewColor(HealthColor, true, 0.2f); } } else { foreach (int idx in listLedsToTurnOn.Where(x => x != -1)) { if (alreadyTouchedLeds.Contains(idx)) { continue; } if (data.Keyboard[idx].color.AlmostEqual(HealthColor)) { data.Keyboard[idx].Color(HurtColor); } else { data.Keyboard[idx].FadeToBlackBy(0.08f); } } } alreadyTouchedLeds.AddRange(listLedsToTurnOn); } // LED STRIP LIGHTING int ledsToTurnOn = Math.Max((int)(healthPercentage * LEDData.NUMLEDS_STRIP), 1); for (int i = 0; i < LEDData.NUMLEDS_STRIP; i++) { if (i < ledsToTurnOn) { data.Strip[i].MixNewColor(HealthColor, true, 0.2f); } else { if (data.Strip[i].color.AlmostEqual(HealthColor)) { data.Strip[i].Color(HurtColor); } else { data.Strip[i].FadeToBlackBy(0.05f); } } } }
private LEDFrame GetLEDFrameFromLuminosities(double[] luminosities) { LEDFrame frame = LEDFrame.Empty; LEDData data = frame.Leds; //Debug.WriteLine(String.Join(",", luminosities)); int lastLuminositySpot = 0; for (int i = 0; i < LUMINOSITY_THRESHOLDS.Length; i++) { if (luminosities[i] > LUMINOSITY_THRESHOLDS[i]) { lastLuminositySpot = i; } } // TODO: Detect when it's not a valid frame so lights dont go crazy alreadyTouchedLeds.Clear(); //double lastLuminositySpotNormal = lastLuminositySpot / 20.0; //Debug.WriteLine(lastLuminositySpot); double boostCurve = lastLuminositySpot / (double)(LUMINOSITY_THRESHOLDS.Length - 1); int keyboardBoostLeds = Math.Max(boostCurve > 0 ? 1 : 0, (int)Utils.Scale(boostCurve, 0, 1, 0, 18)); // ease in // KEYBOARD for (int i = 0; i < 16; i++) { List <int> listLedsToTurnOn = new List <int>(6); // light the whole column for (int j = 0; j < 6; j++) { listLedsToTurnOn.Add(KeyUtils.PointToKey(new Point(i, j))); } if (i < keyboardBoostLeds) { foreach (int idx in listLedsToTurnOn.Where(x => x != -1)) { if (alreadyTouchedLeds.Contains(idx)) { continue; } data.Keyboard[idx].Color(BoostColor); } } else { foreach (int idx in listLedsToTurnOn.Where(x => x != -1)) { if (alreadyTouchedLeds.Contains(idx)) { continue; } if (data.Keyboard[idx].color.AlmostEqual(BoostColor)) { data.Keyboard[idx].Color(BoostColor); } else { data.Keyboard[idx].FadeToBlackBy(0.08f); } } } alreadyTouchedLeds.AddRange(listLedsToTurnOn); } // MOUSE int mouseBoostLeds = (int)Utils.Scale(boostCurve, 0, 1, 0, 8); for (int i = 0; i < LEDData.NUMLEDS_MOUSE; i++) { data.Mouse[i].FadeToBlackBy(0.01f); } if (boostCurve > 0) { data.Mouse[0].Color(BoostColor); data.Mouse[1].Color(BoostColor); for (int i = 0; i < mouseBoostLeds; i++) { data.Mouse[2 + 6 - i].Color(BoostColor); data.Mouse[2 + 7 + 6 - i].Color(BoostColor); // both sides of the mouse } } // MOUSEPAD int mousepadBoostLeds = (int)Utils.Scale(boostCurve, 0, 1, 0, 17); for (int i = 0; i < LEDData.NUMLEDS_MOUSEPAD; i++) { if (i < mousepadBoostLeds) { data.Mousepad[i].Color(BoostColor); } else { if (data.Mousepad[i].color.AlmostEqual(BoostColor)) { data.Mousepad[i].Color(BoostColor); } else { data.Mousepad[i].FadeToBlackBy(0.05f); } } } return(new LEDFrame(this, data, LightZone.Desk)); }
private static List <int> alreadyTouchedLeds = new List <int>(); // fixes a weird flickering bug private static void HealthBar(Led[] leds, LightingMode lightMode, GameState gameState) { float maxHealth = gameState.ActivePlayer.Stats.MaxHealth; float currentHealth = gameState.ActivePlayer.Stats.CurrentHealth; float healthPercentage = currentHealth / maxHealth; alreadyTouchedLeds.Clear(); if (lightMode == LightingMode.Keyboard) { int greenHPLeds = Math.Max((int)Utils.Scale(healthPercentage, 0, 1, 0, 16), 1); // at least one led active when player is alive for (int i = 0; i < 16; i++) { List <int> ledsToTurnOn = new List <int>(6); // light the whole column for (int j = 0; j < 6; j++) { ledsToTurnOn.Add(KeyUtils.PointToKey(new Point(i, j))); } if (i < greenHPLeds) { foreach (int idx in ledsToTurnOn.Where(x => x != -1)) { if (alreadyTouchedLeds.Contains(idx)) { continue; } leds[idx].MixNewColor(HealthColor, true, 0.2f); } } else { foreach (int idx in ledsToTurnOn.Where(x => x != -1)) { if (alreadyTouchedLeds.Contains(idx)) { continue; } if (leds[idx].color.AlmostEqual(HealthColor)) { leds[idx].Color(HurtColor); } else { leds[idx].FadeToBlackBy(0.08f); } } } alreadyTouchedLeds.AddRange(ledsToTurnOn); } } else { int ledsToTurnOn = Math.Max((int)(healthPercentage * leds.Length), 1); for (int i = 0; i < leds.Length; i++) { if (i < ledsToTurnOn) { leds[i].MixNewColor(HealthColor, true, 0.2f); } else { if (leds[i].color.AlmostEqual(HealthColor)) { leds[i].Color(HurtColor); } else { leds[i].FadeToBlackBy(0.05f); } } } } }