NeoPixels working + GameOfLife working + BorderMode
This commit is contained in:
parent
cc8482fccf
commit
9fe334c6a4
@ -30,4 +30,4 @@ add_custom_target(
|
|||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(Z_DUMMY_TARGET ${SRC_LIST} src/display/Display.h src/display/Pixel.h src/mode/GameOfLife/Cell.h)
|
add_executable(Z_DUMMY_TARGET ${SRC_LIST} src/mode/Test/Border.h)
|
||||||
|
|||||||
@ -12,3 +12,8 @@
|
|||||||
platform = espressif32
|
platform = espressif32
|
||||||
board = esp32dev
|
board = esp32dev
|
||||||
framework = arduino
|
framework = arduino
|
||||||
|
lib_deps = https://github.com/adafruit/Adafruit_NeoPixel
|
||||||
|
upload_port = /dev/ttyUSB0
|
||||||
|
upload_speed = 921600
|
||||||
|
monitor_port = /dev/ttyUSB0
|
||||||
|
monitor_speed = 115200
|
||||||
|
|||||||
@ -2,83 +2,59 @@
|
|||||||
#define DISPLAY_H
|
#define DISPLAY_H
|
||||||
|
|
||||||
#include "Pixel.h"
|
#include "Pixel.h"
|
||||||
|
#include "Adafruit_NeoPixel.h"
|
||||||
|
|
||||||
class Display {
|
class Display {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
const uint8_t width;
|
||||||
|
|
||||||
|
const uint8_t height;
|
||||||
|
|
||||||
|
const uint16_t pixelCount;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
uint8_t width;
|
Adafruit_NeoPixel leds;
|
||||||
|
|
||||||
uint8_t height;
|
|
||||||
|
|
||||||
Pixel *pixels;
|
|
||||||
|
|
||||||
uint16_t pixelCount;
|
|
||||||
|
|
||||||
bool dirty = true;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Display(uint8_t width, uint8_t height) :
|
Display(uint8_t width, uint8_t height) :
|
||||||
width(width), height(height) {
|
width(width), height(height),
|
||||||
pixelCount = width * height;
|
pixelCount(width * height),
|
||||||
pixels = (Pixel *) malloc(pixelCount * sizeof(Pixel));
|
leds(pixelCount, GPIO_NUM_13) {
|
||||||
clear();
|
// nothing
|
||||||
}
|
|
||||||
|
|
||||||
~Display() {
|
|
||||||
if (pixels != nullptr) {
|
|
||||||
free(pixels);
|
|
||||||
pixels = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t getWidth() const {
|
|
||||||
return width;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t getHeight() const {
|
|
||||||
return height;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t getPixelCount() const {
|
|
||||||
return pixelCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
void set(uint8_t x, uint8_t y, Pixel pixel) {
|
|
||||||
if (x > width || y > height) {
|
|
||||||
Serial.printf("ERROR: Cannot set pixel (%d/%d) in matrix (%d/%d).\n", x, y, width, height);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
*(pixels + y * width + x) = pixel;
|
|
||||||
dirty = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void clear() {
|
|
||||||
for (Pixel *p = pixels; p < end(); p++) {
|
|
||||||
*p = {0, 0, 0};
|
|
||||||
}
|
|
||||||
dirty = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// TODO init IO
|
leds.begin();
|
||||||
|
leds.setBrightness(8);
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void set(uint8_t x, uint8_t y, uint8_t r, uint8_t g, uint8_t b) {
|
||||||
|
if (x >= width || y >= height) {
|
||||||
|
Serial.printf("ERROR: Cannot set pixel (%d/%d) in matrix (%d/%d).\n", x, y, width, height);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
leds.setPixelColor(y * width + x, r, g, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear() {
|
||||||
|
leds.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if (!dirty) {
|
leds.show();
|
||||||
return;
|
|
||||||
}
|
|
||||||
dirty = false;
|
|
||||||
// TODO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Pixel *begin() {
|
void setBrightness(int brightness) {
|
||||||
return pixels;
|
leds.setBrightness(min(255, max(0, brightness)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Pixel *end() {
|
int getBrightness() {
|
||||||
return pixels + pixelCount;
|
return leds.getBrightness();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -13,6 +13,11 @@ public:
|
|||||||
|
|
||||||
uint8_t b;
|
uint8_t b;
|
||||||
|
|
||||||
|
Pixel(uint8_t r, uint8_t g, uint8_t b) :
|
||||||
|
r(r), g(g), b(b) {
|
||||||
|
// nothing
|
||||||
|
}
|
||||||
|
|
||||||
bool isOn() const {
|
bool isOn() const {
|
||||||
return r != 0 || g != 0 || b != 0;
|
return r != 0 || g != 0 || b != 0;
|
||||||
}
|
}
|
||||||
@ -23,6 +28,14 @@ public:
|
|||||||
b = brightness;
|
b = brightness;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t toInt() const {
|
||||||
|
return (((r << 8) | g) << 8) | b;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Pixel gray(uint8_t brightness) {
|
||||||
|
return {brightness, brightness, brightness};
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
27
src/display/Vector.h
Normal file
27
src/display/Vector.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#ifndef POSITION_H
|
||||||
|
#define POSITION_H
|
||||||
|
|
||||||
|
#include "BASICS.h"
|
||||||
|
|
||||||
|
class Vector {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
double x;
|
||||||
|
|
||||||
|
double y;
|
||||||
|
|
||||||
|
Vector(double x, double y) :
|
||||||
|
x(x), y(y) {
|
||||||
|
// nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector(long degrees, double length) {
|
||||||
|
double radians = (double) degrees * DEG_TO_RAD;
|
||||||
|
x = cos(radians) * length;
|
||||||
|
y = sin(radians) * length;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
59
src/main.cpp
59
src/main.cpp
@ -1,12 +1,14 @@
|
|||||||
#include "mode/Mode.h"
|
#include "mode/Mode.h"
|
||||||
#include "mode/GameOfLife/GameOfLife.h"
|
#include "mode/GameOfLife/GameOfLife.h"
|
||||||
#include "display/Display.h"
|
#include "display/Display.h"
|
||||||
|
#include "mode/Pong/Pong.h"
|
||||||
|
#include "mode/Test/Border.h"
|
||||||
|
|
||||||
enum ModeId {
|
enum ModeId {
|
||||||
NONE, GAME_OF_LIFE
|
NONE, BORDER, GAME_OF_LIFE, PONG
|
||||||
};
|
};
|
||||||
|
|
||||||
Display display(8, 16);
|
Display display(32, 8);
|
||||||
|
|
||||||
ModeId newModeId = GAME_OF_LIFE;
|
ModeId newModeId = GAME_OF_LIFE;
|
||||||
|
|
||||||
@ -24,18 +26,58 @@ void unloadOldMode();
|
|||||||
|
|
||||||
void loadNewMode();
|
void loadNewMode();
|
||||||
|
|
||||||
|
void setBrightness(int value);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
delay(500);
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.println("\n\n\nStartup!\n");
|
Serial.println("\n\n\nStartup!\n");
|
||||||
display.setup();
|
display.setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setSpeed(double value);
|
||||||
|
|
||||||
|
double speed = 1.0;
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
if (Serial.available()) {
|
||||||
|
int input = Serial.read();
|
||||||
|
switch (input) {
|
||||||
|
case '0':
|
||||||
|
case '1':
|
||||||
|
case '2':
|
||||||
|
case '3':
|
||||||
|
newModeId = (ModeId) (input - '0');
|
||||||
|
break;
|
||||||
|
case '+':
|
||||||
|
setBrightness(display.getBrightness() + 10);
|
||||||
|
break;
|
||||||
|
case '-':
|
||||||
|
setBrightness(max(1, display.getBrightness() - 10));
|
||||||
|
break;
|
||||||
|
case ',':
|
||||||
|
setSpeed(speed / 1.1);
|
||||||
|
break;
|
||||||
|
case '.':
|
||||||
|
setSpeed(speed * 1.1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
checkMode();
|
checkMode();
|
||||||
display.loop();
|
display.loop();
|
||||||
stepMode();
|
stepMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setBrightness(int value) {
|
||||||
|
display.setBrightness(value);
|
||||||
|
Serial.printf("Setting brightness to %5.1f%%\n", value / 2.55);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setSpeed(double value) {
|
||||||
|
speed = min(1000.0, max(0.001, value));
|
||||||
|
Serial.printf("Setting speed to %6.2fx\n", value);
|
||||||
|
}
|
||||||
|
|
||||||
void checkMode() {
|
void checkMode() {
|
||||||
if (currentModeId != newModeId) {
|
if (currentModeId != newModeId) {
|
||||||
unloadOldMode();
|
unloadOldMode();
|
||||||
@ -45,7 +87,6 @@ void checkMode() {
|
|||||||
|
|
||||||
void unloadOldMode() {
|
void unloadOldMode() {
|
||||||
if (mode != nullptr) {
|
if (mode != nullptr) {
|
||||||
Serial.printf("Unloading state \"%s\".\n", mode->getName());
|
|
||||||
delete mode;
|
delete mode;
|
||||||
mode = nullptr;
|
mode = nullptr;
|
||||||
}
|
}
|
||||||
@ -55,15 +96,21 @@ void unloadOldMode() {
|
|||||||
void loadNewMode() {
|
void loadNewMode() {
|
||||||
currentModeId = newModeId;
|
currentModeId = newModeId;
|
||||||
lastMillis = 0;
|
lastMillis = 0;
|
||||||
Serial.printf("Loading state #%d.\n", currentModeId);
|
Serial.printf("Loading mode: #%d\n", currentModeId);
|
||||||
switch (currentModeId) {
|
switch (currentModeId) {
|
||||||
case NONE:
|
case NONE:
|
||||||
break;
|
break;
|
||||||
|
case BORDER:
|
||||||
|
mode = new Border(&display);
|
||||||
|
break;
|
||||||
case GAME_OF_LIFE:
|
case GAME_OF_LIFE:
|
||||||
mode = new GameOfLife(&display);
|
mode = new GameOfLife(&display);
|
||||||
break;
|
break;
|
||||||
|
case PONG:
|
||||||
|
mode = new Pong(&display);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
Serial.printf("Loaded state \"%s\".\n", mode == nullptr ? "None" : mode->getName());
|
Serial.printf("Loaded mode: %s\n\n", mode == nullptr ? "None" : mode->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
void stepMode() {
|
void stepMode() {
|
||||||
@ -73,5 +120,5 @@ void stepMode() {
|
|||||||
millis_t currentMillis = millis();
|
millis_t currentMillis = millis();
|
||||||
millis_t dt = currentMillis - lastMillis;
|
millis_t dt = currentMillis - lastMillis;
|
||||||
lastMillis = currentMillis;
|
lastMillis = currentMillis;
|
||||||
mode->step(dt);
|
mode->step((millis_t) max(1.0, (double) dt * speed));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,10 +21,12 @@ public:
|
|||||||
|
|
||||||
void spawn() {
|
void spawn() {
|
||||||
state = GROWING;
|
state = GROWING;
|
||||||
|
value = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void kill() {
|
void kill() {
|
||||||
state = DYING;
|
state = DYING;
|
||||||
|
value = 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
void animate(uint8_t dt) {
|
void animate(uint8_t dt) {
|
||||||
@ -49,6 +51,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint8_t getR() const {
|
uint8_t getR() const {
|
||||||
|
if (state == ALIVE) {
|
||||||
|
return 255;
|
||||||
|
}
|
||||||
if (state == DYING) {
|
if (state == DYING) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@ -56,6 +61,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint8_t getG() const {
|
uint8_t getG() const {
|
||||||
|
if (state == ALIVE) {
|
||||||
|
return 255;
|
||||||
|
}
|
||||||
if (state == GROWING) {
|
if (state == GROWING) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,32 +9,37 @@ class GameOfLife : public Mode {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
const uint8_t width;
|
millis_t runtime = 0;
|
||||||
const uint8_t height;
|
|
||||||
const uint16_t count;
|
uint8_t steps = 0;
|
||||||
|
|
||||||
uint16_t aliveCount = 0;
|
uint16_t aliveCount = 0;
|
||||||
|
|
||||||
millis_t runtime = 0;
|
uint16_t lastAliveCount = 0;
|
||||||
uint8_t steps = 0;
|
|
||||||
|
|
||||||
Cell *cells;
|
Cell *cells;
|
||||||
|
Cell *last;
|
||||||
|
|
||||||
Cell *next;
|
Cell *next;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
explicit GameOfLife(Display *display) :
|
explicit GameOfLife(Display *display) :
|
||||||
Mode(display, "Game of Life"),
|
Mode(display, "Game of Life") {
|
||||||
width(display->getWidth()),
|
cells = (Cell *) malloc(display->pixelCount * sizeof(Cell));
|
||||||
height(display->getHeight()),
|
last = cells;
|
||||||
count(display->getPixelCount()) {
|
for (Cell *cell = cells; cell < cells + display->pixelCount; cell++) {
|
||||||
cells = (Cell *) malloc(count * sizeof(Cell));
|
cell->state = DEAD;
|
||||||
next = (Cell *) malloc(count * sizeof(Cell));
|
cell->value = 0;
|
||||||
|
}
|
||||||
|
next = (Cell *) malloc(display->pixelCount * sizeof(Cell));
|
||||||
|
for (Cell *cell = next; cell < next + display->pixelCount; cell++) {
|
||||||
|
cell->state = DEAD;
|
||||||
|
cell->value = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
~GameOfLife()
|
~GameOfLife() override {
|
||||||
|
|
||||||
override {
|
|
||||||
if (cells != nullptr) {
|
if (cells != nullptr) {
|
||||||
free(cells);
|
free(cells);
|
||||||
cells = nullptr;
|
cells = nullptr;
|
||||||
@ -45,13 +50,13 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void step(millis_t dt)
|
void step(millis_t dt) override {
|
||||||
|
|
||||||
override {
|
|
||||||
runtime += dt;
|
runtime += dt;
|
||||||
while (runtime % 100 == 0) {
|
if (runtime >= 500) {
|
||||||
if (steps++ == 0 || aliveCount == 0) {
|
runtime = 0;
|
||||||
steps = 0;
|
bool isSteady = lastAliveCount == aliveCount;
|
||||||
|
lastAliveCount = aliveCount;
|
||||||
|
if (steps++ == 0 || aliveCount == 0 || isSteady) {
|
||||||
randomFill();
|
randomFill();
|
||||||
} else {
|
} else {
|
||||||
nextGeneration();
|
nextGeneration();
|
||||||
@ -63,7 +68,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
void randomFill() {
|
void randomFill() {
|
||||||
for (Cell *cell = cells; cell < cells + count; cell++) {
|
for (Cell *cell = cells; cell < cells + display->pixelCount; cell++) {
|
||||||
if (random(4) == 0) {
|
if (random(4) == 0) {
|
||||||
if (!cell->isAlive()) {
|
if (!cell->isAlive()) {
|
||||||
cell->spawn();
|
cell->spawn();
|
||||||
@ -79,30 +84,48 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void nextGeneration() {
|
void nextGeneration() {
|
||||||
for (int y = 0; y < height; y++) {
|
memcpy(next, cells, display->pixelCount * sizeof(Cell));
|
||||||
for (int x = 0; x < width; x++) {
|
Cell *src = cells;
|
||||||
Cell *cell = get(x, y);
|
Cell *dst = next;
|
||||||
|
for (int y = 0; y < display->height; y++) {
|
||||||
|
for (int x = 0; x < display->width; x++) {
|
||||||
uint8_t around = countAround(x, y);
|
uint8_t around = countAround(x, y);
|
||||||
if (cell->isAlive()) {
|
if (src->isAlive()) {
|
||||||
if (around <= 2 || 4 <= around) {
|
if (around <= 2 || 4 <= around) {
|
||||||
cell->kill();
|
dst->kill();
|
||||||
aliveCount--;
|
aliveCount--;
|
||||||
}
|
}
|
||||||
} else if (around == 3) {
|
} else if (around == 3) {
|
||||||
cell->spawn();
|
dst->spawn();
|
||||||
aliveCount++;
|
aliveCount++;
|
||||||
}
|
}
|
||||||
|
src++;
|
||||||
|
dst++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
memcpy(cells, next, count);
|
memcpy(cells, next, display->pixelCount * sizeof(Cell));
|
||||||
|
}
|
||||||
|
|
||||||
|
void print() {
|
||||||
|
Cell *cell = cells;
|
||||||
|
for (int y = 0; y < display->height; y++) {
|
||||||
|
Serial.print("|");
|
||||||
|
for (int x = 0; x < display->width; x++) {
|
||||||
|
Serial.print(cell->isAlive() ? "x|" : " |");
|
||||||
|
cell++;
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void animate(millis_t dt) {
|
void animate(millis_t dt) {
|
||||||
Cell *cell = cells;
|
Cell *cell = cells;
|
||||||
for (int y = 0; y < height; y++) {
|
for (int y = 0; y < display->height; y++) {
|
||||||
for (int x = 0; x < width; x++) {
|
for (int x = 0; x < display->width; x++) {
|
||||||
cell->animate(dt);
|
cell->animate(dt);
|
||||||
display->set(x, y, {cell->getR(), cell->getG(), cell->getB()});
|
int xx = (y % 2) == 0 ? display->width - x - 1 : x;
|
||||||
|
display->set(xx, y, cell->getR(), cell->getG(), cell->getB());
|
||||||
cell++;
|
cell++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -110,21 +133,20 @@ private:
|
|||||||
|
|
||||||
uint8_t countAround(int x, int y) {
|
uint8_t countAround(int x, int y) {
|
||||||
return countIfAlive(x - 1, y - 1) + countIfAlive(x + 0, y - 1) + countIfAlive(x + 1, y - 1) +
|
return countIfAlive(x - 1, y - 1) + countIfAlive(x + 0, y - 1) + countIfAlive(x + 1, y - 1) +
|
||||||
countIfAlive(x - 1, y + 0) + countIfAlive(x + 0, y + 0) + countIfAlive(x + 1, y + 0) +
|
countIfAlive(x - 1, y + 0) + /* */ countIfAlive(x + 1, y + 0) +
|
||||||
countIfAlive(x - 1, y + 1) + countIfAlive(x + 0, y + 1) + countIfAlive(x + 1, y + 1);
|
countIfAlive(x - 1, y + 1) + countIfAlive(x + 0, y + 1) + countIfAlive(x + 1, y + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t countIfAlive(int x, int y) {
|
uint8_t countIfAlive(int x, int y) {
|
||||||
if (x < 0 || y < 0 || x >= width || y >= height) {
|
if (x < 0 || y < 0 || x >= display->width || y >= display->height) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return get(x, y)->isAlive() ? 1 : 0;
|
return get(x, y)->isAlive() ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Cell *get(int x, int y) {
|
Cell *get(int x, int y) {
|
||||||
return cells + width * y + x;
|
return cells + display->width * y + x;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
16
src/mode/Pong/Player.h
Normal file
16
src/mode/Pong/Player.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#ifndef PLAYER_H
|
||||||
|
#define PLAYER_H
|
||||||
|
|
||||||
|
#include "BASICS.h"
|
||||||
|
|
||||||
|
class Player {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
int8_t position = 0;
|
||||||
|
|
||||||
|
uint8_t score = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
41
src/mode/Pong/Pong.h
Normal file
41
src/mode/Pong/Pong.h
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#ifndef PONG_H
|
||||||
|
#define PONG_H
|
||||||
|
|
||||||
|
#include "mode/Mode.h"
|
||||||
|
#include "Player.h"
|
||||||
|
#include "display/Vector.h"
|
||||||
|
|
||||||
|
class Pong : public Mode {
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
Player player0;
|
||||||
|
|
||||||
|
Player player1;
|
||||||
|
|
||||||
|
Vector position;
|
||||||
|
|
||||||
|
Vector velocity;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
explicit Pong(Display *display) :
|
||||||
|
Mode(display, "Pong"),
|
||||||
|
position(display->width / 2.0, display->height / 2.0),
|
||||||
|
velocity(random(360), exp10(1)) {
|
||||||
|
// nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
static int8_t randomSignum() {
|
||||||
|
return random(2) == 0 ? -1 : +1;
|
||||||
|
}
|
||||||
|
|
||||||
|
~Pong() override = default;
|
||||||
|
|
||||||
|
void step(millis_t dt) override {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
31
src/mode/Test/Border.h
Normal file
31
src/mode/Test/Border.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#ifndef TEST_H
|
||||||
|
#define TEST_H
|
||||||
|
|
||||||
|
#include "mode/Mode.h"
|
||||||
|
|
||||||
|
class Border : public Mode {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
explicit Border(Display *display) :
|
||||||
|
Mode(display, "Border") {
|
||||||
|
// nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
~Border() override = default;
|
||||||
|
|
||||||
|
void step(millis_t dt) override {
|
||||||
|
for (int y = 0; y < display->height; y++) {
|
||||||
|
for (int x = 0; x < display->width; x++) {
|
||||||
|
if (x == 0 || x == display->width - 1 || y == 0 || y == display->height - 1) {
|
||||||
|
display->set(x, y, 255, 255, 255);
|
||||||
|
} else {
|
||||||
|
display->set(x, y, 0, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Loading…
Reference in New Issue
Block a user