
/*****************************************************************************/
void birduino()
{
  myGLCD.clrScr();
  myGLCD.setColor(255, 255, 255);
  //  myGLCD.fillScr(210, 210, 210);
  // myGLCD.fillScr(WHITE);
  myGLCD.fillScr(BIRD_BG);


  drawTitle();
  if (exit_menu == 1)
  { exit_menu = 0;
    loop();
  }
  initiateGame(); // Initiate the game

  // myGLCD.drawBitmap (100,150, BORD_BMP_X, BORD_BMP_Y, udar);
  //delay(100);
  while (1)
  {
play:

    but();

    if (valBtnL || valBtnR || valBtnT || valBtnD)
    { valBtnL = 0;
      valBtnR = 0;
      valBtnT = 0;
      valBtnD = 0;
      if (valBtnPause == 1)
      { valBtnPause = 0;
        myGLCD.setBackColor(BIRD_BG);
        myGLCD.print("PAUSE", 275, 200); //,255,5);
        myGLCD.print("PAUSE", 100, 90); //,255,5);
        // break;
        while (1)
        { delay(1000);
          but();
          if (valBtnL || valBtnR || valBtnT || valBtnD)
          { myGLCD.setColor(BIRD_BG);
            myGLCD.fillRect(270, 180, 270 + 100, 250);
            goto pause_end;
          }
        }
      }
      else
      { tick = 0;
        fallRate = 0; // Setting the fallRate negative will make the bird jump
        fallRateInt = -10; // Setting the fallRate negative will make the bird jump скороть взлета
        screenPressed = true;
      }
    }

    if (myTouch.dataAvailable())
    {
      myTouch.read();
      xt = myTouch.getX();
      yt = myTouch.getY();
      if ((xt >= 600) && (xt <= 800)) // Upper row
      {
        if ((yt >= 130) && (yt <= 270)) // Button: 1
        { myGLCD.setColor(BIRD_BG);
          myGLCD.drawCircle(670, 200, 10);
          myGLCD.drawCircle(670, 200, 11);

          tick = 0;
          fallRate = 0; // Setting the fallRate negative will make the bird jump
          fallRateInt = -10; // Setting the fallRate negative will make the bird jump скороть взлета
          screenPressed = true;
        }
        if ((yt >= 400) && (yt <= 470)) // Button: ПАУЗА
        { myGLCD.setBackColor(BIRD_BG);
          myGLCD.setColor(255, 0, 0);
          myGLCD.print("PAUSE", 275, 200); //,255,5);
          myGLCD.setColor(VGA_GRAY);
          myGLCD.fillRect(620, 415, 720, 455);
          myGLCD.setColor(VGA_WHITE);
          myGLCD.drawRoundRect(620, 415, 720, 455);
          myGLCD.setBackColor(VGA_GRAY);
          myGLCD.setColor(255, 0, 0);
          myGLCD.print("PAUSE", 630, 428); //,255,5);
          delay(1000);
          while (1)
          {
            but();
            if (valBtnL || valBtnR || valBtnT || valBtnD)
            { myGLCD.setColor(BIRD_BG);
              myGLCD.fillRect(270, 180, 270 + 100, 220);
              goto pause_end;
            }
            if (myTouch.dataAvailable())
            { myTouch.read();
              xt = myTouch.getX();
              yt = myTouch.getY();
              if ((xt >= 600) && (xt <= 800)) // Upper row
              { if ((yt > 0) && (yt < 470))
                { myGLCD.setColor(BIRD_BG);
                  myGLCD.fillRect(270, 180, 370, 220);
                  //*** КНОПКА ПАУЗА***********
                  myGLCD.setColor(VGA_WHITE);
                  myGLCD.fillRect(620, 415, 720, 455);
                  myGLCD.setColor(VGA_GRAY);
                  myGLCD.drawRoundRect(620, 415, 720, 455);
                  myGLCD.setBackColor(VGA_WHITE);
                  myGLCD.setColor(255, 0, 0);
                  myGLCD.print("PAUSE", 630, 428); //,255,5);
                  goto pause_end;
                }
              }
            }

          }
        }

      }

    }


pause_end:
    // only do the rest when the time has come...
    crt_millis = millis();
#define TIME_UNIT 10 // game ticker, in millis  скороть движения
    if ( (crt_millis - prev_millis) < TIME_UNIT ) goto play;

    prev_millis = crt_millis;

    if ( (tick++) > 0 ) {
      fallRate = tick * tick; // Setting the fallRate negative will make the bird jump
      //  fallRate = tick*10; // Setting the fallRate negative will make the bird jump скорость падения
      //fallRateInt = int(fallRate/30);
      fallRateInt = int(fallRate / 100);
    }

    drawPilars(xP, yP); // Draws the pillars
    // delay(30);

    // yB - y coordinate of the bird which depends on value of the fallingRate variable
    yB += fallRateInt;
    // clip bird coordinates
    if ( yB > (BOTTOM_AREA_Y - BORD_BMP_Y) )
    { yB = (BOTTOM_AREA_Y - BORD_BMP_Y);
      fallRateInt = 20;
    }

    if ( yB < 0 ) yB = 0;

    // Draws the bird
    drawBird(yB);

    // Checks for collision
    // top and bottom
    //if ( yB>(BOTTOM_AREA_Y-BIRD_BMP_Y) || yB<0 )  gameOver();
    // upper or lower pillar
    if ( xP < (BIRD_X + BORD_BMP_X - 5) && xP > (BIRD_X - PILLAR_BMP_X + 5) && ( yB < (yP) || yB > (yP + PILLAR_GAP - BORD_BMP_Y) ) )
    { life = life - 1;
      if ( life < 1) {
        life = 3;
        // myGLCD.setColor(BIRD_BG);
        // myGLCD.fillRect(200, 0, 100+200, 20);
        gameOver();
      }
      else {
        hit();
      }
    }

    // After the pillar has passed through the screen
    if (xP <= -PILLAR_END_BMP_X) {
      xP += TFTHEIGHT - 150 - PILLAR_END_BMP_X; // Restart xP
      yP = map(rand() % 100, 0, 100, PILLAR_END_BMP_Y, (BOTTOM_AREA_Y - PILLAR_END_BMP_Y - PILLAR_GAP)); // Random number for the pillars height
      score++; // Increase score by one
    }
    xP -= movingRate; // xP - x coordinate of the pillars; range: 319 - (-51)
    // After each five points, increases the moving rate of the pillars
    if ((score - lastSpeedUpScore) == 5) {
      lastSpeedUpScore = score;
      level ++;
      if (level <= 30)
      { life ++;
      }
      else
      {
        if (level % 2 == 0)life ++;
      }

      movingRate = level + 2; //скорость дв пилонов

      if (level % 10 == 0)movingRate = movingRate - life / 2;
      if (movingRate > 16)movingRate = 16;

    }
    drawScore();
    myGLCD.setColor(VGA_WHITE);
    myGLCD.drawCircle(670, 200, 10);
    myGLCD.drawCircle(670, 200, 11);
    /*  myGLCD.setColor(BIRD_BG);
       myGLCD.setColor(VGA_RED);
      myGLCD.setBackColor(BIRD_BG);
      // myGLCD.setTextColor(BLACK, BIRD_BG);
       //myGLCD.setCursor(285,5);
        myGLCD.setColor(VGA_BLUE);
         myGLCD.setBackColor(BIRD_BG);
      // myGLCD.setTextColor(BLACK, BIRD_BG);
      // myGLCD.setCursor(5,5);
      //  myGLCD.print("Highscore:");//,5,5);
       myGLCD.print("Highscore:",5,5);
      // myGLCD.setCursor(130,5);
      // myGLCD.print(highscore);//, 120, 6);
       myGLCD.printNumI(highscore,130,5);
         myGLCD.setColor(VGA_RED);
         myGLCD.setBackColor(BIRD_BG);
      // myGLCD.setCursor(230,5);
      //  myGLCD.print("Life:");//,5,5);
       myGLCD.print("Life:",230,5);
        myGLCD.printNumI(life,300,5);
    */
  }// while (1)



}



