My game works perfectly except for the fact that the gameover doesn't worK. It only does game over if line2 hits it. Pleased help for a solution. Here is the code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,7,4,3,2);
int pbu = 13;
int pbd = 10;
int pbr = 8;
int pbl = 6;
int currentcirc = 0;
int xp = 0;
int yp = 0;
int xlp;
int ylp;
int curline;
int shootdelay = 1250;
int prevline;
int ranline;
int gameover = false;
byte circle1[8] =
{
B01110,
B11111,
B11111,
B11111,
B01110,
B00000,
B00000,
B00000,
};
byte circle2[8] =
{
B00000,
B01110,
B11111,
B11111,
B11111,
B01110,
B00000,
B00000,
};
byte circle3[8] =
{
B00000,
B00000,
B01110,
B11111,
B11111,
B11111,
B01110,
B00000,
};
byte circle4[8] =
{
B00000,
B00000,
B00000,
B01110,
B11111,
B11111,
B11111,
B01110,
};
byte line1[8] =
{
B11111,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
};
byte line2[8] =
{
B00000,
B00000,
B11111,
B00000,
B00000,
B00000,
B00000,
B00000,
};
byte line3[8] =
{
B00000,
B00000,
B00000,
B00000,
B11111,
B00000,
B00000,
B00000,
};
byte line4[8] =
{
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B11111,
B00000,
};
void setup()
{
lcd.begin(16,2);
pinMode(9,OUTPUT);
analogWrite(9,50);
pinMode(pbu,INPUT);
pinMode(pbd,INPUT);
pinMode(pbr,INPUT);
pinMode(pbl,INPUT);
lcd.createChar(0,circle1);
lcd.createChar(1,circle2);
lcd.createChar(2,circle3);
lcd.createChar(3,circle4);
lcd.createChar(4,line1);
lcd.createChar(5,line2);
lcd.createChar(6,line3);
lcd.createChar(7,line4);
xlp = 16;
}
void loop()
{
if (gameover != true)
{
lcd.setCursor(0,0);
if (xlp <2)
{
if (curline == 4 && ylp == yp)
{
if (currentcirc != 0)
{
gameover = true;
}
}
if (curline == 5 && ylp == yp)
{
if (currentcirc != 3)
{
gameover = true;
}
}
if (curline == 6 && ylp == yp)
{
gameover == true;
}
if (curline == 7 && ylp == yp)
{
if (currentcirc == 3)
{
gameover = true;
}
}
}
if (xlp == 15)
{ylp = random(0,2);
curline = random(4,8);
}
if (xlp == 1)
{
xlp = 16;
}
if (digitalRead(pbu) == HIGH)
{
if (currentcirc == 0)
{
if (yp == 1)
{
yp = yp - 1;
currentcirc = 3;
}
}
else
{
currentcirc = currentcirc - 1;
}
}
if (digitalRead(pbd) == HIGH)
{
if (currentcirc == 3)
{
if (yp == 0)
{
yp = yp + 1;
currentcirc = 0;
}
}
else
{
currentcirc = currentcirc + 1;
}
}
//if (digitalRead(pbr) == HIGH)
//{
//if (xp < 16)
//{
//xp = xp + 1;
//}
//}
//if (digitalRead(pbl) == HIGH)
//{
//if (xp > 0)
//{
//xp = xp - 1;
//}
//}
if (xp > 16)
{
xp = 16;
}
if (yp > 1)
{
yp = 1;
}
xlp = xlp - 1;
lcd.setCursor(xp,yp);
lcd.write((byte)currentcirc);
shoot();
delay(100);
lcd.clear();
shootdelay = shootdelay - 15;
}
else
{
lcd.clear();
lcd.setCursor(6,0);
lcd.print("GAME");
lcd.setCursor(6,1);
lcd.print("OVER");
if (digitalRead(pbu) == HIGH)
{
gameover = false;
shootdelay= 1250;
}
}
}
void shoot()
{
if (shootdelay < 125)
{
shootdelay = 115;
}
delay(shootdelay);
lcd.setCursor(xlp,ylp);
lcd.write((byte)curline);
}