 
 void resetMaxScore()
 {
-  EEPROM_Write(&maxScore,0);
-}
-
-
-
-void EEPROM_Write(int *num, int MemPos)
-{
- byte ByteArray[2];
- memcpy(ByteArray, num, 2);
- for(int x = 0; x < 2; x++)
- {
-   EEPROM.write((MemPos * 2) + x, ByteArray[x]);
- }  
-}
-
-
-
-void EEPROM_Read(int *num, int MemPos)
-{
- byte ByteArray[2];
- for(int x = 0; x < 2; x++)
- {
-   ByteArray[x] = EEPROM.read((MemPos * 2) + x);    
- }
- memcpy(num, ByteArray, 2);
-}
-
-
+  EEPROM.writeInt(address, 0);
+  EEPROM.commit();
+}
+

// ---------------
void game_over() {
  M5.Lcd.fillScreen(TFT_BLACK);
  EEPROM_Read(&maxScore,0);
  
  if(score>maxScore)
  {
    EEPROM_Write(&score,0);
    maxScore = score;
    M5.Lcd.setTextColor(TFT_RED);
    M5.Lcd.setTextSize(2); 

// By Ponticelli Domenico.
// 12NOV2020 EEPROM Fix added, modified by Zontex
// https://github.com/pcelli85/M5Stack_FlappyBird_game

#include <M5Stack.h>