void drawTitle()
{
  //myGLCD.drawBitmap((TFTHEIGHT-FLAPPY_TITLE_X)/2, (TFTWIDTH-FLAPPY_TITLE_Y)/3, FLAPPY_TITLE_X, FLAPPY_TITLE_Y, icon);

  myFiles.load(0, 0, 800, 480, "play/15.raw" , 32, 0);

  /*for (int i=0; i<640+55; i=i+10) {
    movingRate=10;
    xP=640-i;
    drawPilars(xP, yP); // Draws the pillars
    }*/

  uint32_t tim = millis();
  myGLCD.setFont(BigFont);
  myGLCD.setColor (VGA_WHITE);
  myGLCD.setBackColor(VGA_TRANSPARENT);
  myGLCD.print("TAP TO CONTINUE", CENTER, 450);

  int st = 0;
  while (st < 100) {
    delay(100);
    but();
    st++;
    if (st > 98)exit_menu = 1;
    if (valBtnL || valBtnR || valBtnT || valBtnD)
    { valBtnPause = 0;
      exit_menu = 0;
      break;
    }
    if (myTouch.dataAvailable())
    { exit_menu = 0;
      break;
    }
  }
  myGLCD.fillScr(BIRD_BG);
  //delay(5000);
}
/*****************************************************************************/
/*****************************************************************************/
void initiateGame(void)
{
  ////                                        while ( ts.getPoint(&p) ); // wait to release touch
  myGLCD.fillScr(BIRD_BG);
  // Ground
  drawGround();
  // Text
  myGLCD.setColor(VGA_BLUE);
  myGLCD.setBackColor(VGA_YELLOW);
  myGLCD.print("Score:", 5, 420);

  myGLCD.setFont(BigFont);
  // myGLCD.setTextSize(2);
  //  myGLCD.setCursor(5,220);
  //  myGLCD.print("Score:");
  //myGLCD.setTextSize(1);//SmallFont);
  //  myGLCD.setCursor(170,220);
  // myGLCD.print("Level:");//, 140, 220);
  myGLCD.setColor(VGA_BLUE);
  //    myGLCD.setBackColor(VGA_YELLOW);

  myGLCD.setBackColor(VGA_YELLOW);

  myGLCD.print("Level:", 190, 420);
  //myGLCD.setTextColor(RED, BIRD_BG);
  // myGLCD.setCursor(230,5);
  myGLCD.setColor(VGA_RED);
  myGLCD.print("Life:", 350, 420); //,5,5);
  myGLCD.printNumI(life, 440, 420); //,5,5);
  myGLCD.setColor(BIRD_BG);
  myGLCD.fillRect(200, 0, 100 + 200, 20);
  myGLCD.setBackColor(VGA_YELLOW);
  myGLCD.setColor(VGA_BLUE);
  //   myGLCD.setBackColor(BIRD_BG);
  // myGLCD.setTextColor(BLACK, BIRD_BG);
  // myGLCD.setCursor(5,5);
  //  myGLCD.print("Highscore:");//,5,5);
  myGLCD.print("Highscore:", 5, 450);
  // myGLCD.setCursor(130,5);
  // myGLCD.print(highscore);//, 120, 6);
  myGLCD.printNumI(highscore, 175, 450);
  myGLCD.setColor(VGA_RED);
  myGLCD.setBackColor(BIRD_BG);

  //****Управление тач***********
  //myGLCD.setColor(VGA_AQUA);
  myGLCD.setColor(204, 244, 255);
  myGLCD.fillRect(605, 5, 735, 475);
  myGLCD.setColor(VGA_WHITE);
  myGLCD.drawRoundRect(605, 5, 735, 475);
  //***КРУГЛАЯ КНОПКА***********
  myGLCD.setColor(GRAY);
  myGLCD.fillCircle(670, 200, 50);
  myGLCD.setColor(VGA_WHITE);
  myGLCD.fillCircle(670, 200, 48);
  //*** КНОПКА ПАУЗА***********
  myGLCD.setColor(VGA_WHITE);
  myGLCD.fillRect(620, 415, 720, 455);
  myGLCD.setColor(VGA_GRAY);
  myGLCD.drawRoundRect(620, 415, 720, 455);

  myGLCD.setBackColor(VGA_WHITE);
  myGLCD.setColor(255, 0, 0);
  myGLCD.print("PAUSE", 630, 428); //,255,5);
  // myGLCD.setCursor(230,5);
  //  myGLCD.print("Life:");//,5,5);
  // myGLCD.print("Life:",230,5);
  // myGLCD.printNumI(life,300,5);
  // myGLCD.setCursor(285,5);
  // myGLCD.print(life);//, 120, 6);
  //  myGLCD.setCursor(255,5);
  //  myGLCD.print("| RESET |");//,255,5);

  // Resets the variables to start position values
  xP = TFTWIDTH;//TFTHEIGHT;
  yB = 100;
  fallRate = 0;
  fallRateInt = 0;
  score = 0;
  level = 0;
  lastSpeedUpScore = 0;
  movingRate = MOV_RATE_X0;
  //screenPressed = -1;
  screenPressed = false;
  gameStarted = false;
  paused = false;
  steps = 0;
  tick = 0;

  drawBird(yB); // Draws the bird
  drawScore();
  // write tap to start
  // myGLCD.drawFastHLine(0,23,TFTHEIGHT, BLACK);
  myGLCD.setColor(VGA_BLACK);
  myGLCD.drawLine(0, 23, TFTHEIGHT - 200, 23); //V
  // myGLCD.setTextSize(1);
  // myGLCD.setTextColor(BLACK, BIRD_BG);


  while (!gameStarted) {
    uint32_t tim = millis();
    myGLCD.setColor(VGA_BLUE);
    myGLCD.print("TAP TO START", 250, 200);
    // myGLCD.setCursor(TEXT_POSITION_CENTER,100);
    // myGLCD.print("TAP TO START");//,CENTER,100);

    myGLCD.setBackColor(BIRD_BG);
    // myGLCD.fillRect(TEXT_POSITION_CENTER, 100, 100+TEXT_POSITION_CENTER, 10+100); // clear text
    tim = millis();

    while ((millis() - tim) < 500)
    { but();

      if (valBtnL || valBtnR || valBtnT || valBtnD)
      { valBtnPause = 0;
        gameStarted = true;
        break;
      }
      if (myTouch.dataAvailable())
      { gameStarted = true;
        break;
      }

    }
  }


  myGLCD.setColor(BIRD_BG);
  myGLCD.fillRect(250, 150, 400, 250); // clear text
  // myGLCD.fillRect(TEXT_POSITION_CENTER, 100, 100, 10, BIRD_BG); // clear text
  myGLCD.fillRect(0, 0, TFTHEIGHT - 200, BOTTOM_AREA_Y); // delete top status row, leave room for the game
  delay(10); // wait touch end
}
/*****************************************************************************/
void drawGroundDeco(void)//земля узоры
{
  //int offs = xP<0 ? (-xP)%12 : xP%12; // template repetition length = 12
  int offs = (steps += movingRate) % 12; // template repetition length = 12
  // draw 6 lines of deco
  myGLCD.drawBitmap(0, BOTTOM_AREA_Y + 2, TFTHEIGHT - 200, 1, bottom_deco + ((offs++) % 12));
  myGLCD.drawBitmap(0, BOTTOM_AREA_Y + 3, TFTHEIGHT - 200, 1, bottom_deco + ((offs++) % 12));
  myGLCD.drawBitmap(0, BOTTOM_AREA_Y + 4, TFTHEIGHT - 200, 1, bottom_deco + ((offs++) % 12));
  myGLCD.drawBitmap(0, BOTTOM_AREA_Y + 5, TFTHEIGHT - 200, 1, bottom_deco + ((offs++) % 12));
  myGLCD.drawBitmap(0, BOTTOM_AREA_Y + 6, TFTHEIGHT - 200, 1, bottom_deco + ((offs++) % 12));
  myGLCD.drawBitmap(0, BOTTOM_AREA_Y + 7, TFTHEIGHT - 200, 1, bottom_deco + ((offs++) % 12));
}
/*****************************************************************************/
// ===== drawPlillars - Custom Function
/*****************************************************************************/
void drawPilars(int x, int y)// препятствия
{
  int c = 0;
  //x = 250; // test
  //sprintf(s, "drawPillars x: %3i, y: %3i\n", x, y); Serial.print(s);

  // clip y coordinates:
  if ( y < PILLAR_END_BMP_Y ) y = PILLAR_END_BMP_Y;
  if ( y > (BOTTOM_AREA_Y - PILLAR_GAP - PILLAR_END_BMP_Y) ) y = (BOTTOM_AREA_Y - PILLAR_GAP - PILLAR_END_BMP_Y);

  // draw pillar body till (y-PILLAR_END_BMP_Y)
  for (int i = 0; i < PILLAR_BMP_X; i++) {
    if (x + i < 0) {
      myGLCD.setColor(BIRD_BG);
      // myGLCD.setColor(VGA_AQUA);
    }
    else
    { myGLCD.setColor(pillar[i]);
    }
    myGLCD.drawLine(x + i, 0, x + i, (y - PILLAR_END_BMP_Y)); //V
    //  myGLCD.drawLine(x+c+1, 0,x+c+1, (y-PILLAR_END_BMP_Y));//V
    c = c + 1;

  }
  // draw pillar end
  if (x > 0) myGLCD.drawBitmap(x, y - PILLAR_END_BMP_Y, (int)PILLAR_END_BMP_X, (int)PILLAR_END_BMP_Y, pillar_end);



  myGLCD.setColor(BIRD_BG);
  myGLCD.fillRect(x + PILLAR_END_BMP_X, 0, x + PILLAR_END_BMP_X + movingRate, y);

  // now draw lower pillar. First the pillar end
  if (x > 0) myGLCD.drawBitmap(x, y + PILLAR_GAP, (int)PILLAR_END_BMP_X, (int)PILLAR_END_BMP_Y, pillar_end);
  // then the body
  c = 0;

  for (int j = 0; j < PILLAR_BMP_X; j++) {
    if (x + j < 0) {
      myGLCD.setColor(BIRD_BG);
      //myGLCD.setColor(VGA_AQUA);
    }
    else
    { myGLCD.setColor(pillar[j]);
    }
    myGLCD.drawLine(x + j, y + PILLAR_GAP + PILLAR_END_BMP_Y, x + j, y + PILLAR_GAP + PILLAR_END_BMP_Y + (BOTTOM_AREA_Y - y - PILLAR_GAP - PILLAR_END_BMP_Y)); //V
    // myGLCD.drawLine(x+c+1, y+PILLAR_GAP+PILLAR_END_BMP_Y,x+c+1, y+PILLAR_GAP+PILLAR_END_BMP_Y+ (BOTTOM_AREA_Y-y-PILLAR_GAP-PILLAR_END_BMP_Y));//V
    c = c + 1;
    // myGLCD.drawBitmap(x, j, (int)PILLAR_BMP_X, (int)PILLAR_BMP_Y, pillar);
  }
  // delete old columns
  myGLCD.setColor(BIRD_BG);
  myGLCD.fillRect(x + PILLAR_END_BMP_X, y + PILLAR_GAP, x + PILLAR_END_BMP_X + movingRate, y + PILLAR_GAP + BOTTOM_AREA_Y - (y + PILLAR_GAP));


  drawGroundDeco();
}

