-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHighScore.h
116 lines (106 loc) · 3.19 KB
/
HighScore.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
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
#include <EEPROM.h>
#define EEPROM_SIZE 10 // Define the EEPROM size to be used
struct HighScore {
long score;
char initials[3];
};
HighScore highScore;
void saveHighScore() {
EEPROM.begin(EEPROM_SIZE);
EEPROM.put(0, highScore);
EEPROM.commit();
EEPROM.end();
}
void loadHighScore() {
EEPROM.begin(EEPROM_SIZE);
EEPROM.get(0, highScore);
EEPROM.end();
}
void getInitials() {
tft.fillScreen(TFT_BLACK);
char currentInitial = 'A';
int initialIndex = 0;
bool initialsConfirmed = false;
highScore.initials[0] = 'A';
highScore.initials[1] = 'A';
highScore.initials[2] = 'A';
while (!initialsConfirmed) {
// Clear the area where the initials are displayed
tft.fillRect(100, 120, 60, 16, TFT_BLACK); // Adjust size as necessary
// Display the initials with highlighted current initial
for (int i = 0; i < 3; i++) {
if (i == initialIndex) {
tft.setTextColor(TFT_GREEN); // Current initial
} else {
tft.setTextColor(TFT_RED); // Other initials
}
tft.setCursor(100 + i * 20, 120);
tft.print(highScore.initials[i]);
}
// Use dashButton to cycle through letters or to re-enter initials
if (digitalRead(dashButton) == LOW) {
if (initialIndex < 3) {
currentInitial++;
if (currentInitial > 'Z') currentInitial = 'A';
highScore.initials[initialIndex] = currentInitial;
} else {
// Reset initials for re-entry
initialIndex = 0;
currentInitial = 'A';
highScore.initials[0] = 'A';
highScore.initials[1] = 'A';
highScore.initials[2] = 'A';
tft.fillRect(100, 140, 240, 16, TFT_BLACK); // Clear the confirmation area
}
delay(200); // Debounce delay
}
// Use jumpButton to advance to the next slot or confirm initials
if (digitalRead(jumpButton) == LOW) {
if (initialIndex < 2) {
initialIndex++;
currentInitial = 'A';
} else if (initialIndex == 2) {
// Move to confirmation stage
initialIndex++;
tft.setTextColor(TFT_GREEN);
tft.setCursor(100, 140); // Position for confirmation message
tft.print("Jump: Confirm, Dash: Re-enter");
} else {
// Confirm initials
initialsConfirmed = true;
}
delay(200); // Debounce delay
}
delay(100); // Short delay for readability
}
}
void displayHighScore() {
drawStartScreen();
tft.setTextSize(2);
tft.setTextFont(1);
tft.setTextColor(TFT_BLACK);
tft.setCursor(40, 10);
tft.print("High Score: ");
tft.setTextSize(2);
tft.setCursor(60, 50);
tft.setTextFont(2);
tft.setTextColor(TFT_GREEN);
tft.print(highScore.score);
tft.setTextFont(1);
tft.setCursor(40, 110);
tft.setTextColor(TFT_BLACK);
tft.println("Player: ");
tft.setTextSize(2);
tft.setCursor(60, 150);
tft.setTextFont(2);
tft.setTextSize(2);
tft.setTextColor(TFT_RED);
tft.print(highScore.initials[0]);
tft.setTextColor(TFT_BLUE);
tft.print(highScore.initials[1]);
tft.setTextColor(TFT_YELLOW);
tft.print(highScore.initials[2]);
tft.setTextSize(1);
tft.setTextFont(1);
delay(1000);
}