#include <LiquidCrystal.h>
LiquidCrystal lcd(13,12,7,6,5,4);
int coinX, coinY;
int panacikX = 9;
int panacikY = 1;
int score = 0;
uint8_t panacik[8] =
{
0b00100,
0b01010,
0b00100,
0b01110,
0b10101,
0b00100,
0b01010,
0b10001
};
uint8_t minca[8] =
{
0b00000,
0b00000,
0b01110,
0b10001,
0b10001,
0b01110,
0b00000,
0b00000
};
uint8_t animacia[8] =
{
0b00100,
0b01010,
0b10101,
0b01110,
0b00100,
0b00100,
0b01010,
0b10001
};
void setup()
{
pinMode(A2, INPUT_PULLUP);
pinMode(A5, INPUT_PULLUP);
pinMode(A4, INPUT_PULLUP);
pinMode(A3, INPUT_PULLUP);
lcd.createChar(1, panacik);
lcd.createChar(2, minca);
lcd.createChar(3, animacia);
lcd.begin(20, 4);
lcd.print("Score: ");
lcd.print(score);
lcd.setCursor(panacikX, panacikY);
lcd.print("\x01");
randomSeed(analogRead(0));
coin();
}
void loop()
{
if(digitalRead(A2) == LOW && panacikY > 1)
{
pohyb(0, -1);
delay(150);
}
if(digitalRead(A5) == LOW && panacikY < 3)
{
pohyb(0, 1);
delay(150);
}
if(digitalRead(A4) == LOW && panacikX > 0)
{
pohyb(-1, 0);
delay(100);
}
if(digitalRead(A3) == LOW && panacikX < 19)
{
pohyb(1, 0);
delay(100);
}
}
void coin()
{
do
{
coinX = random(0, 20);
coinY = random(1, 4);
}
while (panacikX == coinX && panacikY == coinY);
lcd.setCursor(coinX, coinY);
lcd.print("\x02");
}
void pohyb(int x, int y)
{
lcd.setCursor(panacikX, panacikY);
lcd.print(" ");
panacikX = panacikX + x;
panacikY = panacikY + y;
lcd.setCursor(panacikX, panacikY);
lcd.print("\x01");
delay(50);
kolizia();
}
void kolizia()
{
if(panacikX == coinX && panacikY == coinY)
{
score++;
lcd.setCursor(0,0);
lcd.print("Score: ");
lcd.print(score);
lcd.setCursor(panacikX, panacikY);
lcd.print("\x03");
coin();
delay(300);
lcd.setCursor(panacikX, panacikY);
lcd.print("\x01");
}
}