/*****************************************************************************/
void drawGround(void)//земля желтая
{
  //myGLCD.fillRect(0, BOTTOM_AREA_Y, TFTHEIGHT, 10, color565(47,175,68));
  // myGLCD.drawFastHLine(0, BOTTOM_AREA_Y, TFTHEIGHT, BLACK);
  myGLCD.setColor(VGA_BLACK);
  myGLCD.drawLine(0, BOTTOM_AREA_Y, TFTHEIGHT - 200, BOTTOM_AREA_Y);
  myGLCD.setColor((int)bottom_deco[0]);
  myGLCD.setColor(VGA_YELLOW);
  // myGLCD.drawFastHLine(0, BOTTOM_AREA_Y+1, TFTHEIGHT, (int)bottom_deco[0]); // the light green
  myGLCD.drawLine(0, BOTTOM_AREA_Y + 1, TFTHEIGHT - 200, BOTTOM_AREA_Y + 1);
  drawGroundDeco();
  myGLCD.setColor((int)bottom_deco[6]);
  //myGLCD.drawFastHLine(0, BOTTOM_AREA_Y+8, TFTHEIGHT, (int)bottom_deco[6]); // the dark green
  myGLCD.drawLine(0, BOTTOM_AREA_Y + 8, TFTHEIGHT - 200, BOTTOM_AREA_Y + 8);
  myGLCD.setColor((int)bottom_deco[0]);
  // myGLCD.drawFastHLine(0, BOTTOM_AREA_Y+9, TFTHEIGHT, (int)bottom_deco[0]);
  myGLCD.drawLine(0, BOTTOM_AREA_Y + 9, TFTHEIGHT - 200, BOTTOM_AREA_Y + 9);
  // text area
  // myGLCD.setColor(221,216,148);
  myGLCD.setColor(VGA_YELLOW);
  myGLCD.fillRect(0, BOTTOM_AREA_Y + 10, TFTHEIGHT - 200, TFTWIDTH);
}
/*****************************************************************************/
/*****************************************************************************/
void drawScore(void)//счет
{ // Draws the score
  myGLCD.setFont(BigFont);
  // myGLCD.setTextSize(2);
  myGLCD.setColor(VGA_BLUE);
  myGLCD.setBackColor(VGA_YELLOW);
  // myGLCD.setTextColor(BLACK, myGLCD.color565(221, 216, 148));
  // myGLCD.setCursor(90, 220);
  // myGLCD.print(score);
  myGLCD.printNumI(score, 100, 420);
  //myGLCD.setCursor(260, 220);
  // myGLCD.print(level+1);
  myGLCD.printNumI(level + 1, 290, 420);
  myGLCD.setColor(VGA_RED);
  myGLCD.printNumI(life, 440, 420); //,5,5);
}
/*****************************************************************************/
//====== drawBird() - Custom Function
/*****************************************************************************/
void drawBird(int y)// герой ПТИЧКА
{
  // delete previous bird
  //myGLCD.fillRect(BIRD_X, y-fallRateInt, BIRD_BMP_X, BIRD_BMP_Y, BIRD_BG);
  // Draws the new bird bitmap
  // Serial.println (y);
  //  Serial.println (fallRateInt);
  myGLCD.drawBitmap (BIRD_X, y, BORD_BMP_X, BORD_BMP_Y, bord);
  /**/
  // Draws blue rectangles above and below the bird to clear its previous state
  if (fallRateInt > 0) {
    myGLCD.setColor(BIRD_BG);
    //  myGLCD.setColor(VGA_RED);
    //   myGLCD.fillRect(BIRD_X, y-fallRateInt, BIRD_BMP_X, fallRateInt, BIRD_BG);
    myGLCD.fillRect(BIRD_X, y - fallRateInt, BORD_BMP_X + BIRD_X, y);
    // myGLCD.fillRect(BIRD_X, y-fallRateInt, BORD_BMP_X+BIRD_X, y-fallRateInt+BORD_BMP_Y);

  } else if (fallRateInt < 0) {
    //Serial.println("bird up");
    myGLCD.setColor(BIRD_BG);
    //  myGLCD.setColor(VGA_RED);
    myGLCD.fillRect(BIRD_X, y + BORD_BMP_Y, BORD_BMP_X + BIRD_X, y + BORD_BMP_Y - fallRateInt);
  }

}
//****************Удар*************************************************************************************
void hit(void)//столкновение
{

  for (int i = 0; i < 20; i++) {
    if (i & 1)
    { myGLCD.drawBitmap (50, yB, BORD_BMP_X, BORD_BMP_Y, udar);
    }
    else
    { myGLCD.drawBitmap (50, yB, BORD_BMP_X, BORD_BMP_Y, bord);
    }

    delay(100);
  }
  delay(1000);

  xP = -PILLAR_END_BMP_X;
  myGLCD.setColor(BIRD_BG);
  myGLCD.fillRect(0, 0, 500, BOTTOM_AREA_Y);
  myGLCD.setBackColor(VGA_YELLOW);
  myGLCD.setColor(VGA_RED);

  //myGLCD.setTextColor(RED, BIRD_BG);
  // myGLCD.setCursor(230,5);
  //  myGLCD.print("Life:",230,420);//,5,5);
  // myGLCD.setCursor(285,5);
  myGLCD.printNumI(life, 440, 420); //, 120, 6);
  if (level > 3)movingRate = 1 + level / 2; //скорость дв пилонов
  if (movingRate > 12)movingRate = 12;
  score = score - 1;
  delay(2000);
}

