aboutsummaryrefslogtreecommitdiff
path: root/examples/AuroraDemo/PatternInvaders.h
diff options
context:
space:
mode:
authormrfaptastic <gmail@qwe23.com>2019-05-11 15:20:53 +0100
committermrfaptastic <gmail@qwe23.com>2019-05-11 15:20:53 +0100
commit85d0d448911ae42206cb355b9a4fdec136ad5499 (patch)
tree5e5c522cd1e177c67cf9ee8df35a36b3a9b68007 /examples/AuroraDemo/PatternInvaders.h
parent95dd8aa339fd9a52d4779174c1493b8b1a56d060 (diff)
Added new demo
Based on Aurora code.
Diffstat (limited to 'examples/AuroraDemo/PatternInvaders.h')
-rw-r--r--examples/AuroraDemo/PatternInvaders.h154
1 files changed, 154 insertions, 0 deletions
diff --git a/examples/AuroraDemo/PatternInvaders.h b/examples/AuroraDemo/PatternInvaders.h
new file mode 100644
index 0000000..cad004c
--- /dev/null
+++ b/examples/AuroraDemo/PatternInvaders.h
@@ -0,0 +1,154 @@
+/*
+ * Aurora: https://github.com/pixelmatix/aurora
+ * Copyright (c) 2014 Jason Coon
+ *
+ * Inspired by 'Space Invader Generator': https://the8bitpimp.wordpress.com/2013/05/07/space-invader-generator
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef PatternInvaders_H
+#define PatternInvaders_H
+
+class PatternInvadersSmall : public Drawable {
+ private:
+ uint8_t x = 1;
+ uint8_t y = 1;
+
+ public:
+ PatternInvadersSmall() {
+ name = (char *)"Invaders Small";
+ }
+
+ void start() {
+ matrix.fillScreen(0);
+ }
+
+ unsigned int drawFrame() {
+ CRGB color1 = effects.ColorFromCurrentPalette(random(0, 255));
+
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 5; j++) {
+ CRGB color = CRGB::Black;
+
+ if (random(0, 2) == 1) color = color1;
+
+ effects.drawBackgroundFastLEDPixelCRGB(x + i, y + j, color);
+
+ if (i < 2)
+ effects.drawBackgroundFastLEDPixelCRGB(x + (4 - i), y + j, color);
+ }
+ }
+
+ x += 6;
+ if (x > 25) {
+ x = 1;
+ y += 6;
+ }
+
+ if (y > 25) y = x = 1;
+
+ effects.ShowFrame();
+
+ return 125;
+ }
+};
+
+class PatternInvadersMedium : public Drawable {
+ private:
+ uint8_t x = 0;
+ uint8_t y = 0;
+
+ public:
+ PatternInvadersMedium() {
+ name = (char *)"Invaders Medium";
+ }
+
+ void start() {
+ matrix.fillScreen(0);
+ }
+
+ unsigned int drawFrame() {
+ CRGB color1 = effects.ColorFromCurrentPalette(random(0, 255));
+
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 5; j++) {
+ CRGB color = CRGB::Black;
+
+ if (random(0, 2) == 1) color = color1;
+
+ matrix.fillRect(x + (i * 2), y + (j * 2), x + (i * 2 + 1), y + (j * 2 + 1), color);
+
+ if (i < 2)
+ matrix.fillRect(x + (8 - i * 2), y + (j * 2), x + (9 - i * 2), y + (j * 2 + 1), color);
+ }
+ }
+
+ x += 11;
+ if (x > 22) {
+ x = 0;
+ y += 11;
+ }
+
+ if (y > 22) y = x = 0;
+
+ effects.ShowFrame();
+
+ return 500;
+ }
+};
+
+class PatternInvadersLarge : public Drawable {
+ private:
+
+ public:
+ PatternInvadersLarge() {
+ name = (char *)"Invaders Large";
+ }
+
+ void start() {
+ matrix.fillScreen(0);
+ }
+
+ unsigned int drawFrame() {
+ matrix.fillScreen(0);
+
+ CRGB color1 = effects.ColorFromCurrentPalette(random(0, 255));
+
+ for (int x = 0; x < 3; x++) {
+ for (int y = 0; y < 5; y++) {
+ CRGB color = CRGB::Black;
+
+ if (random(0, 2) == 1) {
+ color = color1;
+ }
+
+ matrix.fillRect(1 + x * 6, 1 + y * 6, 5 + x * 6, 5 + y * 6, color);
+
+ if (x < 2)
+ matrix.fillRect(1 + (4 - x) * 6, 1 + y * 6, 5 + (4 - x) * 6, 5 + y * 6, color);
+ }
+ }
+
+ effects.ShowFrame();
+
+ return 2000;
+ }
+};
+
+#endif