Vga Boulder Crash
A fun game on a vga screen with a insane 4 FPS!
Components and supplies
1
Jumper wires (generic)
1
Through Hole Resistor, 68 kohm
1
Analog joystick (Generic)
1
Arduino UNO
1
Resistor 220 ohm
Apps and platforms
1
Arduino IDE
Project description
Code
Boulder Crash
c_cpp
You will need two libraries that are at the top.
1#include <Adafruit_GFX.h> // include Adafruit graphics library 2#include <VGA.h> // include VGA library 3 4// initialize the VGA library 5VGA display = VGA(); 6 7int player = 12; 8int rockx1 = random((player - 5), (player + 5) + 1); 9int rocky1 = 30; 10int rockx2 = random((player - 5), (player + 5) + 1); 11int rocky2 = 20; 12int rockx3 = random((player - 5), (player + 5) + 1); 13int rocky3 = 10; 14int score = 0; 15int title_screen = 1; 16 17void setup(void) { 18 // initialize the VGA display 19 pinMode(A0, INPUT); //VR x / left and right 20 pinMode(A1, INPUT); //SW / start 21 22 display.begin(); 23} 24 25void loop() { 26 //setup 27 display.delay(250); 28 display.clearDisplay(); 29 display.setCursor(0, 0); 30 display.setTextSize(1); 31 display.setTextColor(WHITE); 32 33 //floor 34 display.setCursor(0, 57); 35 display.print("_"); 36 display.setCursor(5, 57); 37 display.print("_"); 38 display.setCursor(10, 57); 39 display.print("_"); 40 display.setCursor(15, 57); 41 display.print("_"); 42 display.setCursor(20, 57); 43 display.print("_"); 44 45 //player on screen 46 display.setCursor(player, 54); 47 display.print("."); 48 display.setCursor(player, 56); 49 display.print("."); 50 51 //player controll 52 if (analogRead(A0) < 400) { 53 player += -1; 54 } 55 if (analogRead(A0) > 600) { 56 player += 1; 57 } 58 if (player <= -3) { 59 player = -2; 60 } 61 if (player >= 22) { 62 player = 21; 63 } 64 65 //rock falling thing on screen 66 display.setCursor(rockx1, rocky1); 67 display.print("."); 68 display.setCursor(rockx2, rocky2); 69 display.print("."); 70 display.setCursor(rockx3, rocky3); 71 display.print("."); 72 73 //rock falling thing "ai" 74 //resets rocks when they touch the ground 75 if (rocky1 >= 56) { 76 rocky1 = 27; 77 rockx1 = random((player - 5), (player + 5) + 1); 78 score += 1; 79 } else { 80 rocky1 += 2; 81 } 82 if (rocky2 >= 56) { 83 rocky2 = 27; 84 rockx2 = random((player - 5), (player + 5) + 1); 85 score += 1; 86 } else { 87 rocky2 += 2; 88 } 89 if (rocky3 >= 56) { 90 rocky3 = 27; 91 rockx3 = random((player - 5), (player + 5) + 1); 92 score += 1; 93 } else { 94 rocky3 += 2; 95 } 96 97 //rock hard stop 98 if (rockx1 < -2) { 99 rockx1 = -2; 100 } 101 if (rockx1 > 21) { 102 rockx1 = 21; 103 104 }if (rockx2 < -2) { 105 rockx2 = -2; 106 } 107 if (rockx2 > 21) { 108 rockx2 = 21; 109 110 }if (rockx3 < -2) { 111 rockx3 = -2; 112 } 113 if (rockx3 > 21) { 114 rockx3 = 21; 115 } 116 117 //Score on screen 118 display.setCursor(0, 5); 119 display.print("Score "); 120 display.println(score); 121 122 //title screen 123 if (title_screen == 1){ 124 rocky1 = 30; 125 rocky2 = 20; 126 rocky3 = 10; 127 display.setCursor(0, 15); 128 display.print("Press"); 129 display.setCursor(0, 25); 130 display.print("Start"); 131 } 132 133 //turn off title screen 134 if (analogRead(A1) == 0) { 135 if (title_screen == 1) { 136 title_screen = 0; 137 score = 0; 138 } 139 } 140 141 //Death 142 if (((!(rockx1 >= player + 2)) && (!(rockx1 <= player - 2))) && rocky1 >= 52) { 143 title_screen = 1; 144 } 145 if (((!(rockx2 >= player + 2)) && (!(rockx2 <= player - 2))) && rocky2 >= 52) { 146 title_screen = 1; 147 } 148 if (((!(rockx3 >= player + 2)) && (!(rockx3 <= player - 2))) && rocky3 >= 52) { 149 title_screen = 1; 150 } 151 152 //Title 153 display.setCursor(60, 5); 154 display.print("Boulder Crash"); 155 156} 157 158// end of code.
Boulder Crash
c_cpp
You will need two libraries that are at the top.
1#include <Adafruit_GFX.h> // include Adafruit graphics library 2#include 3 <VGA.h> // include VGA library 4 5// initialize the VGA library 6VGA 7 display = VGA(); 8 9int player = 12; 10int rockx1 = random((player - 5), (player 11 + 5) + 1); 12int rocky1 = 30; 13int rockx2 = random((player - 5), (player + 5) 14 + 1); 15int rocky2 = 20; 16int rockx3 = random((player - 5), (player + 5) + 1); 17int 18 rocky3 = 10; 19int score = 0; 20int title_screen = 1; 21 22void setup(void) 23 { 24 // initialize the VGA display 25 pinMode(A0, INPUT); //VR x / left and 26 right 27 pinMode(A1, INPUT); //SW / start 28 29 display.begin(); 30} 31 32void 33 loop() { 34 //setup 35 display.delay(250); 36 display.clearDisplay(); 37 38 display.setCursor(0, 0); 39 display.setTextSize(1); 40 display.setTextColor(WHITE); 41 42 43 //floor 44 display.setCursor(0, 57); 45 display.print("_"); 46 display.setCursor(5, 47 57); 48 display.print("_"); 49 display.setCursor(10, 57); 50 display.print("_"); 51 52 display.setCursor(15, 57); 53 display.print("_"); 54 display.setCursor(20, 55 57); 56 display.print("_"); 57 58 //player on screen 59 display.setCursor(player, 60 54); 61 display.print("."); 62 display.setCursor(player, 56); 63 display.print("."); 64 65 66 //player controll 67 if (analogRead(A0) < 400) { 68 player += -1; 69 } 70 71 if (analogRead(A0) > 600) { 72 player += 1; 73 } 74 if (player <= -3) 75 { 76 player = -2; 77 } 78 if (player >= 22) { 79 player = 21; 80 } 81 82 83 //rock falling thing on screen 84 display.setCursor(rockx1, rocky1); 85 display.print("."); 86 87 display.setCursor(rockx2, rocky2); 88 display.print("."); 89 display.setCursor(rockx3, 90 rocky3); 91 display.print("."); 92 93 //rock falling thing "ai" 94 //resets 95 rocks when they touch the ground 96 if (rocky1 >= 56) { 97 rocky1 = 27; 98 99 rockx1 = random((player - 5), (player + 5) + 1); 100 score += 1; 101 } else 102 { 103 rocky1 += 2; 104 } 105 if (rocky2 >= 56) { 106 rocky2 = 27; 107 rockx2 108 = random((player - 5), (player + 5) + 1); 109 score += 1; 110 } else { 111 rocky2 112 += 2; 113 } 114 if (rocky3 >= 56) { 115 rocky3 = 27; 116 rockx3 = random((player 117 - 5), (player + 5) + 1); 118 score += 1; 119 } else { 120 rocky3 += 2; 121 122 } 123 124 //rock hard stop 125 if (rockx1 < -2) { 126 rockx1 = -2; 127 } 128 129 if (rockx1 > 21) { 130 rockx1 = 21; 131 132 }if (rockx2 < -2) { 133 rockx2 134 = -2; 135 } 136 if (rockx2 > 21) { 137 rockx2 = 21; 138 139 }if (rockx3 140 < -2) { 141 rockx3 = -2; 142 } 143 if (rockx3 > 21) { 144 rockx3 = 21; 145 146 } 147 148 //Score on screen 149 display.setCursor(0, 5); 150 display.print("Score 151 "); 152 display.println(score); 153 154 //title screen 155 if (title_screen 156 == 1){ 157 rocky1 = 30; 158 rocky2 = 20; 159 rocky3 = 10; 160 display.setCursor(0, 161 15); 162 display.print("Press"); 163 display.setCursor(0, 25); 164 display.print("Start"); 165 166 } 167 168 //turn off title screen 169 if (analogRead(A1) == 0) { 170 if (title_screen 171 == 1) { 172 title_screen = 0; 173 score = 0; 174 } 175 } 176 177 178 //Death 179 if (((!(rockx1 >= player + 2)) && (!(rockx1 <= player - 2))) && rocky1 180 >= 52) { 181 title_screen = 1; 182 } 183 if (((!(rockx2 >= player + 2)) && 184 (!(rockx2 <= player - 2))) && rocky2 >= 52) { 185 title_screen = 1; 186 } 187 188 if (((!(rockx3 >= player + 2)) && (!(rockx3 <= player - 2))) && rocky3 >= 52) 189 { 190 title_screen = 1; 191 } 192 193 //Title 194 display.setCursor(60, 5); 195 196 display.print("Boulder Crash"); 197 198} 199 200// end of code.
Downloadable files
Scamatics
Joystick 5v to 5v gnd to gnd VRx to A0 SW to A1
Scamatics

Comments
Only logged in users can leave comments