/*****************************************************************************/
/*****************************************************************************/
//======== gameOver() - Custom Function
/*****************************************************************************/
void gameOver(void)
{
  // blink display

  for (int i = 0; i < 10; i++) {
    if (i & 1)
    { myGLCD.setColor(WHITE);

    }
    else myGLCD.setColor(RED);
    myGLCD.fillRect(0, 0, TFTHEIGHT - 200, BOTTOM_AREA_Y);
  }
  delay(500); // 1 second
  myGLCD.setColor(RED);
  myGLCD.setBackColor(WHITE);
  // myGLCD.setCursor(150,50);
  // myGLCD.setTextSize(3);
  // myGLCD.setTextColor(BLACK);//, BIRD_BG);
  myGLCD.setFont(Ubuntubold);
  myGLCD.print("GAME", 250, 150);
  myGLCD.print("OVER!", 250, 250);

  delay(1000);
  myGLCD.setFont(BigFont);
  myGLCD.setColor(VGA_BLUE);
  myGLCD.print("TAP TO CONTINUE", 200, 360);
  myGLCD.setFont(Ubuntubold);
  boolean t = false;
  while ( !t ) {
    myGLCD.setColor(RED);
    myGLCD.setBackColor(WHITE);
    myGLCD.print("GAME", 250, 150);
    myGLCD.print("OVER!", 250, 250);
    uint32_t tim = millis();

    if (score > highscore) {
      highscore = score;
      //EEPROM.write(0,highscore);
      myGLCD.setBackColor(VGA_YELLOW);
      myGLCD.setColor(VGA_BLUE);
      myGLCD.printNumI(highscore, 175, 450);
    }
    int tim1 = 0  ;
    while (tim1 < 100 || !t ) {
      delay(300);
      tim1++;
      if (myTouch.dataAvailable())
      { myTouch.read();
        xt = myTouch.getX();
        yt = myTouch.getY();
        Serial.print(" x = ");
        Serial.print(xt);
        Serial.print(", y = ");
        Serial.println(yt);
        if (xt > 10) {
          if ( yt > 10)t = true;
        }

      }
      myGLCD.setBackColor(RED);
      myGLCD.setColor(WHITE);
      myGLCD.print("GAME", 250, 150);
      myGLCD.print("OVER!", 250, 250);
    }
  }
  myGLCD.setColor(BIRD_BG);
  myGLCD.fillRect(0, 0, 600, BOTTOM_AREA_Y);

  myGLCD.setFont(BigFont);

  delay(1000);
  ////                                                 while( ts.getPoint(&p) ); // wait for touch release
  // Writes the highest score in the EEPROM

  // Restart game
  birduino();
}
