🌠 create a vector so we can spawn new drops dynamically :3
This commit is contained in:
parent
8d51a0a036
commit
f0836c66f0
@ -1,6 +1,7 @@
|
|||||||
#include "rain.h"
|
#include "rain.h"
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
#include "overlay.h"
|
#include "overlay.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#define COLOR_HIGHLIGHT_R 128
|
#define COLOR_HIGHLIGHT_R 128
|
||||||
#define COLOR_HIGHLIGHT_G 255
|
#define COLOR_HIGHLIGHT_G 255
|
||||||
@ -10,19 +11,21 @@
|
|||||||
#define COLOR_DEFAULT_G 255
|
#define COLOR_DEFAULT_G 255
|
||||||
#define COLOR_DEFAULT_B 0
|
#define COLOR_DEFAULT_B 0
|
||||||
|
|
||||||
typedef struct {
|
//typedef struct {
|
||||||
bool reached_bottom = false;
|
struct Raindrop {
|
||||||
|
//bool reached_bottom = false;
|
||||||
|
bool reached_bottom;
|
||||||
|
int x;
|
||||||
int y;
|
int y;
|
||||||
int length;
|
int length;
|
||||||
int speed;
|
int speed;
|
||||||
unsigned long last_moved;
|
unsigned long last_moved;
|
||||||
} Raindrop;
|
} ;
|
||||||
|
|
||||||
// TODO: Use a dynamic vector instead
|
|
||||||
Raindrop raindrops[PANEL_WIDTH];
|
|
||||||
bool rain_initialized = false;
|
bool rain_initialized = false;
|
||||||
uint16_t color_highlight;
|
uint16_t color_highlight;
|
||||||
uint16_t color_default;
|
uint16_t color_default;
|
||||||
|
std::vector<Raindrop> raindrops;
|
||||||
|
|
||||||
void setup_rain(MatrixPanel_I2S_DMA *matrix) {
|
void setup_rain(MatrixPanel_I2S_DMA *matrix) {
|
||||||
color_highlight = matrix->color565(
|
color_highlight = matrix->color565(
|
||||||
@ -35,11 +38,15 @@ void setup_rain(MatrixPanel_I2S_DMA *matrix) {
|
|||||||
COLOR_DEFAULT_B,
|
COLOR_DEFAULT_B,
|
||||||
COLOR_DEFAULT_G
|
COLOR_DEFAULT_G
|
||||||
);
|
);
|
||||||
for (int i = 0; i<PANEL_WIDTH; i++) {
|
for (int x = 0; x<PANEL_WIDTH; x++) {
|
||||||
raindrops[i].y = 0 - random(24);
|
raindrops.push_back({
|
||||||
raindrops[i].length = random(20, 28);
|
false,
|
||||||
raindrops[i].speed = random(25, 100);
|
x,
|
||||||
raindrops[i].last_moved = millis();
|
0 - random(24),
|
||||||
|
random(20, 28),
|
||||||
|
random(25, 100),
|
||||||
|
millis()
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,19 +57,28 @@ void draw_rain(MatrixPanel_I2S_DMA *matrix, Mode mode) {
|
|||||||
rain_initialized = true;
|
rain_initialized = true;
|
||||||
}
|
}
|
||||||
unsigned long timestamp = millis();
|
unsigned long timestamp = millis();
|
||||||
for (int x = 0; x < PANEL_WIDTH; x++) {
|
int x = 0;
|
||||||
|
while(x < raindrops.size()) {
|
||||||
if ((timestamp - raindrops[x].last_moved) > raindrops[x].speed) {
|
if ((timestamp - raindrops[x].last_moved) > raindrops[x].speed) {
|
||||||
// step down a pixel
|
// step down a pixel
|
||||||
raindrops[x].y++;
|
raindrops[x].y++;
|
||||||
raindrops[x].last_moved = timestamp;
|
raindrops[x].last_moved = timestamp;
|
||||||
}
|
}
|
||||||
if (raindrops[x].y > PANEL_HEIGHT) {
|
if (raindrops[x].y > PANEL_HEIGHT + raindrops[x].length) {
|
||||||
raindrops[x].y = 0;
|
raindrops.push_back({
|
||||||
raindrops[x].reached_bottom = true;
|
false,
|
||||||
|
raindrops[x].x,
|
||||||
|
0 - random(8),
|
||||||
|
random(20, 28),
|
||||||
|
random(0, 76),
|
||||||
|
millis()
|
||||||
|
});
|
||||||
|
raindrops.erase(raindrops.begin() + x);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
if (raindrops[x].y >= 0) {
|
if (raindrops[x].y >= 0) {
|
||||||
//draw our pixel
|
//draw our pixel
|
||||||
matrix->drawPixel(x, raindrops[x].y, matrix->color565(128, 255, 128));
|
matrix->drawPixel(raindrops[x].x, raindrops[x].y, matrix->color565(128, 255, 128));
|
||||||
// draw our trail
|
// draw our trail
|
||||||
for (int trail_offset = 1; trail_offset < raindrops[x].length; trail_offset++) {
|
for (int trail_offset = 1; trail_offset < raindrops[x].length; trail_offset++) {
|
||||||
int trail_y = raindrops[x].y - trail_offset;
|
int trail_y = raindrops[x].y - trail_offset;
|
||||||
@ -74,28 +90,25 @@ void draw_rain(MatrixPanel_I2S_DMA *matrix, Mode mode) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (trail_y < 0) {
|
if (trail_y < 0) {
|
||||||
if (not raindrops[x].reached_bottom) {
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
// we need to count from the bottom up
|
|
||||||
trail_y = PANEL_HEIGHT + trail_y;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int pixel_num = (trail_y * PANEL_WIDTH) + x;
|
int pixel_num = (trail_y * PANEL_WIDTH) + raindrops[x].x;
|
||||||
if (overlay[pixel_num / 8] & (1 << (7 - (pixel_num % 8))) and mode != Stealth) {
|
if (overlay[pixel_num / 8] & (1 << (7 - (pixel_num % 8))) and mode != Stealth) {
|
||||||
if (mode == HighVis) {
|
if (mode == HighVis) {
|
||||||
matrix->drawPixel(x, trail_y, color_highlight);
|
matrix->drawPixel(raindrops[x].x, trail_y, color_highlight);
|
||||||
} else {
|
} else {
|
||||||
matrix->drawPixel(x, trail_y, matrix->color565(
|
matrix->drawPixel(raindrops[x].x, trail_y, matrix->color565(
|
||||||
COLOR_HIGHLIGHT_R * brightness,
|
COLOR_HIGHLIGHT_R * brightness,
|
||||||
COLOR_HIGHLIGHT_G * brightness,
|
COLOR_HIGHLIGHT_G * brightness,
|
||||||
COLOR_HIGHLIGHT_B * brightness
|
COLOR_HIGHLIGHT_B * brightness
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
matrix->drawPixel(x, trail_y, fade_color);
|
matrix->drawPixel(raindrops[x].x, trail_y, fade_color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
x++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user