-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoard.cpp
More file actions
66 lines (61 loc) · 1.86 KB
/
Copy pathBoard.cpp
File metadata and controls
66 lines (61 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "Board.h"
BoardElement board[BOARD_H][BOARD_W] = {{{}}};
#ifdef ARDUINO_AVR_UNO
#define NUM_LEDS 64
#define LEDS_DATA_PIN 3
#include <Arduino.h>
#include <FastLED.h>
CRGB leds[NUM_LEDS];
#else
#include <iostream>
#include <stdlib.h>
using namespace std;
#endif
void setupBoard() {
#ifdef ARDUINO_AVR_UNO
FastLED.addLeds<WS2812, LEDS_DATA_PIN, GRB>(leds, NUM_LEDS);
#endif
}
void displayMap(Time currT) {
#ifdef ARDUINO_AVR_UNO
for (int by = 0; by < BOARD_H*2; ++by) {
for (int bx = 0; bx < BOARD_W*2; ++bx) {
int ind = by * 8 + ((by % 2 == 0) ? (8 - 1 - bx) : bx); // goes right to left on even index rows
int y = by / 2;
int x = bx / 2;
BoardElement& elem = board[y][x];
if (elem.note != NULL) {
Note* note = elem.note;
auto t = NOTE_TIMES[songNum][note->id];
auto l = 1000;//NOTE_LENGTHS[songNum][note->id];
long relativeToEndT = (long)t + l - currT;
if (relativeToEndT < 0) {
if (relativeToEndT < -LEEWAY_MS) {
elem.note = NULL; // note expired
}
leds[ind] = CRGB::Black;
continue;
}
const int BRIGHTNESS = 100;
auto b = BRIGHTNESS - relativeToEndT * BRIGHTNESS / l;
Player* player = note->owner;
leds[ind] = player->id == 0 ? CRGB(0, b, BRIGHTNESS - b) : player->id == 1 ? CRGB(BRIGHTNESS - b, b, 0) : CRGB::Purple;
} else if (elem.player != NULL) {
Player* player = elem.player;
leds[ind] = player->id == 0 ? CRGB(0, 0, 10) : player->id == 1 ? CRGB(10, 0, 0) : CRGB::Purple;
} else {
leds[ind] = CRGB::Black;
}
}
}
FastLED.show();
#else
//system("clear");
for (int i = 0; i < BOARD_H; ++i) {
for (int j = 0; j < BOARD_W; ++j) {
cout << (char)((board[i][j].player != NULL) ? (board[i][j].player->id + '0') : '-');
}
cout << endl;
}
#endif
}