forked from Oyaki122/musicGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrhythm.cpp
98 lines (89 loc) · 2.34 KB
/
rhythm.cpp
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <time.h>
#include <chrono>
#include <iostream>
class CRGB {
public:
int r = 0;
int g = 0;
int b = 0;
CRGB() {
this->r = 0;
this->g = 0;
this->b = 0;
}
CRGB(int r, int g, int b) {
this->r = r;
this->g = g;
this->b = b;
}
int operator==(CRGB obj) {
bool flag = (this->r == obj.r && this->g == obj.g) && this->b == obj.b;
return flag ? 1 : 0;
}
}; //多分こんな感じで実装されてる。。。?わからん。
CRGB leds[20];
class Led {
private:
long long counter = 0; //描写した回数
int timing_counter = 0; //ノーツを降らした回数
int draw_conter = 0; //譜面を流した回数
int speed;
int LED_NUM;
int FPS;
int* timing;
int timing_num;
public:
Led(int speed, int LED_NUM, int FPS, int* timing, int timing_num) {
this->speed = speed;
this->LED_NUM = LED_NUM;
this->FPS = FPS;
this->timing = timing;
this->timing_num = timing_num;
}
void draw() {
counter++;
if (counter % speed == 0) {
draw_conter++;
for (int i = LED_NUM - 1; i > 0; i--) {
leds[i] = leds[i - 1];
}
leds[0] = CRGB(0, 0, 0);
}
if (counter == timing[timing_counter]) {
leds[0] = CRGB(255, 0, 0);
timing_counter++;
}
}
void check(int millis) {}
};
void calc(int& speed, int FPS, int* timing, int timing_num) {
int Frame_per_second =
1.0 * 1000 / FPS + 0.5; // 0.5足して四捨五入できてるはず。。。たぶん
speed = 1.0 * speed / Frame_per_second + 0.5;
for (int i = 0; i < timing_num; i++) {
timing[i] = 1.0 * timing[i] / Frame_per_second + 0.5;
}
}
int main() {
int speed = 500; //変更可能にする 球/ms
int LED_NUM = 20;
int FPS = 60;
int timing[] = {100, 150, 500, 1500}; //単位はms
int timing_num = 4;
calc(speed, FPS, timing,
timing_num); //ここで、単位をmsからフレーム数に変える。
Led timing_game(speed, LED_NUM, FPS, timing, timing_num);
for (int i = 0; i < 600; i++) {
if (i == 6) continue;
timing_game.draw();
// timing_game.check();
for (int i = 0; i < LED_NUM; i++) {
if (leds[i].r == 255) {
std::cout << 1;
} else {
std::cout << 0;
}
}
std::cout << std::endl;
}
}