Components and supplies
Buzzer, Piezo
oled display ssd1309 128x64
Switch Actuator, Head for spring return push-button
Arduino Micro
Project description
Code
InsoDash
arduino
Just add it on an homemade Arduboy and it must works. I don't explain the process for make an homemade Arduboy because it's ever done there.
1#include <Arduboy2.h> 2#include <ArduboyTones.h> 3 4Arduboy2 arduboy; 5ArduboyTones sound(arduboy.audio.enabled); 6 7 8 9#define terreTile 3 10#define videTile 0 11#define playerTile 1 12#define rocherTile 8 13#define diamondTile 7 14#define porteClosedTile 10 15#define wallTile 6 16#define ennemyTile 9 17 18#define screenWidth 128 19#define screenHeight 64 20#define xNbTile 16 21#define yNbTile 8 22 23#define maxLvl 20 24 25const char dataLvl[maxLvl][8][16] PROGMEM ={ 26 { {3,8,3,3,3,3,3,3,3,8,8,3,3,3,3,3}, 27 {3,7,7,7,3,3,3,3,3,3,3,3,3,8,3,3}, 28 {3,3,3,3,3,3,3,3,3,3,3,7,7,7,3,3}, 29 {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}, 30 {3,3,3,0,9,0,3,1,3,3,3,3,3,3,3,3}, 31 {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}, 32 {3,8,3,3,3,3,3,3,3,3,3,3,8,8,3,3}, 33 {3,7,7,7,3,3,3,3,3,3,3,7,7,7,3,3} }, 34 35 { {3,8,8,8,8,3,3,3,3,3,8,3,3,3,3,3}, 36 {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}, 37 {3,7,7,7,7,3,3,6,3,3,7,7,7,3,3,3}, 38 {3,3,3,3,3,3,3,6,3,3,3,3,3,3,3,3}, 39 {3,3,3,3,3,3,3,6,3,3,3,3,3,3,3,3}, 40 {3,3,3,3,8,3,3,6,3,3,3,7,7,7,3,3}, 41 {3,3,3,3,7,3,3,6,3,3,3,8,8,8,3,3}, 42 {3,1,3,3,7,3,3,6,3,3,3,3,3,3,3,3} }, 43 44 { {3,3,3,3,3,3,3,3,3,3,8,3,3,3,3,3}, 45 {3,3,3,3,3,3,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3,3,8}, 202 {3,1,7,6,8,8,8,8,3,3,3,8,3,3,3,7}, 203 {8,3,7,6,3,7,7,7,7,3,3,8,8,8,8,7}, 204 {7,3,3,6,3,3,3,3,3,3,3,3,3,3,3,3}, 205 {7,7,8,6,3,3,3,3,3,3,3,7,7,7,7,3}, 206 {8,3,7,3,3,3,7,7,7,3,8,8,8,3,3,3}, 207 {3,3,3,3,3,3,7,7,7,3,3,3,3,3,3,3}}, 208 209 /* 210 { {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}, 211 {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}, 212 {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}, 213 {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}, 214 {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}, 215 {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}, 216 {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}, 217 {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}, 218 {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}} 219 */ 220 221 222 }; 223 224char currentDataLvl[8][16]; 225char lastCurrentDataLvl[8][16]; 226 227 228const unsigned char PROGMEM mur[] = 229{ 230// width, height, 2318, 8, 2320xff, 0xa5, 0xff, 0xa5, 0xa5, 0xff, 0xa5, 0xff, 233}; 234 235const unsigned char PROGMEM vide[] = 236{ 237// width, height, 2388, 8, 2390x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 240}; 241 242const unsigned char PROGMEM terre[] = 243{ 244// width, height, 2458, 8, 2460x00, 0x00, 0x20, 0x40, 0x02, 0x04, 0x08, 0x00, 247}; 248 249const unsigned char PROGMEM diamant[] = 250{ 251// width, height, 2528, 8, 2530x18, 0x3c, 0x5e, 0xf7, 0xef, 0x7a, 0x3c, 0x18, 254}; 255 256const unsigned char PROGMEM player[] = 257{ 258// width, height, 2598, 8, 2600x20, 0x90, 0xd7, 0x7d, 0x7d, 0xd7, 0x90, 0x08, 261}; 262 263const unsigned char PROGMEM player1[] = 264{ 265// width, height, 2668, 8, 2670x08, 0x92, 0xd5, 0x7f, 0x7f, 0xd5, 0x92, 0x20, 268}; 269 270const unsigned char PROGMEM rocher[] = 271{ 272// width, height, 2738, 8, 2740x3c, 0x6e, 0xdb, 0xb7, 0xed, 0xdb, 0x76, 0x3c, 275}; 276 277const unsigned char PROGMEM ennemy[] = 278{ 279// width, height, 2808, 8, 2810x89, 0xd2, 0x7d, 0x36, 0x36, 0x7d, 0xd2, 0x89, 282}; 283 284const unsigned char PROGMEM ennemy1[] = 285{ 286// width, height, 2878, 8, 2880x88, 0xd0, 0x7d, 0x36, 0x36, 0x7d, 0xd0, 0xa0, 289}; 290 291const unsigned char PROGMEM ennemy2[] = 292{ 293// width, height, 2948, 8, 2950x88, 0xd2, 0x7d, 0x36, 0x36, 0x7d, 0xd2, 0x88, 296}; 297 298 299 300char playerX; 301char playerY; 302bool playerFrame = 1; 303char ennemyFrame = 0; 304 305 306 307char life = 5; 308char iLvl = 0; 309bool beginLvl = 1; 310bool gameOver = 0; 311bool youWin = 0; 312 313void setup() { 314 Serial.begin(9600); 315 arduboy.begin(); 316 arduboy.clear(); 317} 318 319void loop() { 320 //arduboy.clear(); 321 322 if ( beginLvl ){ 323 initLvl(); 324 beginLvl= 0; 325 } 326 else if(youWin){ 327 sound.tone(NOTE_E5,50); 328 delay(160); 329 arduboy.clear(); 330 arduboy.setCursor(0, 15); 331 arduboy.setTextSize(1); 332 arduboy.print("YOU WIN!! "); 333 arduboy.display(); 334 sound.tone(NOTE_E5,50); 335 sound.tone(NOTE_E5,50); 336 delay(300); 337 delay(500); 338 if(iLvl < maxLvl){ 339 iLvl++; 340 youWin = 0; 341 beginLvl = 1; 342 } 343 } 344 else if (gameOver){ 345 life--; 346 sound.tone(NOTE_A1,150); 347 delay(160); 348 arduboy.clear(); 349 arduboy.setCursor(0, 15); 350 arduboy.setTextSize(1); 351 if (life > 0 ){ 352 arduboy.print("You Loose !! "); 353 } 354 else{ 355 arduboy.print("GAME OVER!! "); 356 } 357 arduboy.display(); 358 delay(300); 359 delay(500); 360 if (life > 0){ 361 beginLvl = 1; 362 gameOver = 0; 363 } 364 else{ 365 life = 5; 366 iLvl = 0; 367 beginLvl = 1; 368 gameOver = 0; 369 } 370 } 371 else{ 372 for (uint8_t i = 0 ; i < 5 ; i ++ ){ 373 controls(); 374 drawLvl(); 375 delay(60); 376 } 377 game(); 378 drawLvl(); 379 delay(60); 380 } 381 382} 383 384 385void game(){ 386 uint8_t nbDiamond = 0; 387 for(uint8_t j = 0; j < yNbTile ; j++ ){ 388 for(uint8_t i = 0 ; i < xNbTile ; i++){ 389 if( currentDataLvl[j][i] == diamondTile ){ 390 nbDiamond++; 391 } 392 } 393 } 394 if (nbDiamond == 0){ 395 youWin = 1; 396 } 397 else{ 398 for(uint8_t j = 0; j < yNbTile ; j++ ){ 399 for(uint8_t i = 0 ; i < xNbTile ; i++){ 400 if( currentDataLvl[j][i] == diamondTile ){ 401 nbDiamond++; 402 } 403 if( currentDataLvl[j][i] == rocherTile || currentDataLvl[j][i] == diamondTile ){ 404 if (j < yNbTile - 1 ){ 405 if(currentDataLvl[j +1][i] == videTile || currentDataLvl[j +1][i] == ennemyTile ){ 406 if( j < yNbTile - 2 && currentDataLvl[j + 2][i] == 1 ){ 407 gameOver = 1; 408 } 409 if(currentDataLvl[j +1][i] == ennemyTile ){ 410 sound.tone(NOTE_D3,20); 411 } 412 sound.tone(NOTE_A1,65); 413 currentDataLvl[j +1][i] = currentDataLvl[j][i]; 414 currentDataLvl[j][i] = 0; 415 drawLvl(); 416 } 417 } 418 } 419 else if( currentDataLvl[j][i] == ennemyTile ){ 420 uint8_t rndEnnemyMvt = rand() % 4; 421 switch( rndEnnemyMvt ){ 422 case 0 : 423 //Droite 424 if( i < xNbTile - 2 && ( currentDataLvl[j][i+1] == videTile || currentDataLvl[j][i+1] == playerTile ) ){ 425 if ( currentDataLvl[j][i+1] == playerTile){ 426 gameOver = 1; 427 } 428 currentDataLvl[j][i] = videTile; 429 currentDataLvl[j][i+1] = ennemyTile; 430 drawLvl(); 431 } 432 break; 433 case 1 : 434 //Gauche 435 if( i > 1 && ( currentDataLvl[j][i-1] == videTile || currentDataLvl[j][i-1] == playerTile )){ 436 if ( currentDataLvl[j][i-1] == playerTile){ 437 gameOver = 1; 438 } 439 currentDataLvl[j][i] = videTile; 440 currentDataLvl[j][i-1] = ennemyTile; 441 drawLvl(); 442 } 443 break; 444 case 2 : 445 //Haut 446 if( j > 1 && ( currentDataLvl[j-1][i] == videTile || currentDataLvl[j-1][i] == playerTile ) ){ 447 if ( currentDataLvl[j-1][i] == playerTile){ 448 gameOver = 1; 449 } 450 currentDataLvl[j][i] = videTile; 451 currentDataLvl[j-1][i] = ennemyTile; 452 drawLvl(); 453 } 454 break; 455 case 3 : 456 //Bas 457 if( j < yNbTile - 2 && ( currentDataLvl[j+1][i] == videTile || currentDataLvl[j+1][i] == playerTile ) ){ 458 if ( currentDataLvl[j+1][i] == playerTile){ 459 gameOver = 1; 460 } 461 currentDataLvl[j][i] = videTile; 462 currentDataLvl[j+1][i] = ennemyTile; 463 drawLvl(); 464 } 465 break; 466 } 467 468 } 469 470 } 471 } 472 473 } 474 if (ennemyFrame > 4 ){ 475 ennemyFrame = 0; 476 } 477 478 ennemyFrame++; 479} 480 481 482void controls(){ 483 484 bool controlsActivated = 0; 485 486 uint8_t lastX = playerX; 487 uint8_t lastY = playerY; 488 489 490 if (arduboy.pressed(A_BUTTON) ){ 491 gameOver = 1; 492 controlsActivated = 0; 493 494 } 495 496 if (arduboy.pressed(LEFT_BUTTON) && playerX > 0 ) { 497 playerX = playerX - 1; 498 controlsActivated = 1; 499 } 500 if (arduboy.pressed(RIGHT_BUTTON) && playerX < xNbTile - 1 ) { 501 playerX = playerX + 1; 502 controlsActivated = 1; 503 } 504 if (arduboy.pressed(UP_BUTTON) && playerY > 0 ) { 505 playerY = playerY - 1; 506 controlsActivated = 1; 507 } 508 if (arduboy.pressed(DOWN_BUTTON) && playerY < yNbTile - 1 ) { 509 playerY = playerY + 1; 510 controlsActivated = 1; 511 512 } 513 514 515 bool mvtPossible = 0; 516 if(controlsActivated){ 517 playerFrame = ! playerFrame; 518 if( currentDataLvl[playerY][playerX] == terreTile || currentDataLvl[playerY][playerX] == videTile || currentDataLvl[playerY][playerX] == diamondTile || currentDataLvl[playerY][playerX] == ennemyTile ){ 519 mvtPossible = 1; 520 if( currentDataLvl[playerY][playerX] == diamondTile ){ 521 sound.tone(NOTE_E5,50); 522 } 523 if( currentDataLvl[playerY][playerX] == ennemyTile){ 524 gameOver = 1; 525 sound.tone(NOTE_C3,110); 526 mvtPossible = 0; 527 currentDataLvl[lastY][lastX] = videTile; 528 } 529 } 530 else if(currentDataLvl[playerY][playerX] == rocherTile ){ 531 if(lastX > playerX && playerX > 1 ){ 532 if ( currentDataLvl[playerY][playerX - 1 ] == videTile ){ 533 currentDataLvl[playerY][playerX - 1 ] = rocherTile; 534 mvtPossible = 1; 535 } 536 } 537 else if (lastX < playerX && playerX < xNbTile - 2 ){ 538 if ( currentDataLvl[playerY][playerX + 1 ] == videTile ){ 539 currentDataLvl[playerY][playerX + 1 ] = rocherTile; 540 mvtPossible = 1; 541 } 542 } 543 } 544 if( mvtPossible == 1){ 545 currentDataLvl[lastY][lastX] = videTile; 546 currentDataLvl[playerY][playerX] = playerTile; 547 } 548 else { 549 playerX = lastX; 550 playerY = lastY; 551 } 552 debugLvl(); 553 } 554} 555 556 557void debugLvl(){ 558 for(uint8_t j = 0; j < yNbTile ; j++ ){ 559 for(uint8_t i = 0 ; i < xNbTile ; i++){ 560 uint8_t posXSprite = ( screenWidth / xNbTile ) * i; 561 uint8_t posYSprite = (screenHeight / xNbTile ) * j; 562 563 Serial.print(uint8_t( currentDataLvl[j][i] )); 564 Serial.print(","); 565 } 566 Serial.println(); 567 } 568 Serial.println("\ 569"); 570 Serial.println("\ 571"); 572 Serial.println("\ 573"); 574 575} 576void drawLvl(){ 577 for(uint8_t j = 0; j < yNbTile ; j++ ){ 578 for(uint8_t i = 0 ; i < xNbTile ; i++){ 579 if (lastCurrentDataLvl[j][i] != currentDataLvl[j][i] || currentDataLvl[j][i] == ennemyTile || currentDataLvl[j][i] == playerTile){ 580 uint8_t posXSprite = ( screenWidth / xNbTile ) * i; 581 uint8_t posYSprite = (screenHeight / yNbTile ) * j; 582 unsigned char sprite; 583 switch ( currentDataLvl[j][i] ){ 584 case terreTile : 585 drawSprite( posXSprite, posYSprite, terre, 0 ); 586 break; 587 case playerTile : 588 if(playerFrame == 0 ){ 589 drawSprite( posXSprite, posYSprite, player , 0 ); 590 } 591 else{ 592 drawSprite( posXSprite, posYSprite, player1 , 0 ); 593 } 594 break; 595 case rocherTile : 596 drawSprite( posXSprite, posYSprite, rocher , 0 ); 597 break; 598 case videTile : 599 drawSprite( posXSprite, posYSprite, vide , 0 ); 600 break; 601 case wallTile : 602 drawSprite( posXSprite, posYSprite, mur , 0 ); 603 break; 604 case diamondTile : 605 drawSprite( posXSprite, posYSprite, diamant , 0 ); 606 break; 607 case ennemyTile : 608 switch( ennemyFrame % 3 ){ 609 case 0: 610 drawSprite( posXSprite, posYSprite, ennemy, 0 ); 611 break; 612 case 1: 613 drawSprite( posXSprite, posYSprite, ennemy1, 0 ); 614 break; 615 case 2: 616 drawSprite( posXSprite, posYSprite, ennemy2, 0 ); 617 break; 618 } 619 break; 620 } 621 lastCurrentDataLvl[j][i] = currentDataLvl[j][i]; 622 } 623 } 624 } 625 arduboy.display(); 626} 627 628 629void initLvl(){ 630 for(uint8_t j = 0; j < 8 ; j++ ){ 631 for(uint8_t i = 0 ; i < 16 ; i++){ 632 if ( uint8_t pgm_read_word(&dataLvl[iLvl][j][i]) == playerTile ){ 633 playerX = i; 634 playerY = j; 635 } 636 currentDataLvl[j][i] = pgm_read_word(&dataLvl[iLvl][j][i]); 637 lastCurrentDataLvl[j][i] = -1; 638 } 639 } 640} 641 642void drawSprite(uint8_t posX, uint8_t posY, unsigned char *sprite, uint8_t nolose ){ 643 Sprites::drawOverwrite(posX, posY, sprite, 0); 644}
Comments
Only logged in users can leave comments
hilaireguillaume
0 Followers
•0 Projects
Table of contents
Intro
0
0