|
1 | 1 | // By Ponticelli Domenico. |
| 2 | +// 12NOV2020 EEPROM Fix added, modified by Zontex |
2 | 3 | // https://github.com/pcelli85/M5Stack_FlappyBird_game |
3 | 4 |
|
4 | 5 | #include <M5Stack.h> |
|
27 | 28 | // grass size |
28 | 29 | #define GRASSH 4 // grass height (inside floor, starts at floor y) |
29 | 30 |
|
30 | | -int maxScore = 0; |
| 31 | +int address = 0; |
| 32 | +int maxScore = EEPROM.readInt(address); |
31 | 33 | const int buttonPin = 2; |
32 | 34 | // background |
33 | 35 | const unsigned int BCKGRDCOL = M5.Lcd.color565(138,235,244); |
@@ -92,10 +94,12 @@ static short tmpx, tmpy; |
92 | 94 |
|
93 | 95 | void setup() { |
94 | 96 | // put your setup code here, to run once: |
95 | | -M5.begin(); |
96 | | -M5.Power.begin(); |
97 | | -resetMaxScore(); |
98 | | - |
| 97 | + M5.begin(); |
| 98 | + M5.Power.begin(); |
| 99 | + EEPROM.begin(1000); |
| 100 | + //resetMaxScore(); |
| 101 | + Serial.println("last score:"); |
| 102 | + Serial.println(EEPROM.readInt(address)); |
99 | 103 | } |
100 | 104 |
|
101 | 105 | void loop() { |
@@ -323,11 +327,12 @@ void game_init() { |
323 | 327 | // --------------- |
324 | 328 | void game_over() { |
325 | 329 | M5.Lcd.fillScreen(TFT_BLACK); |
326 | | - EEPROM_Read(&maxScore,0); |
| 330 | + maxScore = EEPROM.readInt(address); |
327 | 331 |
|
328 | 332 | if(score>maxScore) |
329 | 333 | { |
330 | | - EEPROM_Write(&score,0); |
| 334 | + EEPROM.writeInt(address, score); |
| 335 | + EEPROM.commit(); |
331 | 336 | maxScore = score; |
332 | 337 | M5.Lcd.setTextColor(TFT_RED); |
333 | 338 | M5.Lcd.setTextSize(2); |
@@ -360,31 +365,7 @@ void game_over() { |
360 | 365 |
|
361 | 366 | void resetMaxScore() |
362 | 367 | { |
363 | | - EEPROM_Write(&maxScore,0); |
364 | | -} |
365 | | - |
366 | | - |
367 | | - |
368 | | -void EEPROM_Write(int *num, int MemPos) |
369 | | -{ |
370 | | - byte ByteArray[2]; |
371 | | - memcpy(ByteArray, num, 2); |
372 | | - for(int x = 0; x < 2; x++) |
373 | | - { |
374 | | - EEPROM.write((MemPos * 2) + x, ByteArray[x]); |
375 | | - } |
| 368 | + EEPROM.writeInt(address, 0); |
| 369 | + EEPROM.commit(); |
376 | 370 | } |
377 | 371 |
|
378 | | - |
379 | | - |
380 | | -void EEPROM_Read(int *num, int MemPos) |
381 | | -{ |
382 | | - byte ByteArray[2]; |
383 | | - for(int x = 0; x < 2; x++) |
384 | | - { |
385 | | - ByteArray[x] = EEPROM.read((MemPos * 2) + x); |
386 | | - } |
387 | | - memcpy(num, ByteArray, 2); |
388 | | -} |
389 | | - |
390 | | - |
0 commit comments