#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int buttonPin = 9;
byte dino_part1[8] = {
0b01110,
0b11011,
0b11111,
0b11100,
0b11111,
0b11100,
0b11000,
0b10000
};
byte dino_part2[8] = {
0b01100,
0b11000,
0b11000,
0b11111,
0b11111,
0b01111,
0b00111,
0b00010
};
byte cactus[8] = {
0b00100,
0b01110,
0b11110,
0b01110,
0b01110,
0b01111,
0b01110,
0b01110
};
int dino_x = 1;
int dino_y = 1;
int cactus_x = 15;
bool gameOver = false;
bool isJumping = false;
unsigned long jumpStartTime;
const unsigned long jumpDuration = 300;
void setup() {
lcd.begin(16, 2);
pinMode(buttonPin, INPUT);
lcd.createChar(0, dino_part1);
lcd.createChar(1, dino_part2);
lcd.createChar(2, cactus);
}
void loop() {
if (!gameOver) {
if (digitalRead(buttonPin) == HIGH && !isJumping){
isJumping = true;
jumpStartTime = millis();
}
if (isJumping) {
unsigned long elapsedTime = millis() - jumpStartTime;
if (elapsedTime < jumpDuration / 2) {
dino_y = 0;
} else if (elapsedTime < jumpDuration) {
dino_y = 1;
} else {
isJumping = false;
}
} else {
dino_y = 1;
}
lcd.clear();
lcd.setCursor(dino_x, dino_y);
lcd.write((byte)0);
lcd.setCursor(dino_x - 1, dino_y);
lcd.write((byte)1);
lcd.setCursor(cactus_x, 1);
lcd.write((byte)2);
if (cactus_x == dino_x && dino_y == 1) {
gameOver = true;
}
cactus_x--;
if (cactus_x < 0) {
cactus_x = 15;
}
delay(25);
} else {
lcd.setCursor(0, 0);
lcd.print("Game Over!");
lcd.setCursor(0, 1);
lcd.print("Press reset");
}
}