28cweaver
Published © GPL3+

Vga Boulder Crash

A fun game on a vga screen with a insane 4 FPS!

IntermediateFull instructions provided291
Vga Boulder Crash

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Analog joystick (Generic)
×1
Resistor 220 ohm
Resistor 220 ohm
×1
Through Hole Resistor, 68 kohm
Through Hole Resistor, 68 kohm
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Scamatics

Joystick
5v to 5v
gnd to gnd
VRx to A0
SW to A1

Code

Boulder Crash

C/C++
You will need two libraries that are at the top.
#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.

Credits

28cweaver

28cweaver

0 projects • 0 followers

Comments