Hi all, I'm trying to create a space invaders game using an RGB WS2812B LED 22x22 sheet (which is really just a strip that a company made into a sheet that zig-zags back and forth). Below is an amazon link to the exact "sheet" of led's I purchased if you need to see that.
I have the character and enemies relatively moving how I want them to, but now I'm stuck trying to figure out how to shoot upwards. I can't just subtract a certain amount of space from the 'top-point' of the spaceship, as the zig-zag of the strip causes that distance to change depending on where the player is.
Is there a way to collect the column of the led matrix so that I can move the led light upwards rather than side to side?
Alternatively..... Is there a way to reverse the order of the matrix of every other line so that my led sheet iterates in a progressive manner, rather than a back-and-forth/zig-zag/snaking pattern
Current Code:
#include <FastLED.h>
#define LED_PIN 7
#define NUM_LEDS 484
#define NUM_ROWS 22
#define NUM_COLS 22
CRGB leds[NUM_LEDS];
unsigned long time;
unsigned long timeMillis;
int buttonValue = A0;
int top = 452;
int left = 472;
int right = 470;
int mid = 471;
int shot;
void setup() {
// put your setup code here, to run once:
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
leds[right] = CRGB(0, 0, 255);
leds[mid] = CRGB(0, 0, 255);
leds[left] = CRGB(0, 0, 255);
leds[top] = CRGB(0, 0, 255);
FastLED.show();
Serial.begin(9600);
}
void loop() {
time = millis() / 1000;
timeMillis = millis();
// put your main code here, to run repeatedly:
int temp = analogRead(buttonValue);
//Serial.println(temp);
//Enemy Movement
if (time % 2 == 0) {
leds[time] = CRGB(255, 0, 0);
leds[time + 2] = CRGB(255, 0, 0);
leds[time + 4] = CRGB(255, 0, 0);
leds[time + 6] = CRGB(255, 0, 0);
FastLED.show();
if (time >= 2) {
leds[time - 2] = CRGB(0, 0, 0);
FastLED.show();
}
}
//Player Controls
if (temp < 100) {
//do nothing
} else if (temp < 360 && right <= 484 && top >= 441) {
//do something
Serial.println("button left pressed");
leds[right++] = CRGB(0, 0, 255);
leds[mid++] = CRGB(0, 0, 255);
leds[left++] = CRGB(0, 0, 255);
leds[top--] = CRGB(0, 0, 255);
leds[right - 2] = CRGB(0, 0, 0);
leds[top + 2] = CRGB(0, 0, 0);
FastLED.show();
delay(400);
} else if (temp < 460) {
Serial.println("button shoot pressed");
shot = top - 25;
leds[shot] = CRGB(0, 255, 0);
} else if (temp < 960) {
Serial.println("button right pressed");
leds[right--] = CRGB(0, 0, 255);
leds[mid--] = CRGB(0, 0, 255);
leds[left--] = CRGB(0, 0, 255);
leds[top++] = CRGB(0, 0, 255);
leds[left + 2] = CRGB(0, 0, 0);
leds[top - 2] = CRGB(0, 0, 0);
FastLED.show();
delay(400);
}
}



