/*
* Shooter 8x8 von Daniel Süsstrunk an der Kanti-Baden 2022 für's Freifach Robotik geschrieben
* Programm-Logik inspiriert durch Dylan Bennett und sein Buch «Game Development with Pico-8»
* https://mboffin.itch.io/gamedev-with-pico-8-issue1
* Game inspiriert durch Attack of the Cherry Tomato
* https://github.com/evil-mad/MeggyJrRGB/tree/master/examples/MeggyJr_Attack
* auf der Konsole Meggy Jr. von Mad Evil Scientist https://shop.evilmadscientist.com/productsmenu/100
* Funktioniert auf einem ESP32 mit
* - 4 Tasten an GND und den Pins 35, 27, 26 und 25
* - 1000µF Kondensator zwischen GND und 5V
* - 1 8x8 RGB Neopixel-Matrix über 330 Ohm Widerstand an Pin 33 befestigt
*/
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#define NEOPIXEL_PIN 33
// MATRIX DECLARATION:
// Parameter 1 = width of NeoPixel matrix
// Parameter 2 = height of matrix
// Parameter 3 = pin number (most are valid)
// Parameter 4 = matrix layout flags, add together as needed:
// NEO_MATRIX_TOP, NEO_MATRIX_BOTTOM, NEO_MATRIX_LEFT, NEO_MATRIX_RIGHT:
// Position of the FIRST LED in the matrix; pick two, e.g.
// NEO_MATRIX_TOP + NEO_MATRIX_LEFT for the top-left corner.
// NEO_MATRIX_ROWS, NEO_MATRIX_COLUMNS: LEDs are arranged in horizontal
// rows or in vertical columns, respectively; pick one or the other.
// NEO_MATRIX_PROGRESSIVE, NEO_MATRIX_ZIGZAG: all rows/columns proceed
// in the same order, or alternate lines reverse direction; pick one.
// See example below for these values in action.
// Parameter 5 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_GRBW Pixels are wired for GRBW bitstream (RGB+W NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(8, 8, NEOPIXEL_PIN,
NEO_MATRIX_BOTTOM + NEO_MATRIX_RIGHT +
NEO_MATRIX_COLUMNS + NEO_MATRIX_PROGRESSIVE,
NEO_GRB + NEO_KHZ800);
long long next_frame; // Millis, wann es wieder Zeit ist, ein Frame zu rechnen und darzustellen
int millis_between_frames = 33; // Millis zwischen einzelnen Frames (--> 30 FPS)
void setup() {
Serial.begin(57600); // Verbindung mit dem Compi für's Debugging
matrix.begin(); // Matrix wird initialisiert
matrix.setBrightness(40); // Matrix-Helligkeit wird für's Stromsparen reduziert (USB gibt nur 500mA her)
init(); // Die Initialisierungs-Routine des Spiels wird aufgerufen
}
void init(){ // Die Initialisierungs-Routine des Spiels
matrix.fillScreen(0); // Display-RAM wird gelöscht
matrix.fillRect(0,0,4,4,matrix.Color(255,0,0)); // Oben links rot
matrix.fillRect(4,0,4,4,matrix.Color(0,255,0)); // Oben rechts grün
matrix.fillRect(0,4,4,4,matrix.Color(0,0,255)); // unten links blau
matrix.fillRect(4,4,4,4,matrix.Color(255,255,255)); // unten rechts weiss
matrix.drawRect(1,1,6,6,matrix.Color(0,0,0));
// Weitere Zeichnungs-Funktionen finden Sie in der Adafruit_GFX Library:
// ~/Documents/Arduino/Adafruit_GFX/Adafruit_GFX.h
matrix.show(); // Display-RAM wird dargestellt.
next_frame = millis(); // Das nächste Frame wird sofort berechnet werden
}
void loop() {
if(millis() > next_frame){ // Wenn es Zeit für ein neues Frame ist (alle 33 ms)
next_frame = millis() + millis_between_frames; // Wird die Zeit für das nächste Frame berechnet
update_and_move_things(); // Dann werden die Buttons abgefragt und es wird alles berechnet
draw_things(); // ...und schliesslich alles neu gezeichnet
}
else{
}
}
void update_and_move_things(){ // In dieser Update-Routine werden Tasten abgefragt und Objekte
} // im RAM verschoben
void draw_things(){ // In dieser Zeichnen-Routine werden alle Dinge gezeichnet
}