Good day,
i want my Player named smiley only jump for about 3 secs and then stop jumping this game is like
the t-rex game from google chrome but in my code you can hold the button and just "fly" over everything.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//I2C pins declaration
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
int Button = 0;
int Game = 1;
double Nahe = 16.0;
int wait = 150;
int xpos = 2;
int ypos = 1;
int score = 0;
int Press = 0;
byte smiley[8] = {
B00100,
B01010,
B00100,
B01110,
B10101,
B00100,
B01010
};
byte baum[8] = {
B01110,
B01110,
B01110,
B00100,
B00100,
B00100,
B01110
};
void setup() {
lcd.clear();
lcd.begin(16,2);
lcd.createChar(0, smiley);
lcd.createChar(1, baum);
pinMode(7, INPUT);
pinMode(8, OUTPUT);
}
void loop() {
Button = digitalRead(7);
if(Press == 0) {
delay(100);
lcd.clear();
lcd.print("Press to Start");
if(Button == HIGH) {
Press = 1;
}
}
if(Press == 1) {
if(Game == 1) {
lcd.clear();
// if the Button is pressed the play Jumps
if(Button == HIGH){
ypos = 0;
lcd.setCursor(5,ypos);
lcd.print("Score: ");
lcd.print(score);
lcd.setCursor(xpos,ypos);
lcd.print(char(0));
// else it doesnt jump
}else {
ypos = 1;
lcd.setCursor(5,0);
lcd.print("Score: ");
lcd.print(score);
lcd.setCursor(xpos,ypos);
lcd.print(char(0));
}
if(Nahe > 0){
lcd.setCursor(Nahe,1);
delay(50);
lcd.print(char(1));
delay(wait);
Nahe = Nahe - 1;
}else {
Nahe = Nahe + 16;
wait = wait - 20;
score = score + 200 - wait;
if(wait < 50) {
wait = wait + 70;
}
}
if(Nahe == xpos && ypos == 1) {
lcd.clear();
lcd.print("Lost");
Game = 0;
Button = 0;
digitalWrite(8, HIGH);
Nahe = 16;
wait = 150;
xpos = 2;
ypos = 1;
score = 0;
delay(1000);
digitalWrite(8, LOW);
Press = 0;
Game = 1;
}
}
}
}