SnakeEffect now has a shorter tail.

This commit is contained in:
Fabian Schlenz 2019-05-31 23:58:58 +02:00
parent 29e136b8db
commit 12c5bc229d
1 changed files with 12 additions and 12 deletions

View File

@ -2,22 +2,22 @@
#include "functions.h"
void SnakeEffect::loop() {
if (run++ % EFFECT_SNAKE_SLOWDOWN) return;
uint8_t r = random8(EFFECT_SNAKE_DIRECTION_CHANGE);
if (r==0 && valid_position(update_position(this->coords, direction+1))) {
direction++;
} else if (r==1 && valid_position(update_position(this->coords, direction-1))) {
direction--;
} else if (!valid_position(update_position(this->coords, direction))) {
if (valid_position(update_position(this->coords, direction+1))) {
if (run++ % EFFECT_SNAKE_SLOWDOWN == 0) { // Change the coordinates only on every n-th run.
uint8_t r = random8(EFFECT_SNAKE_DIRECTION_CHANGE);
if (r==0 && valid_position(update_position(this->coords, direction+1))) {
direction++;
} else if (valid_position(update_position(this->coords, direction-1))) {
} else if (r==1 && valid_position(update_position(this->coords, direction-1))) {
direction--;
} else if (!valid_position(update_position(this->coords, direction))) {
if (valid_position(update_position(this->coords, direction+1))) {
direction++;
} else if (valid_position(update_position(this->coords, direction-1))) {
direction--;
}
}
}
this->coords = update_position(this->coords, direction);
this->coords = update_position(this->coords, direction);
}
fadeToBlackBy(leds, LED_COUNT, 2);
setPixel(window, this->coords.x, this->coords.y, CHSV(hue, 200, 255));