This repository has been archived by the owner on Jul 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path5_1_Menu.ino
136 lines (120 loc) · 3.64 KB
/
5_1_Menu.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
namespace menu {
enum menu {
resumeGame,
newGame,
showBatteryOption
};
};
class Menu {
public:
u8 selection = 1;
u8 lastSelection = 1;
bool changed = true;
bool visible = true;
bool exitOption = false;
bool showBattery = false;
void update();
void draw();
void setSelection( u8 sel );
};
void Menu::setSelection( u8 sel ){
lastSelection = selection;
selection = sel;
changed = true;
};
void Menu::draw(){
char* headerText = "Kingdom Defender";
char* resumeGameText = "Resume game";
char* newGameText = "New game";
char* showBatteryText = "Show battery";
char* hideBatteryText = "Hide battery";
pocketstar.setFontColor( WHITE_16b, BLACK_16b );
pocketstar.setFont( pocketStar7pt );
pocketstar.setCursor( (WIDTH - pocketstar.getPrintWidth( headerText )) / 2, 4 );
pocketstar.print( headerText );
pocketstar.setCursor( (WIDTH - pocketstar.getPrintWidth( resumeGameText )) / 2, 22 );
pocketstar.print( resumeGameText );
pocketstar.setCursor( (WIDTH - pocketstar.getPrintWidth( newGameText )) / 2, 34 );
pocketstar.print( newGameText );
if( showBattery ) {
pocketstar.setCursor( (WIDTH - pocketstar.getPrintWidth( hideBatteryText )) / 2, 46 );
pocketstar.print( hideBatteryText );
} else {
pocketstar.setCursor( (WIDTH - pocketstar.getPrintWidth( showBatteryText )) / 2, 46 );
pocketstar.print( showBatteryText );
}
u8 x;
u8 w;
if( changed ) {
changed = false;
switch( lastSelection ) {
case menu::resumeGame:
w = pocketstar.getPrintWidth( resumeGameText );
x = (WIDTH - w) / 2;
pocketstar.drawRect( x - 1, 21, w + 3, 12, false, BLACK_16b );
break;
case menu::newGame:
w = pocketstar.getPrintWidth( newGameText );
x = (WIDTH - w) / 2;
pocketstar.drawRect( x - 1, 33, w + 3, 12, false, BLACK_16b );
break;
case menu::showBatteryOption:
w = pocketstar.getPrintWidth( showBatteryText );
x = (WIDTH - w) / 2;
pocketstar.drawRect( x - 1, 45, w + 3, 12, false, BLACK_16b );
break;
};
}
switch( selection ) {
case menu::resumeGame:
w = pocketstar.getPrintWidth( resumeGameText );
x = (WIDTH - w) / 2;
pocketstar.drawRect( x - 1, 21, w + 3, 12, false, YELLOW_16b );
break;
case menu::newGame:
w = pocketstar.getPrintWidth( newGameText );
x = (WIDTH - w) / 2;
pocketstar.drawRect( x - 1, 33, w + 3, 12, false, YELLOW_16b );
break;
case menu::showBatteryOption:
w = pocketstar.getPrintWidth( showBatteryText );
x = (WIDTH - w) / 2;
pocketstar.drawRect( x - 1, 45, w + 3, 12, false, YELLOW_16b );
break;
};
};
void Menu::update(){
if( input.get(buttons::up) ){
if( selection == menu::newGame ) {
setSelection( menu::resumeGame );
} else if( selection == menu::showBatteryOption ) {
setSelection( menu::newGame );
} else {
setSelection( menu::showBatteryOption );
}
}
else if( input.get(buttons::down) ){
if( selection == menu::resumeGame ) {
setSelection( menu::newGame );
} else if( selection == menu::newGame ) {
setSelection( menu::showBatteryOption );
} else {
setSelection( menu::resumeGame );
}
}
if( input.get(buttons::b) ){
visible = true;
}
if( input.get(buttons::a) && !exitOption ){
if( selection == menu::resumeGame) {
visible = false;
// FIXME make the game resume
} else if( selection == menu::newGame) {
visible = false;
// FIXME make a new game
} else if( selection == menu::showBatteryOption) {
showBattery = !showBattery;
}
}
};
Menu optionsMenu;