Creeper blink

This commit is contained in:
Patrick Haßel 2025-01-20 14:32:56 +01:00
parent 6b4ed1658c
commit ad16660716

View File

@ -190,23 +190,45 @@ public:
return countof(sym[0]);
}
static bool doCreeperBlink() {
const auto now = millis();
static auto blink = false;
static auto last = now;
if (!blink) {
if (now - last >= 3000) {
last = now;
if (random(3) == 0) {
blink = true;
}
}
} else {
if (now - last >= 500) {
last = now;
blink = false;
}
}
return blink;
}
// TODO REMOVE QUICK & DIRTY
uint8_t printCreeper(uint8_t xPos, uint8_t yPos) {
Color G = GREEN;
Color I = {128, 255, 128};
Color O = BLACK;
const auto creeperBlink = doCreeperBlink();
Color sym[7][7] = {
{G, G, G, G, G, G, G},
{G, I, I, I, I, I, G},
{G, I, O, I, O, I, G},
{G, I, I, I, I, I, G},
{G, I, O, O, O, I, G},
{G, I, O, I, O, I, G},
{G, G, G, G, G, G, G},
{X, X, X, X, X, X, X},
{X, _, _, X, _, _, X},
{X, _, _, X, _, _, X},
{X, X, X, X, X, X, X},
{X, X, _, _, _, X, X},
{X, X, _, X, _, X, X},
{X, X, X, X, X, X, X},
};
for (int y = 0; y < countof(sym); ++y) {
for (int x = 0; x < countof(sym[0]); ++x) {
set(xPos + x, yPos + y, sym[y][x]);
if (creeperBlink && ((x == 1 || x == 2) && y == 1)) {
set(xPos + x, yPos + y, BLACK);
} else {
set(xPos + x, yPos + y, sym[y][x] ? GREEN : BLACK);
}
}
}
return countof(sym[0]);