#include <Adafruit_GFX.h> // include Adafruit graphics library
#include <VGA.h> // include VGA library
// initialize the VGA library
VGA display = VGA();
int player = 12;
int rockx1 = random((player - 5), (player + 5) + 1);
int rocky1 = 30;
int rockx2 = random((player - 5), (player + 5) + 1);
int rocky2 = 20;
int rockx3 = random((player - 5), (player + 5) + 1);
int rocky3 = 10;
int score = 0;
int title_screen = 1;
void setup(void) {
// initialize the VGA display
pinMode(A0, INPUT); //VR x / left and right
pinMode(A1, INPUT); //SW / start
display.begin();
}
void loop() {
//setup
display.delay(250);
display.clearDisplay();
display.setCursor(0, 0);
display.setTextSize(1);
display.setTextColor(WHITE);
//floor
display.setCursor(0, 57);
display.print("_");
display.setCursor(5, 57);
display.print("_");
display.setCursor(10, 57);
display.print("_");
display.setCursor(15, 57);
display.print("_");
display.setCursor(20, 57);
display.print("_");
//player on screen
display.setCursor(player, 54);
display.print(".");
display.setCursor(player, 56);
display.print(".");
//player controll
if (analogRead(A0) < 400) {
player += -1;
}
if (analogRead(A0) > 600) {
player += 1;
}
if (player <= -3) {
player = -2;
}
if (player >= 22) {
player = 21;
}
//rock falling thing on screen
display.setCursor(rockx1, rocky1);
display.print(".");
display.setCursor(rockx2, rocky2);
display.print(".");
display.setCursor(rockx3, rocky3);
display.print(".");
//rock falling thing "ai"
//resets rocks when they touch the ground
if (rocky1 >= 56) {
rocky1 = 27;
rockx1 = random((player - 5), (player + 5) + 1);
score += 1;
} else {
rocky1 += 2;
}
if (rocky2 >= 56) {
rocky2 = 27;
rockx2 = random((player - 5), (player + 5) + 1);
score += 1;
} else {
rocky2 += 2;
}
if (rocky3 >= 56) {
rocky3 = 27;
rockx3 = random((player - 5), (player + 5) + 1);
score += 1;
} else {
rocky3 += 2;
}
//rock hard stop
if (rockx1 < -2) {
rockx1 = -2;
}
if (rockx1 > 21) {
rockx1 = 21;
}if (rockx2 < -2) {
rockx2 = -2;
}
if (rockx2 > 21) {
rockx2 = 21;
}if (rockx3 < -2) {
rockx3 = -2;
}
if (rockx3 > 21) {
rockx3 = 21;
}
//Score on screen
display.setCursor(0, 5);
display.print("Score ");
display.println(score);
//title screen
if (title_screen == 1){
rocky1 = 30;
rocky2 = 20;
rocky3 = 10;
display.setCursor(0, 15);
display.print("Press");
display.setCursor(0, 25);
display.print("Start");
}
//turn off title screen
if (analogRead(A1) == 0) {
if (title_screen == 1) {
title_screen = 0;
score = 0;
}
}
//Death
if (((!(rockx1 >= player + 2)) && (!(rockx1 <= player - 2))) && rocky1 >= 52) {
title_screen = 1;
}
if (((!(rockx2 >= player + 2)) && (!(rockx2 <= player - 2))) && rocky2 >= 52) {
title_screen = 1;
}
if (((!(rockx3 >= player + 2)) && (!(rockx3 <= player - 2))) && rocky3 >= 52) {
title_screen = 1;
}
//Title
display.setCursor(60, 5);
display.print("Boulder Crash");
}
// end of code.
Comments