forked from sinibida/galaga
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgalaga.ino
89 lines (81 loc) · 1.79 KB
/
galaga.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
#include "graphic.h" //에러 아님
#include "sound.h"
#include "io.h"
#include "structs.h"
#include "constants.h"
#include "game.h"
void setup() {
graphic::init();
sound::init();
io::init();
randomSeed(analogRead(0));
// 디버그용
// Serial.begin(9600);
}
int state = STATE_START;
void restartGame() {
state = STATE_GAME;
resetGame();
}
#define DT 33
void loop() {
sound::soundLoop();
switch(state) { // state 0, 1, 2, 3 값에 따라 상황 전환
case STATE_START: // 시작화면
{
graphic::drawStartMenu();
if (io::getShoot()) {
graphic::clear();
restartGame();
}
if (io::getRight())
{
graphic::clear();
state = STATE_SCORE;
}
delay(DT);
}
break;
case STATE_GAME: // 게임 중
{
int result = gameLoop();
if (result != STATE_GAME) {
graphic::clear();
state = result;
}
}
break;
case STATE_GAME_OVER: // 게임 종료
graphic::drawGameOver();
if (io::getRight()) {
graphic::clear();
state = STATE_START;
}
if (io::getShoot()) {
graphic::clear();
restartGame();
}
delay(DT);
break;
case STATE_CLEAR: // 클리어
graphic::drawClear();
if (io::getRight()) {
graphic::clear();
state = STATE_START;
}
if (io::getShoot()) {
graphic::clear();
restartGame();
}
delay(DT);
break;
case STATE_SCORE: // 점수화면
graphic::drawScoreBoard();
delay(DT);
if (io::getRight()) {
graphic::clear();
state = STATE_START;
}
break;
}
}