//for
// https://forum.arduino.cc/t/help-creating-a-space-invaders-game/1056886
// wokwi: https://wokwi.com/projects/349068891377369684
# define WIDTH 7
int virtualColmRowToRealN(int virtualColm, int virtualRow)
{
int realN;
realN = virtualRow / 2; // full double rows
realN = realN * WIDTH * 2; // add double width
// then fix the column in
if (virtualRow & 0x1) { // odd rows
realN += WIDTH * 2 - virtualColm - 1;
}
else { // even rows
realN += virtualColm;
}
// or use the teneray operator instead of if/else
// realN += (virtualRow & 0x1) ? ( WIDTH * 2 - virtualColm - 1) : virtualColm;
return realN;
}
void setup() {
Serial.begin(115200);
Serial.println("hello maths workd!\n");
for (int row = 0; row < WIDTH; row++) {
for (int colm = 0; colm < WIDTH; colm++) {
Serial.print(virtualColmRowToRealN(colm, row));
Serial.print(" ");
}
Serial.println("");
}
}
void loop() {
// put your main code here, to run repeatedly:
}