-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgameManager.ino
103 lines (81 loc) · 2.41 KB
/
gameManager.ino
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
99
100
101
102
103
#include <Arduino.h>
// void led_begin(byte pin) ←led関係の処理を初期化
// void led_start(double speed) ← ledに光を流すのを始める
// void led_stop()
// void led_loop() ←ledの現在位置を計算し、前と変化していたらテープを更新する
// int led_getPosition() ←現在の光の位置
// void led_reset()
#define LED_PIN 3
#define BUTTON_PIN 4
#define TONE_PIN 5
void gameSetup() {
led_begin();
pinMode(BUTTON_PIN, INPUT_PULLUP);
}
int gameManager() {
const double speedPlus = 8;
const double startSpeed = 10;
const int stopLinePosition = 50;
const int rangeMax = 2;
const int rangeMin = -2;
double speed = startSpeed;
const byte pointPlus = 10;
int point = 0;
byte counter = 1;
const byte countMax = 10;
while (counter <= countMax) {
led_reset();
led_turnon_yellow(stopLinePosition - 1);
led_turnon_yellow(stopLinePosition);
led_turnon_yellow(stopLinePosition + 1);
Serial.print(counter);
Serial.println("回目");
player.playMp3Folder(counter);
delay(1500);
tone(TONE_PIN, 1000, 500);
delay(1000);
tone(TONE_PIN, 1000, 500);
delay(1000);
player.playMp3Folder(13);
Serial.println("Start!");
delay(1900);
led_start(speed);
while (led_getPosition() <= NUM_LEDS - 1) {
led_loop();
bool isPushed = !digitalRead(BUTTON_PIN);
tone(TONE_PIN, 1000, 10);
if (!isPushed) continue;
led_stop();
break;
}
delay(500);
int position = led_getPosition();
int difference = position - stopLinePosition;
if (difference < rangeMin || rangeMax < difference) {
Serial.println("ストップ失敗!");
player.playMp3Folder(17);
delay(1500);
player.playMp3Folder(15);
delay(1600);
break;
}
Serial.println("ストップ成功!");
player.playMp3Folder(16);
point += pointPlus + rangeMax - abs(difference);
Serial.print("判定点からの差: ");
Serial.println(difference);
Serial.print("現在のポイント: ");
Serial.println(point);
counter++;
speed += speedPlus;
if (counter > 10) {
player.playMp3Folder(11);
delay(1000);
}
delay(1000);
}
Serial.println("ゲーム終了");
Serial.println("獲得ポイント: ");
Serial.println(point);
return point;
}