Components and supplies
Alphanumeric LCD, 16 x 2
Pushbutton switch 12mm
Breadboard (generic)
Jumper wires (generic)
Arduino UNO
Resistor 220 ohm
Apps and platforms
Arduino IDE
Project description
Code
Code LCD game
arduino
1#include <LiquidCrystal.h> 2 3#define PIN_BUTTON 2 4#define PIN_AUTOPLAY 1 5#define PIN_BUZZER 8 6#define PIN_READWRITE 10 7#define PIN_CONTRAST 13 8 9#define SPRITE_RUN1 1 10#define SPRITE_RUN2 2 11#define SPRITE_JUMP 3 12#define SPRITE_JUMP_UPPER '.' // Use the '.' character for the head 13#define SPRITE_JUMP_LOWER 4 14#define SPRITE_TERRAIN_EMPTY ' ' // User the ' ' character 15#define SPRITE_TERRAIN_SOLID 5 16#define SPRITE_TERRAIN_SOLID_RIGHT 6 17#define SPRITE_TERRAIN_SOLID_LEFT 7 18 19#define HERO_HORIZONTAL_POSITION 1 // Horizontal position of hero on screen 20 21#define TERRAIN_WIDTH 16 22#define TERRAIN_EMPTY 0 23#define TERRAIN_LOWER_BLOCK 1 24#define TERRAIN_UPPER_BLOCK 2 25 26#define HERO_POSITION_OFF 0 // Hero is invisible 27#define HERO_POSITION_RUN_LOWER_1 1 // Hero is running on lower row (pose 1) 28#define HERO_POSITION_RUN_LOWER_2 2 // (pose 2) 29 30#define HERO_POSITION_JUMP_1 3 // Starting a jump 31#define HERO_POSITION_JUMP_2 4 // Half-way up 32#define HERO_POSITION_JUMP_3 5 // Jump is on upper row 33#define HERO_POSITION_JUMP_4 6 // Jump is on upper row 34#define HERO_POSITION_JUMP_5 7 // Jump is on upper row 35#define HERO_POSITION_JUMP_6 8 // Jump is on upper row 36#define HERO_POSITION_JUMP_7 9 // Half-way down 37#define HERO_POSITION_JUMP_8 10 // About to land 38 39#define HERO_POSITION_RUN_UPPER_1 11 // Hero is running on upper row (pose 1) 40#define HERO_POSITION_RUN_UPPER_2 12 // (pose 2) 41 42LiquidCrystal lcd(12, 11, 5, 4, 3, 7); 43static char terrainUpper[TERRAIN_WIDTH + 1]; 44static char terrainLower[TERRAIN_WIDTH + 1]; 45static bool buttonPushed = false; 46 47void initializeGraphics(){ 48 static byte graphics[] = { 49 // Run position 1 50 B01100, 51 B01100, 52 B00000, 53 B01110, 54 B11100, 55 B01100, 56 B11010, 57 B10011, 58 // Run position 2 59 B01100, 60 B01100, 61 B00000, 62 B01100, 63 B01100, 64 B01100, 65 B01100, 66 B01110, 67 // Jump 68 B01100, 69 B01100, 70 B00000, 71 B11110, 72 B01101, 73 B11111, 74 B10000, 75 B00000, 76 // Jump lower 77 B11110, 78 B01101, 79 B11111, 80 B10000, 81 B00000, 82 B00000, 83 B00000, 84 B00000, 85 // Ground 86 B11111, 87 B11111, 88 B11111, 89 B11111, 90 B11111, 91 B11111, 92 B11111, 93 B11111, 94 // Ground right 95 B00011, 96 B00011, 97 B00011, 98 B00011, 99 B00011, 100 B00011, 101 B00011, 102 B00011, 103 // Ground left 104 B11000, 105 B11000, 106 B11000, 107 B11000, 108 B11000, 109 B11000, 110 B11000, 111 B11000, 112 }; 113 int i; 114 // Skip using character 0, this allows lcd.print() to be used to 115 // quickly draw multiple characters 116 for (i = 0; i < 7; ++i) { 117 lcd.createChar(i + 1, &graphics[i * 8]); 118 } 119 for (i = 0; i < TERRAIN_WIDTH; ++i) { 120 terrainUpper[i] = SPRITE_TERRAIN_EMPTY; 121 terrainLower[i] = SPRITE_TERRAIN_EMPTY; 122 } 123} 124 125// Slide the terrain to the left in half-character increments 126// 127void advanceTerrain(char* terrain, byte newTerrain){ 128 for (int i = 0; i < TERRAIN_WIDTH; ++i) { 129 char current = terrain[i]; 130 char next = (i == TERRAIN_WIDTH-1) ? newTerrain : terrain[i+1]; 131 switch (current){ 132 case SPRITE_TERRAIN_EMPTY: 133 terrain[i] = (next == SPRITE_TERRAIN_SOLID) ? SPRITE_TERRAIN_SOLID_RIGHT : SPRITE_TERRAIN_EMPTY; 134 break; 135 case SPRITE_TERRAIN_SOLID: 136 terrain[i] = (next == SPRITE_TERRAIN_EMPTY) ? SPRITE_TERRAIN_SOLID_LEFT : SPRITE_TERRAIN_SOLID; 137 break; 138 case SPRITE_TERRAIN_SOLID_RIGHT: 139 terrain[i] = SPRITE_TERRAIN_SOLID; 140 break; 141 case SPRITE_TERRAIN_SOLID_LEFT: 142 terrain[i] = SPRITE_TERRAIN_EMPTY; 143 break; 144 } 145 } 146} 147 148bool drawHero(byte position, char* terrainUpper, char* terrainLower, unsigned int score) { 149 bool collide = false; 150 char upperSave = terrainUpper[HERO_HORIZONTAL_POSITION]; 151 char lowerSave = terrainLower[HERO_HORIZONTAL_POSITION]; 152 byte upper, lower; 153 switch (position) { 154 case HERO_POSITION_OFF: 155 upper = lower = SPRITE_TERRAIN_EMPTY; 156 break; 157 case HERO_POSITION_RUN_LOWER_1: 158 upper = SPRITE_TERRAIN_EMPTY; 159 lower = SPRITE_RUN1; 160 break; 161 case HERO_POSITION_RUN_LOWER_2: 162 upper = SPRITE_TERRAIN_EMPTY; 163 lower = SPRITE_RUN2; 164 break; 165 case HERO_POSITION_JUMP_1: 166 case HERO_POSITION_JUMP_8: 167 upper = SPRITE_TERRAIN_EMPTY; 168 lower = SPRITE_JUMP; 169 break; 170 case HERO_POSITION_JUMP_2: 171 case HERO_POSITION_JUMP_7: 172 upper = SPRITE_JUMP_UPPER; 173 lower = SPRITE_JUMP_LOWER; 174 break; 175 case HERO_POSITION_JUMP_3: 176 case HERO_POSITION_JUMP_4: 177 case HERO_POSITION_JUMP_5: 178 case HERO_POSITION_JUMP_6: 179 upper = SPRITE_JUMP; 180 lower = SPRITE_TERRAIN_EMPTY; 181 break; 182 case HERO_POSITION_RUN_UPPER_1: 183 upper = SPRITE_RUN1; 184 lower = SPRITE_TERRAIN_EMPTY; 185 break; 186 case HERO_POSITION_RUN_UPPER_2: 187 upper = SPRITE_RUN2; 188 lower = SPRITE_TERRAIN_EMPTY; 189 break; 190 } 191 if (upper != ' ') { 192 terrainUpper[HERO_HORIZONTAL_POSITION] = upper; 193 collide = (upperSave == SPRITE_TERRAIN_EMPTY) ? false : true; 194 } 195 if (lower != ' ') { 196 terrainLower[HERO_HORIZONTAL_POSITION] = lower; 197 collide |= (lowerSave == SPRITE_TERRAIN_EMPTY) ? false : true; 198 } 199 200 byte digits = (score > 9999) ? 5 : (score > 999) ? 4 : (score > 99) ? 3 : (score > 9) ? 2 : 1; 201 202 // Draw the scene 203 terrainUpper[TERRAIN_WIDTH] = '\\0'; 204 terrainLower[TERRAIN_WIDTH] = '\\0'; 205 char temp = terrainUpper[16-digits]; 206 terrainUpper[16-digits] = '\\0'; 207 lcd.setCursor(0,0); 208 lcd.print(terrainUpper); 209 terrainUpper[16-digits] = temp; 210 lcd.setCursor(0,1); 211 lcd.print(terrainLower); 212 213 lcd.setCursor(16 - digits,0); 214 lcd.print(score); 215 216 terrainUpper[HERO_HORIZONTAL_POSITION] = upperSave; 217 terrainLower[HERO_HORIZONTAL_POSITION] = lowerSave; 218 return collide; 219} 220 221// Handle the button push as an interrupt 222void buttonPush() { 223 buttonPushed = true; 224} 225 226void setup(){ 227 pinMode(PIN_READWRITE, OUTPUT); 228 digitalWrite(PIN_READWRITE, LOW); 229 pinMode(PIN_CONTRAST, OUTPUT); 230 digitalWrite(PIN_CONTRAST, LOW); 231 pinMode(PIN_BUTTON, INPUT); 232 digitalWrite(PIN_BUTTON, HIGH); 233 pinMode(PIN_AUTOPLAY, OUTPUT); 234 digitalWrite(PIN_AUTOPLAY, HIGH); 235 pinMode(PIN_BUZZER,OUTPUT);//initialize the buzzer pin as an output 236 digitalWrite(PIN_BUZZER, LOW); 237 238 // Digital pin 2 maps to interrupt 0 239 attachInterrupt(0/*PIN_BUTTON*/, buttonPush, FALLING); 240 241 initializeGraphics(); 242 243 lcd.begin(16, 2); 244} 245 246void loop(){ 247 static byte heroPos = HERO_POSITION_RUN_LOWER_1; 248 static byte newTerrainType = TERRAIN_EMPTY; 249 static byte newTerrainDuration = 1; 250 static bool playing = false; 251 static bool blink = false; 252 static unsigned int distance = 0; 253 254 if (!playing) { 255 drawHero((blink) ? HERO_POSITION_OFF : heroPos, terrainUpper, terrainLower, distance >> 3); 256 if (blink) { 257 lcd.setCursor(0,0); 258 lcd.print("Press Start"); 259 } 260 delay(250); 261 blink = !blink; 262 if (buttonPushed) { 263 264 265 266 initializeGraphics(); 267 heroPos = HERO_POSITION_RUN_LOWER_1; 268 playing = true; 269 buttonPushed = false; 270 distance = 0; 271 } 272 return; 273 } 274 275 // Shift the terrain to the left 276 advanceTerrain(terrainLower, newTerrainType == TERRAIN_LOWER_BLOCK ? SPRITE_TERRAIN_SOLID : SPRITE_TERRAIN_EMPTY); 277 advanceTerrain(terrainUpper, newTerrainType == TERRAIN_UPPER_BLOCK ? SPRITE_TERRAIN_SOLID : SPRITE_TERRAIN_EMPTY); 278 279 // Make new terrain to enter on the right 280 if (--newTerrainDuration == 0) { 281 if (newTerrainType == TERRAIN_EMPTY) { 282 newTerrainType = (random(3) == 0) ? TERRAIN_UPPER_BLOCK : TERRAIN_LOWER_BLOCK; 283 newTerrainDuration = 2 + random(10); 284 } else { 285 newTerrainType = TERRAIN_EMPTY; 286 newTerrainDuration = 10 + random(10); 287 } 288 } 289 290 if (buttonPushed) { 291 if (heroPos <= HERO_POSITION_RUN_LOWER_2) heroPos = HERO_POSITION_JUMP_1; 292 buttonPushed = false; 293 digitalWrite(PIN_BUZZER,HIGH); 294 } 295 296 if (drawHero(heroPos, terrainUpper, terrainLower, distance >> 3)) { 297 playing = false; // The hero collided with something. Too bad. 298 for (int i = 0; i <= 2; i++) { 299 digitalWrite(PIN_BUZZER, HIGH); 300 delay(100); 301 digitalWrite(PIN_BUZZER, LOW); 302 delay(100); 303 } 304 } else { 305 if (heroPos == HERO_POSITION_RUN_LOWER_2 || heroPos == HERO_POSITION_JUMP_8) { 306 heroPos = HERO_POSITION_RUN_LOWER_1; 307 } else if ((heroPos >= HERO_POSITION_JUMP_3 && heroPos <= HERO_POSITION_JUMP_5) && terrainLower[HERO_HORIZONTAL_POSITION] != SPRITE_TERRAIN_EMPTY) { 308 heroPos = HERO_POSITION_RUN_UPPER_1; 309 } else if (heroPos >= HERO_POSITION_RUN_UPPER_1 && terrainLower[HERO_HORIZONTAL_POSITION] == SPRITE_TERRAIN_EMPTY) { 310 heroPos = HERO_POSITION_JUMP_5; 311 } else if (heroPos == HERO_POSITION_RUN_UPPER_2) { 312 heroPos = HERO_POSITION_RUN_UPPER_1; 313 } else { 314 ++heroPos; 315 } 316 ++distance; 317 318 digitalWrite(PIN_AUTOPLAY, terrainLower[HERO_HORIZONTAL_POSITION + 2] == SPRITE_TERRAIN_EMPTY ? HIGH : LOW); 319 } 320 delay(100); 321 digitalWrite(PIN_BUZZER,LOW); 322}
Code LCD game
arduino
1#include <LiquidCrystal.h> 2 3#define PIN_BUTTON 2 4#define PIN_AUTOPLAY 1 5#define PIN_BUZZER 8 6#define PIN_READWRITE 10 7#define PIN_CONTRAST 13 8 9#define SPRITE_RUN1 1 10#define SPRITE_RUN2 2 11#define SPRITE_JUMP 3 12#define SPRITE_JUMP_UPPER '.' // Use the '.' character for the head 13#define SPRITE_JUMP_LOWER 4 14#define SPRITE_TERRAIN_EMPTY ' ' // User the ' ' character 15#define SPRITE_TERRAIN_SOLID 5 16#define SPRITE_TERRAIN_SOLID_RIGHT 6 17#define SPRITE_TERRAIN_SOLID_LEFT 7 18 19#define HERO_HORIZONTAL_POSITION 1 // Horizontal position of hero on screen 20 21#define TERRAIN_WIDTH 16 22#define TERRAIN_EMPTY 0 23#define TERRAIN_LOWER_BLOCK 1 24#define TERRAIN_UPPER_BLOCK 2 25 26#define HERO_POSITION_OFF 0 // Hero is invisible 27#define HERO_POSITION_RUN_LOWER_1 1 // Hero is running on lower row (pose 1) 28#define HERO_POSITION_RUN_LOWER_2 2 // (pose 2) 29 30#define HERO_POSITION_JUMP_1 3 // Starting a jump 31#define HERO_POSITION_JUMP_2 4 // Half-way up 32#define HERO_POSITION_JUMP_3 5 // Jump is on upper row 33#define HERO_POSITION_JUMP_4 6 // Jump is on upper row 34#define HERO_POSITION_JUMP_5 7 // Jump is on upper row 35#define HERO_POSITION_JUMP_6 8 // Jump is on upper row 36#define HERO_POSITION_JUMP_7 9 // Half-way down 37#define HERO_POSITION_JUMP_8 10 // About to land 38 39#define HERO_POSITION_RUN_UPPER_1 11 // Hero is running on upper row (pose 1) 40#define HERO_POSITION_RUN_UPPER_2 12 // (pose 2) 41 42LiquidCrystal lcd(12, 11, 5, 4, 3, 7); 43static char terrainUpper[TERRAIN_WIDTH + 1]; 44static char terrainLower[TERRAIN_WIDTH + 1]; 45static bool buttonPushed = false; 46 47void initializeGraphics(){ 48 static byte graphics[] = { 49 // Run position 1 50 B01100, 51 B01100, 52 B00000, 53 B01110, 54 B11100, 55 B01100, 56 B11010, 57 B10011, 58 // Run position 2 59 B01100, 60 B01100, 61 B00000, 62 B01100, 63 B01100, 64 B01100, 65 B01100, 66 B01110, 67 // Jump 68 B01100, 69 B01100, 70 B00000, 71 B11110, 72 B01101, 73 B11111, 74 B10000, 75 B00000, 76 // Jump lower 77 B11110, 78 B01101, 79 B11111, 80 B10000, 81 B00000, 82 B00000, 83 B00000, 84 B00000, 85 // Ground 86 B11111, 87 B11111, 88 B11111, 89 B11111, 90 B11111, 91 B11111, 92 B11111, 93 B11111, 94 // Ground right 95 B00011, 96 B00011, 97 B00011, 98 B00011, 99 B00011, 100 B00011, 101 B00011, 102 B00011, 103 // Ground left 104 B11000, 105 B11000, 106 B11000, 107 B11000, 108 B11000, 109 B11000, 110 B11000, 111 B11000, 112 }; 113 int i; 114 // Skip using character 0, this allows lcd.print() to be used to 115 // quickly draw multiple characters 116 for (i = 0; i < 7; ++i) { 117 lcd.createChar(i + 1, &graphics[i * 8]); 118 } 119 for (i = 0; i < TERRAIN_WIDTH; ++i) { 120 terrainUpper[i] = SPRITE_TERRAIN_EMPTY; 121 terrainLower[i] = SPRITE_TERRAIN_EMPTY; 122 } 123} 124 125// Slide the terrain to the left in half-character increments 126// 127void advanceTerrain(char* terrain, byte newTerrain){ 128 for (int i = 0; i < TERRAIN_WIDTH; ++i) { 129 char current = terrain[i]; 130 char next = (i == TERRAIN_WIDTH-1) ? newTerrain : terrain[i+1]; 131 switch (current){ 132 case SPRITE_TERRAIN_EMPTY: 133 terrain[i] = (next == SPRITE_TERRAIN_SOLID) ? SPRITE_TERRAIN_SOLID_RIGHT : SPRITE_TERRAIN_EMPTY; 134 break; 135 case SPRITE_TERRAIN_SOLID: 136 terrain[i] = (next == SPRITE_TERRAIN_EMPTY) ? SPRITE_TERRAIN_SOLID_LEFT : SPRITE_TERRAIN_SOLID; 137 break; 138 case SPRITE_TERRAIN_SOLID_RIGHT: 139 terrain[i] = SPRITE_TERRAIN_SOLID; 140 break; 141 case SPRITE_TERRAIN_SOLID_LEFT: 142 terrain[i] = SPRITE_TERRAIN_EMPTY; 143 break; 144 } 145 } 146} 147 148bool drawHero(byte position, char* terrainUpper, char* terrainLower, unsigned int score) { 149 bool collide = false; 150 char upperSave = terrainUpper[HERO_HORIZONTAL_POSITION]; 151 char lowerSave = terrainLower[HERO_HORIZONTAL_POSITION]; 152 byte upper, lower; 153 switch (position) { 154 case HERO_POSITION_OFF: 155 upper = lower = SPRITE_TERRAIN_EMPTY; 156 break; 157 case HERO_POSITION_RUN_LOWER_1: 158 upper = SPRITE_TERRAIN_EMPTY; 159 lower = SPRITE_RUN1; 160 break; 161 case HERO_POSITION_RUN_LOWER_2: 162 upper = SPRITE_TERRAIN_EMPTY; 163 lower = SPRITE_RUN2; 164 break; 165 case HERO_POSITION_JUMP_1: 166 case HERO_POSITION_JUMP_8: 167 upper = SPRITE_TERRAIN_EMPTY; 168 lower = SPRITE_JUMP; 169 break; 170 case HERO_POSITION_JUMP_2: 171 case HERO_POSITION_JUMP_7: 172 upper = SPRITE_JUMP_UPPER; 173 lower = SPRITE_JUMP_LOWER; 174 break; 175 case HERO_POSITION_JUMP_3: 176 case HERO_POSITION_JUMP_4: 177 case HERO_POSITION_JUMP_5: 178 case HERO_POSITION_JUMP_6: 179 upper = SPRITE_JUMP; 180 lower = SPRITE_TERRAIN_EMPTY; 181 break; 182 case HERO_POSITION_RUN_UPPER_1: 183 upper = SPRITE_RUN1; 184 lower = SPRITE_TERRAIN_EMPTY; 185 break; 186 case HERO_POSITION_RUN_UPPER_2: 187 upper = SPRITE_RUN2; 188 lower = SPRITE_TERRAIN_EMPTY; 189 break; 190 } 191 if (upper != ' ') { 192 terrainUpper[HERO_HORIZONTAL_POSITION] = upper; 193 collide = (upperSave == SPRITE_TERRAIN_EMPTY) ? false : true; 194 } 195 if (lower != ' ') { 196 terrainLower[HERO_HORIZONTAL_POSITION] = lower; 197 collide |= (lowerSave == SPRITE_TERRAIN_EMPTY) ? false : true; 198 } 199 200 byte digits = (score > 9999) ? 5 : (score > 999) ? 4 : (score > 99) ? 3 : (score > 9) ? 2 : 1; 201 202 // Draw the scene 203 terrainUpper[TERRAIN_WIDTH] = '\\0'; 204 terrainLower[TERRAIN_WIDTH] = '\\0'; 205 char temp = terrainUpper[16-digits]; 206 terrainUpper[16-digits] = '\\0'; 207 lcd.setCursor(0,0); 208 lcd.print(terrainUpper); 209 terrainUpper[16-digits] = temp; 210 lcd.setCursor(0,1); 211 lcd.print(terrainLower); 212 213 lcd.setCursor(16 - digits,0); 214 lcd.print(score); 215 216 terrainUpper[HERO_HORIZONTAL_POSITION] = upperSave; 217 terrainLower[HERO_HORIZONTAL_POSITION] = lowerSave; 218 return collide; 219} 220 221// Handle the button push as an interrupt 222void buttonPush() { 223 buttonPushed = true; 224} 225 226void setup(){ 227 pinMode(PIN_READWRITE, OUTPUT); 228 digitalWrite(PIN_READWRITE, LOW); 229 pinMode(PIN_CONTRAST, OUTPUT); 230 digitalWrite(PIN_CONTRAST, LOW); 231 pinMode(PIN_BUTTON, INPUT); 232 digitalWrite(PIN_BUTTON, HIGH); 233 pinMode(PIN_AUTOPLAY, OUTPUT); 234 digitalWrite(PIN_AUTOPLAY, HIGH); 235 pinMode(PIN_BUZZER,OUTPUT);//initialize the buzzer pin as an output 236 digitalWrite(PIN_BUZZER, LOW); 237 238 // Digital pin 2 maps to interrupt 0 239 attachInterrupt(0/*PIN_BUTTON*/, buttonPush, FALLING); 240 241 initializeGraphics(); 242 243 lcd.begin(16, 2); 244} 245 246void loop(){ 247 static byte heroPos = HERO_POSITION_RUN_LOWER_1; 248 static byte newTerrainType = TERRAIN_EMPTY; 249 static byte newTerrainDuration = 1; 250 static bool playing = false; 251 static bool blink = false; 252 static unsigned int distance = 0; 253 254 if (!playing) { 255 drawHero((blink) ? HERO_POSITION_OFF : heroPos, terrainUpper, terrainLower, distance >> 3); 256 if (blink) { 257 lcd.setCursor(0,0); 258 lcd.print("Press Start"); 259 } 260 delay(250); 261 blink = !blink; 262 if (buttonPushed) { 263 264 265 266 initializeGraphics(); 267 heroPos = HERO_POSITION_RUN_LOWER_1; 268 playing = true; 269 buttonPushed = false; 270 distance = 0; 271 } 272 return; 273 } 274 275 // Shift the terrain to the left 276 advanceTerrain(terrainLower, newTerrainType == TERRAIN_LOWER_BLOCK ? SPRITE_TERRAIN_SOLID : SPRITE_TERRAIN_EMPTY); 277 advanceTerrain(terrainUpper, newTerrainType == TERRAIN_UPPER_BLOCK ? SPRITE_TERRAIN_SOLID : SPRITE_TERRAIN_EMPTY); 278 279 // Make new terrain to enter on the right 280 if (--newTerrainDuration == 0) { 281 if (newTerrainType == TERRAIN_EMPTY) { 282 newTerrainType = (random(3) == 0) ? TERRAIN_UPPER_BLOCK : TERRAIN_LOWER_BLOCK; 283 newTerrainDuration = 2 + random(10); 284 } else { 285 newTerrainType = TERRAIN_EMPTY; 286 newTerrainDuration = 10 + random(10); 287 } 288 } 289 290 if (buttonPushed) { 291 if (heroPos <= HERO_POSITION_RUN_LOWER_2) heroPos = HERO_POSITION_JUMP_1; 292 buttonPushed = false; 293 digitalWrite(PIN_BUZZER,HIGH); 294 } 295 296 if (drawHero(heroPos, terrainUpper, terrainLower, distance >> 3)) { 297 playing = false; // The hero collided with something. Too bad. 298 for (int i = 0; i <= 2; i++) { 299 digitalWrite(PIN_BUZZER, HIGH); 300 delay(100); 301 digitalWrite(PIN_BUZZER, LOW); 302 delay(100); 303 } 304 } else { 305 if (heroPos == HERO_POSITION_RUN_LOWER_2 || heroPos == HERO_POSITION_JUMP_8) { 306 heroPos = HERO_POSITION_RUN_LOWER_1; 307 } else if ((heroPos >= HERO_POSITION_JUMP_3 && heroPos <= HERO_POSITION_JUMP_5) && terrainLower[HERO_HORIZONTAL_POSITION] != SPRITE_TERRAIN_EMPTY) { 308 heroPos = HERO_POSITION_RUN_UPPER_1; 309 } else if (heroPos >= HERO_POSITION_RUN_UPPER_1 && terrainLower[HERO_HORIZONTAL_POSITION] == SPRITE_TERRAIN_EMPTY) { 310 heroPos = HERO_POSITION_JUMP_5; 311 } else if (heroPos == HERO_POSITION_RUN_UPPER_2) { 312 heroPos = HERO_POSITION_RUN_UPPER_1; 313 } else { 314 ++heroPos; 315 } 316 ++distance; 317 318 digitalWrite(PIN_AUTOPLAY, terrainLower[HERO_HORIZONTAL_POSITION + 2] == SPRITE_TERRAIN_EMPTY ? HIGH : LOW); 319 } 320 delay(100); 321 digitalWrite(PIN_BUZZER,LOW); 322}
Downloadable files
Schematic LCD game
Schematic LCD game
Comments
Only logged in users can leave comments
nekef
a year ago
What a great game
Anonymous user
2 years ago
Thank you! Perfect!
Anonymous user
2 years ago
help me pls, I am trying to do this for like 6 months, and if I don't manage to do it, my teacher will execute me, so ye some help on the cables would be greatly appreciated! :))
Anonymous user
2 years ago
Awsome!
Anonymous user
2 years ago
how do i install the buzzer
neslihanbaybatur
2 years ago
Thank you! Perfect!
Anonymous user
4 years ago
Awsome!
Anonymous user
5 years ago
help me pls, I am trying to do this for like 6 months, and if I don't manage to do it, my teacher will execute me, so ye some help on the cables would be greatly appreciated! :))
Tiemovanloon
5 years ago
If you have any questions, ask them here!
missfit273
7 months ago
Is this a copy of another project? I see a lot of duplicates...