-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStateChanger.h
81 lines (72 loc) · 2.04 KB
/
StateChanger.h
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
/**
* StateChanger.h - Areas of concern: Handles interrupts that change the game state
*/
void joystickButtonClick() {
volatile int curTime = millis();
if (curTime - lastDebounceTime < DEBOUNCE_DELAY) {
return;
}
lastDebounceTime = curTime;
shouldRedrawMenu = true;
switch (systemState) {
case SYSTEM_STATE_MENU:
setMatrixImage(menuMatrixSymbol);
switch (selectedItem) {
case 0:
systemState = SYSTEM_STATE_GAME;
break;
case 1:
setMatrixImage(settingsMatrixSymbol);
systemState = SYSTEM_STATE_MENU_SETTINGS;
isEditingSetting = false;
break;
case 2:
setMatrixImage(highscoreMatrixSymbol);
systemState = SYSTEM_STATE_MENU_HIGHSCORES;
break;
case 3:
setMatrixImage(aboutMatrixSymbol);
systemState = SYSTEM_STATE_MENU_ABOUT;
break;
}
selectedItem = 0;
return;
case SYSTEM_STATE_MENU_ABOUT:
setMatrixImage(menuMatrixSymbol);
systemState = SYSTEM_STATE_MENU;
return;
case SYSTEM_STATE_MENU_HIGHSCORES:
setMatrixImage(menuMatrixSymbol);
systemState = SYSTEM_STATE_MENU;
return;
case SYSTEM_STATE_MENU_SETTINGS:
doSettingsAction();
return;
case SYSTEM_STATE_NAME_EDIT:
if (index == 5) {
saveSettings();
index = 0;
systemState = SYSTEM_STATE_MENU_SETTINGS;
}
if (nameEditState == SYSTEM_STATE_NAME_EDIT_UNLOCKED) {
nameEditState = SYSTEM_STATE_NAME_EDIT_LOCKED;
} else {
nameEditState = SYSTEM_STATE_NAME_EDIT_UNLOCKED;
}
shouldRedrawNameEdit = true;
return;
case SYSTEM_STATE_GAME:
if (isPowerupAvailable == false) {
return;
}
isPowerupAvailable = false;
isPowerupActive = true;
powerupStartTime = millis();
return;
case SYSTEM_STATE_GAME_END:
setMatrixImage(menuMatrixSymbol);
gameState = SYSTEM_STATE_GAME_SETUP;
systemState = SYSTEM_STATE_MENU;
return;
}
}