   int AyA = ballY - (ballRadius-1);  // of the hitbox will go outside of floaty's
   int AyB = ballY + (ballRadius-1);  // drawing
   int BxA, BxB, ByA, ByB;
-	
+  
   // check top cylinder
   BxA = pipes[0][x];
   BxB = pipes[0][x] + pipeWidth;
   ByA = 0;
   ByB = pipes[1][x];
   if (AxA < BxB && AxB > BxA && AyA < ByB && AyB > ByA) { return true; } // Collided with top pipe
-	
+  
   // check top cap
   BxA = pipes[0][x] - pipeCapWidth;
   BxB = BxA + pipeWidth + (pipeCapWidth*2);
   ByA = pipes[1][x] - pipeCapHeight;
   if (AxA < BxB && AxB > BxA && AyA < ByB && AyB > ByA) { return true; } // Collided with top cap
-	
+  
   // check bottom cyllinder
   BxA = pipes[0][x];
   BxB = pipes[0][x] + pipeWidth;
   ByA = pipes[1][x] + pipeGapHeight;
   ByB = HEIGHT-1;
   if (AxA < BxB && AxB > BxA && AyA < ByB && AyB > ByA) { return true; } // Collided with bottom pipe
-	
+  
   // check bottom cap
   BxA = pipes[0][x] - pipeCapWidth;
   BxB = BxA + pipeWidth + (pipeCapWidth*2);

  arduboy.print("Press Any Button");
  arduboy.display();

  while (!arduboy.getInput());

  delay(500);
  for (int x = 0; x < pipeArraySize; x++) { pipes[0][x] = 255; }  // set all pipes offscreen
  lTime = millis();
}
void loop() {
  if (millis() > lTime + gameFPS) {
    arduboy.clear();
    lTime = millis();
    if (gameState == 0) {       // If the game is paused
      drawFloor();
      drawFloaty();
      if (arduboy.getInput()) { // Wait for a button press
        gameState = 1;          // Then start the game
        ballVY = jumpHeight;    // And make Floaty jump
        if (arduboy.tunes.playing()) { arduboy.tunes.stopScore(); }
        arduboy.tunes.playScore (flap);
      }
    }
    if (gameState == 1) {       // If the game is playing
      pipeGenCount++;           // inc pipe generator counter 1 frame
      if (ballVY > 0) {         // If the ball isn't already rising, check for jump
        if (arduboy.pressed(B_BUTTON) || arduboy.pressed(A_BUTTON)) {
          ballVY = jumpHeight;  // jump
          if (arduboy.tunes.playing()) { arduboy.tunes.stopScore(); }
          arduboy.tunes.playScore (flap);
        }
      }
      if (pipeGenCount > pipeGenTimer) {  // Every pipeGenTimer worth of frames
        generatePipe();                   // Generate a pipe
        pipeGenCount = 0;                 // Reset the generator counter
      }
      ballY = ballY + ballVY;             // Move the ball according to ballVY
      if (ballY < ballRadius) { ballY = ballRadius; } // No clipping the top
      ballVY++;                           // Decrement VY
      for (int x = 0; x < pipeArraySize; x++) {  // For each pipe array element
        if (pipes[0][x] != 255) {         // If the x value isn't 255
          pipes[0][x] = pipes[0][x] - 2;  // Then move it left 2px
          if (pipes[0][x] + pipeWidth < 0) {  // If the pipe's right edge is off screen
          pipes[0][x] = 255;              // Then set its value to 255
        }
          if (pipes[0][x] + pipeWidth == (ballX-ballRadius)) {  // If the pipe passed Floaty
            gameScore++;                  // And increment the score
            gameScoreX = ballX;           // Load up the floating text with
            gameScoreY = ballY - ballRadius; // Current ball x/y values
            gameScoreRiser = 15;          // And set it for 15 frames
            if (arduboy.tunes.playing()) { arduboy.tunes.stopScore(); }
            arduboy.tunes.playScore (point);
          }
        }
      }

      if (gameScoreRiser > 0) {  // If we have floating text
        arduboy.setCursor(gameScoreX - 2,gameScoreY + gameScoreRiser - 24);
        arduboy.print(gameScore);								
        gameScoreX = gameScoreX - 2;
        gameScoreRiser--;
      }

      if (ballY + ballRadius > (HEIGHT-1)) {  // If the ball has fallen below the screen
        ballY = (HEIGHT-1) - ballRadius;      // Don't let the ball go under :O
        gameState = 2;                        // Game over. State is 2.
      }
      // Collision checking
      for (int x = 0; x < pipeArraySize; x++) { // For each pipe array element
        if (pipes[0][x] != 255) {               // If the pipe is active (not 255)
          if (checkPipe(x)) { gameState = 2; }  // If the check is true, game over
        }
      }

      drawPipes();
      drawFloor();
      drawFloaty();

    }
    if (gameState == 2) {  // If the gameState is 2 then we draw a Game Over screen w/ score
      if (gameScore > gameHighScore) { gameHighScore = gameScore; }
      if (arduboy.tunes.playing()) { arduboy.tunes.stopScore(); }
      arduboy.display();              // Make sure final frame is drawn
      arduboy.tunes.playScore (hit);  // Hit sound
      delay(100);                     // Pause for the sound
      while (ballY + ballRadius < (HEIGHT-1)) {  // While floaty is still airborne
      if (ballVY < 0) { ballVY = 0; } // Stop any upward momentum
        ballY = ballY + ballVY;       // Fall
        ballVY++;                     // Increase falling speed
        if (ballY + ballRadius > (HEIGHT-1)) { ballY = HEIGHT - ballRadius; } // Don't fall through the floor plx
        arduboy.clear();
        drawPipes();
        drawFloor();
        drawFloaty();
        arduboy.display();
      }
      arduboy.tunes.playScore (horns);     // SOUND THE LOSER'S HORN	
      arduboy.drawRect(16,8,96,48, WHITE); // Box border
      arduboy.fillRect(17,9,94,46, BLACK); // Black out the inside
      arduboy.drawSlowXYBitmap(30,12,gameover,72,14,1);
      arduboy.setCursor(56 - getOffset(gameScore),30);
      arduboy.print(gameScore);
      arduboy.setCursor(69,30);
      arduboy.print("Score");

      arduboy.setCursor(56 - getOffset(gameHighScore),42);
      arduboy.print(gameHighScore);
      arduboy.setCursor(69,42);
      arduboy.print("High");

      arduboy.display();

      while (!arduboy.getInput());

      gameState = 0;       // Then start the game paused
      gameScore = 0;       // Reset score to 0
      gameScoreRiser = 0;  // Clear the floating score
      for (int x = 0; x < pipeArraySize; x++) { pipes[0][x] = 255; }	// set all pipes inactive
      ballY = 32;          // Reset ball to center
      ballVY = 0;          // With zero lift
      delay(250);          // Slight delay so input doesn't break pause

    }
    arduboy.display();  // Finally draw this thang
  }
}

int gameHighScore = 0;
int pipeGenCount = 0;  // Frame counter to generate new pipes
int ballVY = 0;


// Sounds
