#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
uint8_t up_button = 17;
uint8_t dn_button = 16;
static uint8_t man_y = 1 , remove_man_y = 0 ;
void man_up_dn() {
if (digitalRead(up_button) == LOW) {
man_y = 0;
remove_man_y = 1;
}
if (digitalRead(dn_button) == LOW) {
man_y = 1;
remove_man_y = 0;
}
}
int man_run() {
byte man_0[8] = {
0b00000,
0b00100,
0b00100,
0b01110,
0b10101,
0b00100,
0b01010,
0b10001,
};
byte man_1[8] = {
0b00000,
0b00100,
0b00100,
0b01110,
0b10101,
0b00110,
0b01010,
0b10000,
};
byte man_2[8] = {
0b00000,
0b00100,
0b00100,
0b01110,
0b01110,
0b00100,
0b01010,
0b01010,
};
byte man_3[8] = {
0b00000,
0b00100,
0b00100,
0b01110,
0b01101,
0b00100,
0b11010,
0b00001,
};
lcd.createChar(0, man_0);
lcd.createChar(1, man_1);
lcd.createChar(2, man_2);
lcd.createChar(3, man_3);
for (int i = 0; i < 4; i++) {
man_up_dn();
lcd.setCursor(0, man_y);
lcd.write(i);
lcd.setCursor(0, remove_man_y);
lcd.print(" ");
delay(50);
}
}
static int random_staff_x = 10 ;
static int random_staff_y ;
static int score ;
int random_staff () {
lcd.setCursor (11 , 0 );
lcd.print("SCORE");
lcd.setCursor (13 , 1 );
lcd.print(score);
random_staff_y = random(0,2) ;
for ( random_staff_x = 9 ; random_staff_x > -1 ; random_staff_x -- ){
man_run();
lcd.setCursor (random_staff_x , random_staff_y );
lcd.print("* ");
//delay(100);
}
score ++ ;
//lcd.clear() ;
}
void game_over () {
lcd.clear();
lcd.setCursor (3 ,1);
lcd.print("GAME OVER");
delay(3000);
}
void setup() {
lcd.init();
lcd.backlight();
pinMode(up_button, INPUT_PULLUP);
pinMode(dn_button, INPUT_PULLUP);
}
void loop() {
if ( random_staff_x < 1 && random_staff_y == man_y ){
game_over();
}else {
random_staff ();
}
}