#include "GameBoy.h"
GameBoy gb;
int car[4][3]={
{0, 1, 0},
{1, 1, 1},
{0, 1, 0},
{1, 0, 1}
};
void cs(int x, int y){// cs - carShow - показатиМашинку
for(int c=0; c<=2; c++)//c-column-стовпчик
for(int r=0; r<=3; r++)//r-row-рядок
gb.setLed(y+c, x+r, car[r][c]);
}
void cs2(int x, int y){//enemy
for(int c=0; c<=2; c++)
for(int r=0; r<=3; r++)
gb.setLed(x+c, y+r, car[3-r][c]);
}
int x2=1,y2=0; //enemy
int x=1, y=12; //змінна для позиції машинки ліво/право
int score=0;
void line(){
for(int y=0; y<8*2; y++){
gb.setLed(0, y, 1);
gb.setLed(7, y, 1);
}
}
void setup() {
gb.begin(0);
pinMode(13, OUTPUT);
Serial.begin(9600);}
void loop() {
// Serial.println(gb.getKey());
gb.clearDisplay(); line();
cs(x,y);
cs2(x2, y2++);
if(y2>=16){y2=0; if(random(2)) x2=4; else x2=1;score++;}
if(y2>=y and x2 == x){//машинки зіткнулися
tone(13, 100, 100);
gb.clearDisplay();
for(int x=0; x<8; x++)for(int y=0; y<2*8; y++)
gb.setLed(x, y, y*8+x < score);
delay(500);
asm volatile ("jmp 0");//restart
}
if(gb.getKey()==5)x=4;
if(gb.getKey()==4)x=1;
delay(80);
}