#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int buttonPin = 26;
int birdRow = 0;
int obstacleCol = 15;
int obstacleRow = 1;
bool isGamePlaying = false;
int score = 0;
void setup() {
lcd.init();
lcd.backlight();
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
if (isGamePlaying) {
lcd.clear();
lcd.noBlink();
lcd.setCursor(0, birdRow);
lcd.print(">");
lcd.setCursor(obstacleCol, obstacleRow);
lcd.print("#");
if (obstacleCol == 0 && obstacleRow == birdRow) {
isGamePlaying = false;
}
if (obstacleCol == 0) {
obstacleCol = 15;
obstacleRow = random(0, 2);
} else {
obstacleCol--;
}
birdRow = digitalRead(buttonPin) == LOW ? 0 : 1;
score++;
} else {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Play Again?");
lcd.setCursor(0, 1);
lcd.print("Score: ");
lcd.print(score);
if (digitalRead(buttonPin) == LOW) {
isGamePlaying = true;
birdRow = 0;
obstacleCol = 15;
score = 0;
delay(200);
}
}
delay(max(50, 200 - score / 5));
}