Components and supplies
Analog joystick (Generic)
Breadboard (generic)
Alphanumeric LCD, 16 x 2
Resistor 330 ohm
Jumper wires (generic)
Arduino UNO
Single Turn Potentiometer- 10k ohms
Tools and machines
Plier, Long Nose
Apps and platforms
Arduino IDE
Project description
Code
Code
arduino
1//www.YouTube.com/Electronics is Fun// 2//Mohd Sohail// 3 4#include <LiquidCrystal.h> 5 6#define JoyX 2 7#define PIN_AUTOPLAY 1 8#define PIN_READWRITE 10 9#define PIN_CONTRAST 12 10 11#define SPRITE_RUN1 1 12#define SPRITE_RUN2 2 13#define SPRITE_JUMP 3 14#define SPRITE_JUMP_UPPER '.' // Use the '.' character for the head 15#define SPRITE_JUMP_LOWER 4 16#define SPRITE_TERRAIN_EMPTY ' ' // User the ' ' character 17#define SPRITE_TERRAIN_SOLID 5 18#define SPRITE_TERRAIN_SOLID_RIGHT 6 19#define SPRITE_TERRAIN_SOLID_LEFT 7 20 21#define BOY_HORIZONTAL_POSITION 1 // Horizontal position of hero on screen 22 23#define TERRAIN_WIDTH 16 24#define TERRAIN_EMPTY 0 25#define TERRAIN_LOWER_BLOCK 1 26#define TERRAIN_UPPER_BLOCK 2 27 28#define BOY_POSITION_OFF 0 // boy is invisible 29#define BOY_POSITION_RUN_LOWER_1 1 // boy is running on lower row (pose 1) 30#define BOY_POSITION_RUN_LOWER_2 2 // (pose 2) 31 32#define BOY_POSITION_JUMP_1 3 // Starting a jump 33#define BOY_POSITION_JUMP_2 4 // Half-way up 34#define BOY_POSITION_JUMP_3 5 // Jump is on upper row 35#define BOY_POSITION_JUMP_4 6 // Jump is on upper row 36#define BOY_POSITION_JUMP_5 7 // Jump is on upper row 37#define BOY_POSITION_JUMP_6 8 // Jump is on upper row 38#define BOY_POSITION_JUMP_7 9 // Half-way down 39#define BOY_POSITION_JUMP_8 10 // About to land 40 41#define BOY_POSITION_RUN_UPPER_1 11 // boy is running on upper row (pose 1) 42#define BOY_POSITION_RUN_UPPER_2 12 // (pose 2) 43 44LiquidCrystal lcd(11, 9, 6, 5, 4, 3); 45static char terrainUpper[TERRAIN_WIDTH + 1]; 46static char terrainLower[TERRAIN_WIDTH + 1]; 47static bool buttonPushed = false; 48 49void initializeGraphics(){ 50 static byte graphics[] = { 51 // Run position 1 52 B01100, 53 B01100, 54 B00000, 55 B01110, 56 B11100, 57 B01100, 58 B11010, 59 B10011, 60 // Run position 2 61 B01100, 62 B01100, 63 B00000, 64 B01100, 65 B01100, 66 B01100, 67 B01100, 68 B01110, 69 // Jump 70 B01100, 71 B01100, 72 B00000, 73 B11110, 74 B01101, 75 B11111, 76 B10000, 77 B00000, 78 // Jump lower 79 B11110, 80 B01101, 81 B11111, 82 B10000, 83 B00000, 84 B00000, 85 B00000, 86 B00000, 87 // Ground 88 B11111, 89 B11111, 90 B11111, 91 B11111, 92 B11111, 93 B11111, 94 B11111, 95 B11111, 96 // Ground right 97 B00011, 98 B00011, 99 B00011, 100 B00011, 101 B00011, 102 B00011, 103 B00011, 104 B00011, 105 // Ground left 106 B11000, 107 B11000, 108 B11000, 109 B11000, 110 B11000, 111 B11000, 112 B11000, 113 B11000, 114 }; 115 int i; 116 // Skip using character 0, this allows lcd.print() to be used to 117 // quickly draw multiple characters 118 for (i = 0; i < 7; ++i) { 119 lcd.createChar(i + 1, &graphics[i * 8]); 120 } 121 for (i = 0; i < TERRAIN_WIDTH; ++i) { 122 terrainUpper[i] = SPRITE_TERRAIN_EMPTY; 123 terrainLower[i] = SPRITE_TERRAIN_EMPTY; 124 } 125} 126 127// Slide the terrain to the left in half-character increments 128// 129void advanceTerrain(char* terrain, byte newTerrain){ 130 for (int i = 0; i < TERRAIN_WIDTH; ++i) { 131 char current = terrain[i]; 132 char next = (i == TERRAIN_WIDTH-1) ? newTerrain : terrain[i+1]; 133 switch (current){ 134 case SPRITE_TERRAIN_EMPTY: 135 terrain[i] = (next == SPRITE_TERRAIN_SOLID) ? SPRITE_TERRAIN_SOLID_RIGHT : SPRITE_TERRAIN_EMPTY; 136 break; 137 case SPRITE_TERRAIN_SOLID: 138 terrain[i] = (next == SPRITE_TERRAIN_EMPTY) ? SPRITE_TERRAIN_SOLID_LEFT : SPRITE_TERRAIN_SOLID; 139 break; 140 case SPRITE_TERRAIN_SOLID_RIGHT: 141 terrain[i] = SPRITE_TERRAIN_SOLID; 142 break; 143 case SPRITE_TERRAIN_SOLID_LEFT: 144 terrain[i] = SPRITE_TERRAIN_EMPTY; 145 break; 146 } 147 } 148} 149 150bool drawBoy(byte position, char* terrainUpper, char* terrainLower, unsigned int score) { 151 bool collide = false; 152 char upperSave = terrainUpper[BOY_HORIZONTAL_POSITION]; 153 char lowerSave = terrainLower[BOY_HORIZONTAL_POSITION]; 154 byte upper, lower; 155 switch (position) { 156 case BOY_POSITION_OFF: 157 upper = lower = SPRITE_TERRAIN_EMPTY; 158 break; 159 case BOY_POSITION_RUN_LOWER_1: 160 upper = SPRITE_TERRAIN_EMPTY; 161 lower = SPRITE_RUN1; 162 break; 163 case BOY_POSITION_RUN_LOWER_2: 164 upper = SPRITE_TERRAIN_EMPTY; 165 lower = SPRITE_RUN2; 166 break; 167 case BOY_POSITION_JUMP_1: 168 case BOY_POSITION_JUMP_8: 169 upper = SPRITE_TERRAIN_EMPTY; 170 lower = SPRITE_JUMP; 171 break; 172 case BOY_POSITION_JUMP_2: 173 case BOY_POSITION_JUMP_7: 174 upper = SPRITE_JUMP_UPPER; 175 lower = SPRITE_JUMP_LOWER; 176 break; 177 case BOY_POSITION_JUMP_3: 178 case BOY_POSITION_JUMP_4: 179 case BOY_POSITION_JUMP_5: 180 case BOY_POSITION_JUMP_6: 181 upper = SPRITE_JUMP; 182 lower = SPRITE_TERRAIN_EMPTY; 183 break; 184 case BOY_POSITION_RUN_UPPER_1: 185 upper = SPRITE_RUN1; 186 lower = SPRITE_TERRAIN_EMPTY; 187 break; 188 case BOY_POSITION_RUN_UPPER_2: 189 upper = SPRITE_RUN2; 190 lower = SPRITE_TERRAIN_EMPTY; 191 break; 192 } 193 if (upper != ' ') { 194 terrainUpper[BOY_HORIZONTAL_POSITION] = upper; 195 collide = (upperSave == SPRITE_TERRAIN_EMPTY) ? false : true; 196 } 197 if (lower != ' ') { 198 terrainLower[BOY_HORIZONTAL_POSITION] = lower; 199 collide |= (lowerSave == SPRITE_TERRAIN_EMPTY) ? false : true; 200 } 201 202 byte digits = (score > 9999) ? 5 : (score > 999) ? 4 : (score > 99) ? 3 : (score > 9) ? 2 : 1; 203 204 // Draw the scene 205 terrainUpper[TERRAIN_WIDTH] = '\\0'; 206 terrainLower[TERRAIN_WIDTH] = '\\0'; 207 char temp = terrainUpper[16-digits]; 208 terrainUpper[16-digits] = '\\0'; 209 lcd.setCursor(0,0); 210 lcd.print(terrainUpper); 211 terrainUpper[16-digits] = temp; 212 lcd.setCursor(0,1); 213 lcd.print(terrainLower); 214 215 lcd.setCursor(16 - digits,0); 216 lcd.print(score); 217 218 terrainUpper[BOY_HORIZONTAL_POSITION] = upperSave; 219 terrainLower[BOY_HORIZONTAL_POSITION] = lowerSave; 220 return collide; 221} 222 223// Handle the button push as an interrupt 224void buttonPush() { 225 buttonPushed = true; 226} 227 228void setup(){ 229 pinMode(PIN_READWRITE, OUTPUT); 230 digitalWrite(PIN_READWRITE, LOW); 231 pinMode(PIN_CONTRAST, OUTPUT); 232 digitalWrite(PIN_CONTRAST, LOW); 233 pinMode(JoyX, INPUT); 234 digitalWrite(JoyX, HIGH); 235 pinMode(PIN_AUTOPLAY, OUTPUT); 236 digitalWrite(PIN_AUTOPLAY, HIGH); 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 boyPos = BOY_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 drawBoy((blink) ? BOY_POSITION_OFF : boyPos, 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 initializeGraphics(); 264 boyPos = BOY_POSITION_RUN_LOWER_1; 265 playing = true; 266 buttonPushed = false; 267 distance = 0; 268 } 269 return; 270 } 271 272 // Shift the terrain to the left 273 advanceTerrain(terrainLower, newTerrainType == TERRAIN_LOWER_BLOCK ? SPRITE_TERRAIN_SOLID : SPRITE_TERRAIN_EMPTY); 274 advanceTerrain(terrainUpper, newTerrainType == TERRAIN_UPPER_BLOCK ? SPRITE_TERRAIN_SOLID : SPRITE_TERRAIN_EMPTY); 275 276 // Make new terrain to enter on the right 277 if (--newTerrainDuration == 0) { 278 if (newTerrainType == TERRAIN_EMPTY) { 279 newTerrainType = (random(3) == 0) ? TERRAIN_UPPER_BLOCK : TERRAIN_LOWER_BLOCK; 280 newTerrainDuration = 2 + random(10); 281 } else { 282 newTerrainType = TERRAIN_EMPTY; 283 newTerrainDuration = 10 + random(10); 284 } 285 } 286 287 if (buttonPushed) { 288 if (boyPos <= BOY_POSITION_RUN_LOWER_2) boyPos = BOY_POSITION_JUMP_1; 289 buttonPushed = false; 290 } 291 292 if (drawBoy(boyPos, terrainUpper, terrainLower, distance >> 3)) { 293 playing = false; // The boy collided with something. Too bad. 294 } else { 295 if (boyPos == BOY_POSITION_RUN_LOWER_2 || boyPos == BOY_POSITION_JUMP_8) { 296 boyPos = BOY_POSITION_RUN_LOWER_1; 297 } else if ((boyPos >= BOY_POSITION_JUMP_3 && boyPos <= BOY_POSITION_JUMP_5) && terrainLower[BOY_HORIZONTAL_POSITION] != SPRITE_TERRAIN_EMPTY) { 298 boyPos = BOY_POSITION_RUN_UPPER_1; 299 } else if (boyPos >= BOY_POSITION_RUN_UPPER_1 && terrainLower[BOY_HORIZONTAL_POSITION] == SPRITE_TERRAIN_EMPTY) { 300 boyPos = BOY_POSITION_JUMP_5; 301 } else if (boyPos == BOY_POSITION_RUN_UPPER_2) { 302 boyPos = BOY_POSITION_RUN_UPPER_1; 303 } else { 304 ++boyPos; 305 } 306 ++distance; 307 308 digitalWrite(PIN_AUTOPLAY, terrainLower[BOY_HORIZONTAL_POSITION + 2] == SPRITE_TERRAIN_EMPTY ? HIGH : LOW); 309 } 310 delay(100); 311} 312
Code
arduino
1//www.YouTube.com/Electronics is Fun// 2//Mohd Sohail// 3 4#include 5 <LiquidCrystal.h> 6 7#define JoyX 2 8#define PIN_AUTOPLAY 1 9#define PIN_READWRITE 10 10 11#define PIN_CONTRAST 12 12 13#define SPRITE_RUN1 1 14#define SPRITE_RUN2 15 2 16#define SPRITE_JUMP 3 17#define SPRITE_JUMP_UPPER '.' // Use the '.' 18 character for the head 19#define SPRITE_JUMP_LOWER 4 20#define SPRITE_TERRAIN_EMPTY 21 ' ' // User the ' ' character 22#define SPRITE_TERRAIN_SOLID 5 23#define 24 SPRITE_TERRAIN_SOLID_RIGHT 6 25#define SPRITE_TERRAIN_SOLID_LEFT 7 26 27#define 28 BOY_HORIZONTAL_POSITION 1 // Horizontal position of hero on screen 29 30#define 31 TERRAIN_WIDTH 16 32#define TERRAIN_EMPTY 0 33#define TERRAIN_LOWER_BLOCK 1 34#define 35 TERRAIN_UPPER_BLOCK 2 36 37#define BOY_POSITION_OFF 0 // boy is invisible 38#define 39 BOY_POSITION_RUN_LOWER_1 1 // boy is running on lower row (pose 1) 40#define BOY_POSITION_RUN_LOWER_2 41 2 // (pose 2) 42 43#define BOY_POSITION_JUMP_1 3 44 // Starting a jump 45#define BOY_POSITION_JUMP_2 4 // Half-way up 46#define 47 BOY_POSITION_JUMP_3 5 // Jump is on upper row 48#define BOY_POSITION_JUMP_4 49 6 // Jump is on upper row 50#define BOY_POSITION_JUMP_5 7 // Jump is 51 on upper row 52#define BOY_POSITION_JUMP_6 8 // Jump is on upper row 53#define 54 BOY_POSITION_JUMP_7 9 // Half-way down 55#define BOY_POSITION_JUMP_8 10 // 56 About to land 57 58#define BOY_POSITION_RUN_UPPER_1 11 // boy is running on upper 59 row (pose 1) 60#define BOY_POSITION_RUN_UPPER_2 12 // (pose 61 2) 62 63LiquidCrystal lcd(11, 9, 6, 5, 4, 3); 64static char terrainUpper[TERRAIN_WIDTH 65 + 1]; 66static char terrainLower[TERRAIN_WIDTH + 1]; 67static bool buttonPushed 68 = false; 69 70void initializeGraphics(){ 71 static byte graphics[] = { 72 // 73 Run position 1 74 B01100, 75 B01100, 76 B00000, 77 B01110, 78 B11100, 79 80 B01100, 81 B11010, 82 B10011, 83 // Run position 2 84 B01100, 85 86 B01100, 87 B00000, 88 B01100, 89 B01100, 90 B01100, 91 B01100, 92 93 B01110, 94 // Jump 95 B01100, 96 B01100, 97 B00000, 98 B11110, 99 100 B01101, 101 B11111, 102 B10000, 103 B00000, 104 // Jump lower 105 106 B11110, 107 B01101, 108 B11111, 109 B10000, 110 B00000, 111 B00000, 112 113 B00000, 114 B00000, 115 // Ground 116 B11111, 117 B11111, 118 B11111, 119 120 B11111, 121 B11111, 122 B11111, 123 B11111, 124 B11111, 125 // 126 Ground right 127 B00011, 128 B00011, 129 B00011, 130 B00011, 131 B00011, 132 133 B00011, 134 B00011, 135 B00011, 136 // Ground left 137 B11000, 138 139 B11000, 140 B11000, 141 B11000, 142 B11000, 143 B11000, 144 B11000, 145 146 B11000, 147 }; 148 int i; 149 // Skip using character 0, this allows lcd.print() 150 to be used to 151 // quickly draw multiple characters 152 for (i = 0; i < 7; ++i) 153 { 154 lcd.createChar(i + 1, &graphics[i * 8]); 155 } 156 for (i = 0; i < TERRAIN_WIDTH; 157 ++i) { 158 terrainUpper[i] = SPRITE_TERRAIN_EMPTY; 159 terrainLower[i] = SPRITE_TERRAIN_EMPTY; 160 161 } 162} 163 164// Slide the terrain to the left in half-character increments 165// 166void 167 advanceTerrain(char* terrain, byte newTerrain){ 168 for (int i = 0; i < TERRAIN_WIDTH; 169 ++i) { 170 char current = terrain[i]; 171 char next = (i == TERRAIN_WIDTH-1) 172 ? newTerrain : terrain[i+1]; 173 switch (current){ 174 case SPRITE_TERRAIN_EMPTY: 175 176 terrain[i] = (next == SPRITE_TERRAIN_SOLID) ? SPRITE_TERRAIN_SOLID_RIGHT 177 : SPRITE_TERRAIN_EMPTY; 178 break; 179 case SPRITE_TERRAIN_SOLID: 180 181 terrain[i] = (next == SPRITE_TERRAIN_EMPTY) ? SPRITE_TERRAIN_SOLID_LEFT 182 : SPRITE_TERRAIN_SOLID; 183 break; 184 case SPRITE_TERRAIN_SOLID_RIGHT: 185 186 terrain[i] = SPRITE_TERRAIN_SOLID; 187 break; 188 case SPRITE_TERRAIN_SOLID_LEFT: 189 190 terrain[i] = SPRITE_TERRAIN_EMPTY; 191 break; 192 } 193 } 194} 195 196bool 197 drawBoy(byte position, char* terrainUpper, char* terrainLower, unsigned int score) 198 { 199 bool collide = false; 200 char upperSave = terrainUpper[BOY_HORIZONTAL_POSITION]; 201 202 char lowerSave = terrainLower[BOY_HORIZONTAL_POSITION]; 203 byte upper, lower; 204 205 switch (position) { 206 case BOY_POSITION_OFF: 207 upper = lower = SPRITE_TERRAIN_EMPTY; 208 209 break; 210 case BOY_POSITION_RUN_LOWER_1: 211 upper = SPRITE_TERRAIN_EMPTY; 212 213 lower = SPRITE_RUN1; 214 break; 215 case BOY_POSITION_RUN_LOWER_2: 216 217 upper = SPRITE_TERRAIN_EMPTY; 218 lower = SPRITE_RUN2; 219 break; 220 221 case BOY_POSITION_JUMP_1: 222 case BOY_POSITION_JUMP_8: 223 upper = 224 SPRITE_TERRAIN_EMPTY; 225 lower = SPRITE_JUMP; 226 break; 227 case 228 BOY_POSITION_JUMP_2: 229 case BOY_POSITION_JUMP_7: 230 upper = SPRITE_JUMP_UPPER; 231 232 lower = SPRITE_JUMP_LOWER; 233 break; 234 case BOY_POSITION_JUMP_3: 235 236 case BOY_POSITION_JUMP_4: 237 case BOY_POSITION_JUMP_5: 238 case BOY_POSITION_JUMP_6: 239 240 upper = SPRITE_JUMP; 241 lower = SPRITE_TERRAIN_EMPTY; 242 break; 243 244 case BOY_POSITION_RUN_UPPER_1: 245 upper = SPRITE_RUN1; 246 lower 247 = SPRITE_TERRAIN_EMPTY; 248 break; 249 case BOY_POSITION_RUN_UPPER_2: 250 251 upper = SPRITE_RUN2; 252 lower = SPRITE_TERRAIN_EMPTY; 253 break; 254 255 } 256 if (upper != ' ') { 257 terrainUpper[BOY_HORIZONTAL_POSITION] = upper; 258 259 collide = (upperSave == SPRITE_TERRAIN_EMPTY) ? false : true; 260 } 261 if 262 (lower != ' ') { 263 terrainLower[BOY_HORIZONTAL_POSITION] = lower; 264 collide 265 |= (lowerSave == SPRITE_TERRAIN_EMPTY) ? false : true; 266 } 267 268 byte digits 269 = (score > 9999) ? 5 : (score > 999) ? 4 : (score > 99) ? 3 : (score > 9) ? 2 : 270 1; 271 272 // Draw the scene 273 terrainUpper[TERRAIN_WIDTH] = '\\0'; 274 terrainLower[TERRAIN_WIDTH] 275 = '\\0'; 276 char temp = terrainUpper[16-digits]; 277 terrainUpper[16-digits] 278 = '\\0'; 279 lcd.setCursor(0,0); 280 lcd.print(terrainUpper); 281 terrainUpper[16-digits] 282 = temp; 283 lcd.setCursor(0,1); 284 lcd.print(terrainLower); 285 286 lcd.setCursor(16 287 - digits,0); 288 lcd.print(score); 289 290 terrainUpper[BOY_HORIZONTAL_POSITION] 291 = upperSave; 292 terrainLower[BOY_HORIZONTAL_POSITION] = lowerSave; 293 return 294 collide; 295} 296 297// Handle the button push as an interrupt 298void buttonPush() 299 { 300 buttonPushed = true; 301} 302 303void setup(){ 304 pinMode(PIN_READWRITE, 305 OUTPUT); 306 digitalWrite(PIN_READWRITE, LOW); 307 pinMode(PIN_CONTRAST, OUTPUT); 308 309 digitalWrite(PIN_CONTRAST, LOW); 310 pinMode(JoyX, INPUT); 311 digitalWrite(JoyX, 312 HIGH); 313 pinMode(PIN_AUTOPLAY, OUTPUT); 314 digitalWrite(PIN_AUTOPLAY, HIGH); 315 316 317 // Digital pin 2 maps to interrupt 0 318 attachInterrupt(0/*PIN_BUTTON*/, 319 buttonPush, FALLING); 320 321 initializeGraphics(); 322 323 lcd.begin(16, 324 2); 325} 326 327void loop(){ 328 static byte boyPos = BOY_POSITION_RUN_LOWER_1; 329 330 static byte newTerrainType = TERRAIN_EMPTY; 331 static byte newTerrainDuration 332 = 1; 333 static bool playing = false; 334 static bool blink = false; 335 static 336 unsigned int distance = 0; 337 338 if (!playing) { 339 drawBoy((blink) ? BOY_POSITION_OFF 340 : boyPos, terrainUpper, terrainLower, distance >> 3); 341 if (blink) { 342 lcd.setCursor(0,0); 343 344 lcd.print("Press Start"); 345 } 346 delay(250); 347 blink = !blink; 348 349 if (buttonPushed) { 350 initializeGraphics(); 351 boyPos = BOY_POSITION_RUN_LOWER_1; 352 353 playing = true; 354 buttonPushed = false; 355 distance = 0; 356 357 } 358 return; 359 } 360 361 // Shift the terrain to the left 362 advanceTerrain(terrainLower, 363 newTerrainType == TERRAIN_LOWER_BLOCK ? SPRITE_TERRAIN_SOLID : SPRITE_TERRAIN_EMPTY); 364 365 advanceTerrain(terrainUpper, newTerrainType == TERRAIN_UPPER_BLOCK ? SPRITE_TERRAIN_SOLID 366 : SPRITE_TERRAIN_EMPTY); 367 368 // Make new terrain to enter on the right 369 370 if (--newTerrainDuration == 0) { 371 if (newTerrainType == TERRAIN_EMPTY) { 372 373 newTerrainType = (random(3) == 0) ? TERRAIN_UPPER_BLOCK : TERRAIN_LOWER_BLOCK; 374 375 newTerrainDuration = 2 + random(10); 376 } else { 377 newTerrainType 378 = TERRAIN_EMPTY; 379 newTerrainDuration = 10 + random(10); 380 } 381 } 382 383 384 if (buttonPushed) { 385 if (boyPos <= BOY_POSITION_RUN_LOWER_2) boyPos 386 = BOY_POSITION_JUMP_1; 387 buttonPushed = false; 388 } 389 390 if (drawBoy(boyPos, 391 terrainUpper, terrainLower, distance >> 3)) { 392 playing = false; // The boy 393 collided with something. Too bad. 394 } else { 395 if (boyPos == BOY_POSITION_RUN_LOWER_2 396 || boyPos == BOY_POSITION_JUMP_8) { 397 boyPos = BOY_POSITION_RUN_LOWER_1; 398 399 } else if ((boyPos >= BOY_POSITION_JUMP_3 && boyPos <= BOY_POSITION_JUMP_5) 400 && terrainLower[BOY_HORIZONTAL_POSITION] != SPRITE_TERRAIN_EMPTY) { 401 boyPos 402 = BOY_POSITION_RUN_UPPER_1; 403 } else if (boyPos >= BOY_POSITION_RUN_UPPER_1 404 && terrainLower[BOY_HORIZONTAL_POSITION] == SPRITE_TERRAIN_EMPTY) { 405 boyPos 406 = BOY_POSITION_JUMP_5; 407 } else if (boyPos == BOY_POSITION_RUN_UPPER_2) { 408 409 boyPos = BOY_POSITION_RUN_UPPER_1; 410 } else { 411 ++boyPos; 412 413 } 414 ++distance; 415 416 digitalWrite(PIN_AUTOPLAY, terrainLower[BOY_HORIZONTAL_POSITION 417 + 2] == SPRITE_TERRAIN_EMPTY ? HIGH : LOW); 418 } 419 delay(100); 420} 421
Downloadable files
Circuit
Circuit
Comments
Only logged in users can leave comments