#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
int redPin = 6;
int bluePin = 5;
bool alive = true;
int playerSprite = 0;
int playerPos = 0;
int pipeDelay = 0;
int pipeTop = 1;
int pipeBottom = 2;
int gameSpeed = 400;
int pipeRandom;
int pos1x = 0;
int pos2x = 0;
int pos3x = 0;
int pos4x = 0;
int pos1y = 0;
int pos2y = 0;
int pos3y = 0;
int pos4y = 0;
//bird sprite
byte player[8] = {
B00000,
B11100,
B00010,
B01001,
B00010,
B00010,
B11100,
B00000,
};
byte pipe1[8] = {
B01110,
B01110,
B01110,
B01110,
B01110,
B01110,
B01110,
B11111,
};
byte pipe2[8] = {
B11111,
B01110,
B01110,
B01110,
B01110,
B01110,
B01110,
B01110,
};
void setup() {
nChar(0, player);
nChar(1, pipe1);
nChar(2, pipe2);
//prints the credit screen and moves onto the main loop
lcd.begin(16, 2);
lcd.print("Flappy Bird");
delay(1500);
lcd.clear();
cur(0, 0);
lcd.print("Designed by");
cur(0, 1);
lcd.print("Thea");
delay(1500);
}
void loop() {
//title screen
lcd.clear();
cur(0, 0);
lcd.print("Press Red");
cur(0, 1);
lcd.print("To Start");
cur(9, 1);
lcdWrite(playerSprite);
//sets the button state for the buttonWait function to 0 to make the game fully loop
int buttonState = 0;
buttonWait(redPin);
lcd.clear();
cur(8, 0);
lcd.print("3");
countdownSec(8, 0);
lcd.print("2");
countdownSec(8, 0);
lcd.print("1");
countdownSec(7, 0);
lcd.print("GO!");
lcdWrite(0);
delay(1000);
lcd.clear();
cur(7, playerPos);
lcdWrite(0);
while (alive == true) { //main game loop
if (digitalRead(redPin) = HIGH) {
playerPos = 0;
}
if (digitalRead(bluePin) = HIGH) {
playerPos = 1;
}
pipeRandom = random(0, 1);
pipeDelay++;
delay(30);
} //end of game loop
}
void buttonWait(int buttonPin){
//function mainly for the title screen
int buttonState = 0;
while(1){
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
return;
}
}
}
void countdownSec(int a, int b) {
//function to make the counting down animations more compact and readable
delay(1000);
lcd.clear();
lcd.setCursor(a, b);
}
void nChar(int num, int charByte) {
//function to make registering custom characters easier
lcd.createChar(num, charByte);
}
void lcdWrite(int num) {
lcd.write(byte(num));
}
void cur(int x, int y) {
lcd.setCursor(x, y);
}
// void checkPipeAvailable(int pipeNumx, int pipeNumy) {
// int randomPos = random(0, 1);
// if (pipeNumx == -15) {
// pipeNumx = 0;
// pipeNumy = randomPos;
// cur((pipeNumx + 16), pipeNumy);
// }
// if (pipeNumy == 0) {
// cur((pipeNumx + 16), pipeNumy);
// lcdWrite(1);
// }
// else {
// cur((pipeNumx + 16), pipeNumy);
// lcdWrite(2);
// }
// }