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