Hilaire Guillaume
Published

Remake of Boulder Dash Game for Homemade Arduboy

It's a remake of the Boulder Dash game made for a homemade Arduboy.

BeginnerFull instructions provided1,539
Remake of Boulder Dash Game for Homemade Arduboy

Things used in this project

Hardware components

Arduino Micro
Arduino Micro
×1
Switch Actuator, Head for spring return push-button
Switch Actuator, Head for spring return push-button
×6
Buzzer, Piezo
Buzzer, Piezo
×1
oled display ssd1309 128x64
×1

Story

Read more

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.
#include <Arduboy2.h>
#include <ArduboyTones.h>

Arduboy2 arduboy;
ArduboyTones sound(arduboy.audio.enabled);



#define terreTile  3
#define videTile  0
#define playerTile  1
#define rocherTile  8
#define diamondTile  7
#define porteClosedTile  10
#define wallTile  6
#define ennemyTile  9

#define screenWidth  128
#define screenHeight  64
#define xNbTile  16
#define yNbTile  8

#define maxLvl  20

const  char dataLvl[maxLvl][8][16] PROGMEM ={
             { {3,8,3,3,3,3,3,3,3,8,8,3,3,3,3,3},
              {3,7,7,7,3,3,3,3,3,3,3,3,3,8,3,3},
              {3,3,3,3,3,3,3,3,3,3,3,7,7,7,3,3},
              {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
              {3,3,3,0,9,0,3,1,3,3,3,3,3,3,3,3},
              {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
              {3,8,3,3,3,3,3,3,3,3,3,3,8,8,3,3},
              {3,7,7,7,3,3,3,3,3,3,3,7,7,7,3,3} },
              
            { {3,8,8,8,8,3,3,3,3,3,8,3,3,3,3,3},
              {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
              {3,7,7,7,7,3,3,6,3,3,7,7,7,3,3,3},
              {3,3,3,3,3,3,3,6,3,3,3,3,3,3,3,3},
              {3,3,3,3,3,3,3,6,3,3,3,3,3,3,3,3},
              {3,3,3,3,8,3,3,6,3,3,3,7,7,7,3,3},
              {3,3,3,3,7,3,3,6,3,3,3,8,8,8,3,3},
              {3,1,3,3,7,3,3,6,3,3,3,3,3,3,3,3} },
              
            { {3,3,3,3,3,3,3,3,3,3,8,3,3,3,3,3},
              {3,3,3,3,3,3,3,3,3,3,7,3,3,3,3,3},
              {3,3,3,3,3,0,9,0,3,3,7,3,3,3,3,3},
              {3,3,8,3,3,3,3,3,3,3,7,3,3,3,3,3},
              {3,3,3,3,3,3,3,6,3,3,3,3,3,3,3,3},
              {3,3,7,3,3,3,3,6,3,3,3,3,3,3,3,3},
              {3,3,7,3,3,3,3,6,6,6,6,6,6,6,6,6},
              {3,3,7,3,3,3,3,3,3,3,3,3,3,1,3,3} },
              
           { {3,3,3,8,8,8,3,3,3,3,3,3,3,3,3,3},
              {3,3,3,3,3,3,3,3,3,7,7,7,3,3,3,3},
              {3,3,3,0,9,0,3,3,3,3,3,3,3,3,3,3},
              {3,3,3,7,7,7,3,3,3,3,3,3,3,3,3,3},
              {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
              {3,3,3,8,8,8,3,3,3,3,3,3,3,1,3,3},
              {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
              {3,3,3,7,7,7,3,3,3,3,3,3,3,3,3,3}},
              
            
            
              { {3,3,3,8,8,8,8,3,3,3,6,3,3,3,3,3},
              {8,3,3,7,7,7,7,3,3,3,6,3,3,8,8,3},
              {7,3,3,3,3,3,3,3,3,3,6,3,3,7,7,3},
              {7,3,3,3,6,3,3,3,3,3,6,8,8,3,3,3},
              {7,3,3,8,6,3,3,3,3,3,6,7,7,3,3,3},
              {3,3,3,7,6,3,3,3,3,3,6,3,3,3,3,3},
              {3,3,3,7,6,8,8,8,3,3,6,6,6,6,3,3},
              {3,1,3,3,6,0,0,9,3,3,7,7,7,7,3,3}},
                
            { {1,3,3,3,3,7,7,7,3,3,3,3,3,3,3,8},
              {3,3,3,3,3,7,7,7,3,3,3,3,3,7,7,7},
              {6,6,6,6,6,6,6,6,6,6,6,6,3,3,3,3},
              {8,8,3,3,7,7,7,7,3,3,3,3,3,3,8,8},
              {3,3,3,3,3,3,3,3,3,3,3,3,3,3,7,7},
              {3,3,3,3,3,6,6,6,6,6,6,6,6,6,6,6},
              {3,3,3,3,3,7,7,7,3,3,3,3,6,3,3,3},
              {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}},

              
              { {3,3,3,3,3,8,7,7,7,7,3,3,3,3,8,8},
              {3,3,3,8,3,3,3,3,3,3,3,3,3,3,7,7},
              {3,3,3,7,6,6,6,6,6,6,6,8,3,3,3,3},
              {3,3,3,7,6,3,3,3,8,8,6,7,3,3,3,3},
              {3,3,3,7,6,7,7,7,7,7,6,7,3,3,3,3},
              {9,3,3,3,6,3,3,3,3,3,6,7,3,3,3,9},
              {0,8,8,3,6,6,6,3,6,6,6,3,8,8,8,0},
              {3,0,0,3,3,3,3,1,3,3,3,3,0,0,0,3}},
              
              { {3,8,8,8,3,3,3,3,3,8,8,3,3,8,8,8},
              {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
              {3,0,9,0,3,3,3,3,3,3,3,3,3,0,9,0},
              {3,7,7,7,3,3,8,8,8,8,8,3,3,7,7,7},
              {3,6,6,6,6,3,7,7,7,7,7,3,6,6,6,6},
              {3,6,8,8,6,3,3,3,3,3,3,3,6,8,8,6},
              {3,6,6,6,6,3,3,3,1,3,3,3,6,6,6,6},
              {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}},
              
              { {3,3,3,3,3,3,3,3,8,8,3,8,3,3,3,3},
              {3,3,3,8,3,3,3,3,7,7,3,3,3,3,3,8},
              {3,3,3,3,3,3,3,3,3,3,3,0,3,3,3,7},
              {8,8,3,0,3,3,3,8,3,3,3,0,3,3,3,3},
              {7,7,3,9,3,3,3,3,3,3,3,9,3,8,8,3},
              {7,7,3,0,3,3,3,0,3,3,3,3,3,7,7,3},
              {3,3,3,3,3,3,3,0,3,3,3,8,8,3,3,3},
              {3,3,3,3,3,3,3,0,3,3,7,7,7,3,3,1}},
              
              { {3,3,8,8,8,3,6,3,8,3,6,3,3,8,8,8},
              {7,7,7,7,7,3,6,3,7,3,6,7,7,7,7,7},
              {3,3,3,3,3,3,6,3,7,3,6,3,3,3,3,3},
              {6,6,6,6,6,3,6,3,7,3,6,3,6,6,6,6},
              {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
              {3,8,8,3,3,3,1,3,3,3,6,3,6,6,6,6},
              {3,3,3,3,3,3,3,3,3,3,6,3,7,7,7,7},
              {3,3,3,3,3,0,9,0,3,3,6,3,3,3,3,3}},
              
            { {1,3,3,8,8,8,3,8,8,8,8,3,7,7,3,3},
              {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
              {3,3,8,0,9,0,8,0,9,0,0,8,3,3,3,3},
              {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
              {3,3,9,3,7,3,9,3,7,3,3,9,3,3,8,8},
              {3,3,0,3,7,3,0,3,7,3,3,0,3,3,7,7},
              {3,3,0,3,7,3,0,3,7,3,3,0,3,3,7,7},
              {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}},
            
              { {7,7,7,3,6,8,8,8,8,8,8,6,3,7,7,7},
              {3,8,3,3,6,7,7,7,7,7,7,6,3,3,8,3},
              {3,3,3,3,6,3,7,7,7,7,3,6,3,3,3,3},
              {3,9,3,3,6,3,3,3,3,3,3,6,3,3,9,3},
              {3,0,3,3,6,6,6,3,3,6,6,6,3,3,0,3},
              {3,0,3,3,7,7,3,3,3,7,7,3,3,3,0,3},
              {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
              {3,3,3,3,3,1,3,3,3,3,3,3,3,3,3,3}},

              { {3,3,3,3,3,3,8,8,7,7,3,3,3,8,3,3},
              {3,3,3,3,3,3,7,7,3,3,3,3,3,3,3,3},
              {6,6,6,6,6,6,6,6,6,6,3,3,3,0,3,3},
              {3,8,3,8,3,3,3,7,7,7,7,3,3,9,3,3},
              {3,3,3,3,3,3,6,6,6,6,6,6,6,6,6,6},
              {3,9,3,9,3,3,8,8,8,8,8,8,8,8,8,8},
              {3,0,3,0,3,3,7,7,7,7,7,7,7,7,3,3},
              {3,0,3,0,3,3,3,3,3,3,3,3,3,3,3,1}},

              { {3,3,3,3,6,3,7,7,7,3,3,3,3,6,8,8},
              {6,6,6,6,6,3,3,3,3,3,3,3,3,6,6,6},
              {7,7,3,3,3,3,0,3,0,3,3,3,3,3,3,7},
              {7,7,3,3,3,3,0,3,0,3,3,3,3,3,3,7},
              {6,6,6,6,3,3,9,3,9,3,3,3,6,6,6,6},
              {8,8,8,6,3,3,3,3,3,3,3,3,6,3,8,8},
              {7,7,7,6,3,3,3,3,3,3,3,3,6,3,7,7},
              {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1}},
              
            { {8,8,3,3,3,3,3,1,3,3,3,3,3,8,8,8},
              {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
              {0,0,0,9,6,6,6,6,6,6,6,0,0,0,0,9},
              {3,3,3,3,6,8,8,8,8,8,6,3,3,3,3,3},
              {3,8,3,3,6,7,7,7,7,7,6,3,3,3,3,8},
              {3,3,3,3,6,3,3,3,3,3,6,3,3,3,3,3},
              {7,0,3,3,6,6,3,3,6,6,6,3,3,3,3,0},
              {7,0,3,3,7,7,3,3,7,7,7,3,3,3,3,0}},

              { {1,3,3,3,6,8,3,8,8,3,3,3,3,3,8,8},
              {3,3,8,8,6,3,3,7,7,3,3,3,3,3,7,7},
              {3,3,7,7,6,9,3,3,3,3,3,3,3,3,3,3},
              {3,3,7,7,6,0,3,3,6,6,6,6,6,6,3,3},
              {3,3,7,7,6,3,3,3,6,3,3,3,8,8,8,3},
              {3,3,3,3,6,7,7,3,6,3,3,3,7,7,7,3},
              {3,3,8,8,6,7,7,3,6,3,3,3,8,8,8,3},
              {3,3,3,3,3,3,3,3,6,3,3,3,7,7,7,3}},

               { {3,3,8,8,8,3,8,8,8,3,8,8,8,3,8,8},
                {1,3,7,7,7,3,7,7,7,3,7,7,7,3,7,7},
                {3,3,3,3,8,8,8,3,8,8,8,3,8,8,8,3},
                {3,3,8,3,7,7,7,3,7,7,7,3,7,7,7,3},
                {8,3,8,7,3,3,3,3,3,3,3,3,3,3,3,3},
                {8,3,8,7,3,3,8,3,8,3,8,3,8,3,8,3},
                {3,3,7,7,3,3,8,3,8,3,8,3,8,3,8,3},
                {3,3,7,3,3,3,7,7,7,3,7,7,7,3,7,7}},

                { {3,3,3,3,8,6,8,8,8,3,3,8,8,6,3,3},
                {3,1,3,3,7,6,7,7,7,3,3,7,7,6,3,3},
                {3,8,8,3,7,6,3,3,8,3,3,7,7,6,3,8},
                {3,7,7,3,7,6,3,3,7,6,3,7,7,6,3,3},
                {3,7,7,3,7,6,3,3,7,6,3,3,3,6,8,3},
                {3,3,3,3,7,6,3,3,7,6,3,3,3,6,7,3},
                {3,3,3,3,7,3,3,3,3,6,3,3,3,6,7,3},
                {3,3,3,3,3,3,3,3,3,6,7,3,3,3,3,3}},

            { {8,8,3,3,3,6,3,3,3,3,8,8,8,8,7,8},
              {7,7,8,8,8,6,3,3,3,7,7,7,7,7,7,8},
              {7,7,7,7,7,6,3,3,3,3,3,3,3,3,3,3},
              {7,7,8,8,8,6,6,6,6,6,6,6,6,8,3,3},
              {3,3,7,7,7,3,3,8,8,8,8,8,8,8,3,3},
              {8,3,7,7,7,3,3,7,7,7,7,7,7,7,3,3},
              {8,3,7,7,7,3,3,3,3,3,3,3,3,3,3,3},
              {3,1,3,3,3,3,3,8,8,8,8,3,3,3,3,3}},

            { {8,8,8,6,3,3,8,8,8,8,8,7,7,7,7,8},
              {3,3,7,6,3,3,3,3,3,7,7,3,3,3,3,8},
              {3,1,7,6,8,8,8,8,3,3,3,8,3,3,3,7},
              {8,3,7,6,3,7,7,7,7,3,3,8,8,8,8,7},
              {7,3,3,6,3,3,3,3,3,3,3,3,3,3,3,3},
              {7,7,8,6,3,3,3,3,3,3,3,7,7,7,7,3},
              {8,3,7,3,3,3,7,7,7,3,8,8,8,3,3,3},
              {3,3,3,3,3,3,7,7,7,3,3,3,3,3,3,3}},

           /*
              { {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
              {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
              {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
              {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
              {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
              {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
              {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
              {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
              {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}}
              */
         

  };

char currentDataLvl[8][16];
char lastCurrentDataLvl[8][16];


const unsigned char PROGMEM mur[] =
{
// width, height,
8, 8,
0xff, 0xa5, 0xff, 0xa5, 0xa5, 0xff, 0xa5, 0xff, 
};

const unsigned char PROGMEM vide[] =
{
// width, height,
8, 8,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
};

const unsigned char PROGMEM terre[] =
{
// width, height,
8, 8,
0x00, 0x00, 0x20, 0x40, 0x02, 0x04, 0x08, 0x00, 
};

const unsigned char PROGMEM diamant[] =
{
// width, height,
8, 8,
0x18, 0x3c, 0x5e, 0xf7, 0xef, 0x7a, 0x3c, 0x18, 
};

const unsigned char PROGMEM player[] =
{
// width, height,
8, 8,
0x20, 0x90, 0xd7, 0x7d, 0x7d, 0xd7, 0x90, 0x08, 
};

const unsigned char PROGMEM player1[] =
{
// width, height,
8, 8,
0x08, 0x92, 0xd5, 0x7f, 0x7f, 0xd5, 0x92, 0x20, 
};

const unsigned char PROGMEM rocher[] =
{
// width, height,
8, 8,
0x3c, 0x6e, 0xdb, 0xb7, 0xed, 0xdb, 0x76, 0x3c, 
};

const unsigned char PROGMEM ennemy[] =
{
// width, height,
8, 8,
0x89, 0xd2, 0x7d, 0x36, 0x36, 0x7d, 0xd2, 0x89, 
};

const unsigned char PROGMEM ennemy1[] =
{
// width, height,
8, 8,
0x88, 0xd0, 0x7d, 0x36, 0x36, 0x7d, 0xd0, 0xa0, 
};

const unsigned char PROGMEM ennemy2[] =
{
// width, height,
8, 8,
0x88, 0xd2, 0x7d, 0x36, 0x36, 0x7d, 0xd2, 0x88, 
};



char playerX;
char playerY;
bool playerFrame = 1;
char ennemyFrame = 0;



char life = 5;
char iLvl = 0;
bool beginLvl = 1;
bool gameOver = 0;
bool youWin = 0;

void setup() {
  Serial.begin(9600);
  arduboy.begin();
  arduboy.clear();
}

void loop() {
  //arduboy.clear(); 
  
  if ( beginLvl ){
    initLvl();
    beginLvl= 0;
  }
  else if(youWin){
    sound.tone(NOTE_E5,50);
    delay(160);
    arduboy.clear();
    arduboy.setCursor(0, 15);
    arduboy.setTextSize(1);
    arduboy.print("YOU WIN!! ");
    arduboy.display();
    sound.tone(NOTE_E5,50);
    sound.tone(NOTE_E5,50);
    delay(300);
    delay(500);
    if(iLvl < maxLvl){
      iLvl++;
      youWin = 0;
      beginLvl = 1;
    }
  }
  else  if (gameOver){
    life--;
    sound.tone(NOTE_A1,150);
    delay(160);
    arduboy.clear();
    arduboy.setCursor(0, 15);
    arduboy.setTextSize(1);
    if (life > 0 ){
        arduboy.print("You Loose !! ");
    }
    else{
        arduboy.print("GAME OVER!! ");
    }
    arduboy.display();
    delay(300);
    delay(500);
    if (life > 0){
      beginLvl = 1;
      gameOver = 0;
    }
    else{
      life = 5;
      iLvl = 0;
      beginLvl = 1;
      gameOver = 0;
    }
  }
  else{
    for (uint8_t i = 0 ; i < 5 ; i ++ ){
      controls();
      drawLvl();
      delay(60);  
    }
    game();
    drawLvl();
    delay(60);  
  }
 
}


void game(){
  uint8_t nbDiamond = 0;
  for(uint8_t j = 0; j < yNbTile ; j++ ){
    for(uint8_t i = 0 ; i < xNbTile ; i++){
      if( currentDataLvl[j][i] == diamondTile ){
        nbDiamond++; 
      }
    }
  }
  if (nbDiamond == 0){
    youWin = 1;
  }
  else{
    for(uint8_t j = 0; j < yNbTile ; j++ ){
      for(uint8_t i = 0 ; i < xNbTile ; i++){
        if( currentDataLvl[j][i] == diamondTile ){
          nbDiamond++; 
        }
        if( currentDataLvl[j][i] == rocherTile || currentDataLvl[j][i] == diamondTile ){
              if (j < yNbTile - 1 ){
                if(currentDataLvl[j +1][i] == videTile || currentDataLvl[j +1][i] == ennemyTile ){
                  if( j < yNbTile - 2 && currentDataLvl[j + 2][i] == 1 ){
                    gameOver = 1;
                  }
                  if(currentDataLvl[j +1][i] == ennemyTile ){
                    sound.tone(NOTE_D3,20);  
                  }
                  sound.tone(NOTE_A1,65);
                  currentDataLvl[j +1][i] = currentDataLvl[j][i];
                  currentDataLvl[j][i] = 0; 
                  drawLvl();
                }  
              }
        }
        else if( currentDataLvl[j][i] == ennemyTile ){
          uint8_t rndEnnemyMvt = rand() % 4;
          switch( rndEnnemyMvt ){
            case 0 :
              //Droite
              if( i < xNbTile - 2 && ( currentDataLvl[j][i+1] == videTile || currentDataLvl[j][i+1] == playerTile ) ){
                  if ( currentDataLvl[j][i+1] == playerTile){
                    gameOver = 1;
                  }
                  currentDataLvl[j][i] = videTile;
                  currentDataLvl[j][i+1] = ennemyTile;
                  drawLvl();
              }
              break;
            case 1 :
              //Gauche
              if( i > 1 && ( currentDataLvl[j][i-1] == videTile || currentDataLvl[j][i-1] == playerTile )){
                  if ( currentDataLvl[j][i-1] == playerTile){
                    gameOver = 1;
                  }
                  currentDataLvl[j][i] = videTile;
                  currentDataLvl[j][i-1] = ennemyTile;
                  drawLvl();
              }
              break;
            case 2 :
              //Haut
              if( j > 1  && ( currentDataLvl[j-1][i] == videTile || currentDataLvl[j-1][i] == playerTile ) ){
                  if ( currentDataLvl[j-1][i] == playerTile){
                    gameOver = 1;
                  }
                  currentDataLvl[j][i] = videTile;
                  currentDataLvl[j-1][i] = ennemyTile;
                  drawLvl();
              }
              break;
            case 3 :
              //Bas
              if( j < yNbTile - 2 && ( currentDataLvl[j+1][i] == videTile || currentDataLvl[j+1][i] == playerTile ) ){
                  if ( currentDataLvl[j+1][i] == playerTile){
                    gameOver = 1;
                  }
                  currentDataLvl[j][i] = videTile;
                  currentDataLvl[j+1][i] = ennemyTile;
                  drawLvl();
              }
              break;
          }
          
        }
        
      }
    }
  
  }
  if (ennemyFrame > 4 ){
    ennemyFrame = 0;
  }
  
  ennemyFrame++;
}


void controls(){

  bool controlsActivated = 0;
  
  uint8_t lastX = playerX;
  uint8_t lastY = playerY;


  if (arduboy.pressed(A_BUTTON) ){
    gameOver = 1;
    controlsActivated  = 0;
      
  }
  
  if (arduboy.pressed(LEFT_BUTTON) && playerX > 0 ) {
    playerX = playerX - 1;
    controlsActivated  = 1;
  }
  if (arduboy.pressed(RIGHT_BUTTON) && playerX < xNbTile - 1 ) {
      playerX = playerX + 1;
      controlsActivated  = 1;
  }
  if (arduboy.pressed(UP_BUTTON) && playerY > 0 ) {
      playerY = playerY - 1;
      controlsActivated  = 1;
  }
  if (arduboy.pressed(DOWN_BUTTON) && playerY < yNbTile - 1 ) {
      playerY = playerY + 1;
      controlsActivated  = 1;

  }


  bool mvtPossible = 0;
  if(controlsActivated){
    playerFrame = ! playerFrame;
    if( currentDataLvl[playerY][playerX] == terreTile || currentDataLvl[playerY][playerX] == videTile || currentDataLvl[playerY][playerX] == diamondTile || currentDataLvl[playerY][playerX] == ennemyTile ){
          mvtPossible = 1;
      if( currentDataLvl[playerY][playerX] == diamondTile ){
         sound.tone(NOTE_E5,50);
      }
      if( currentDataLvl[playerY][playerX] == ennemyTile){
        gameOver = 1;
        sound.tone(NOTE_C3,110);
        mvtPossible = 0;  
        currentDataLvl[lastY][lastX] = videTile;
      }
    }
    else if(currentDataLvl[playerY][playerX] == rocherTile ){
         if(lastX > playerX && playerX > 1 ){
            if ( currentDataLvl[playerY][playerX - 1 ] == videTile ){
                 currentDataLvl[playerY][playerX - 1 ] = rocherTile;
                 mvtPossible = 1;
            }
         }
         else if (lastX < playerX && playerX < xNbTile - 2 ){
          if ( currentDataLvl[playerY][playerX + 1 ] == videTile ){
              currentDataLvl[playerY][playerX + 1 ] = rocherTile;
              mvtPossible = 1;
            }
         }
    }
    if( mvtPossible == 1){
      currentDataLvl[lastY][lastX] = videTile;
      currentDataLvl[playerY][playerX] = playerTile;  
    }
    else {
      playerX = lastX;
      playerY = lastY;
    }
    debugLvl();
  }
}


void debugLvl(){
  for(uint8_t j = 0; j < yNbTile ; j++ ){
    for(uint8_t i = 0 ; i < xNbTile ; i++){
      uint8_t posXSprite = ( screenWidth / xNbTile ) * i;
      uint8_t posYSprite = (screenHeight / xNbTile ) * j;

      Serial.print(uint8_t( currentDataLvl[j][i] ));
      Serial.print(",");
    }
    Serial.println();
  }
  Serial.println("\n");
  Serial.println("\n");
  Serial.println("\n");
  
}
void drawLvl(){
  for(uint8_t j = 0; j < yNbTile ; j++ ){
    for(uint8_t i = 0 ; i < xNbTile ; i++){
      if (lastCurrentDataLvl[j][i] != currentDataLvl[j][i] || currentDataLvl[j][i] == ennemyTile || currentDataLvl[j][i] == playerTile){
        uint8_t posXSprite = ( screenWidth / xNbTile ) * i;
        uint8_t posYSprite = (screenHeight / yNbTile ) * j;
        unsigned char  sprite;
        switch ( currentDataLvl[j][i] ){
            case terreTile : 
              drawSprite( posXSprite, posYSprite, terre, 0 );
              break;
            case playerTile :
              if(playerFrame == 0 ){
                drawSprite( posXSprite, posYSprite, player , 0 );  
              }
              else{
                drawSprite( posXSprite, posYSprite, player1 , 0 );
              }
              break;
            case rocherTile :
              drawSprite( posXSprite, posYSprite, rocher , 0 );
              break;
            case videTile : 
              drawSprite( posXSprite, posYSprite, vide , 0 );
              break;
            case wallTile : 
              drawSprite( posXSprite, posYSprite, mur , 0 );
              break;
            case diamondTile : 
              drawSprite( posXSprite, posYSprite, diamant , 0 );
              break;
            case ennemyTile :
              switch( ennemyFrame % 3 ){
                case 0:
                  drawSprite( posXSprite, posYSprite, ennemy, 0 );
                  break;
                case 1:
                  drawSprite( posXSprite, posYSprite, ennemy1, 0 );
                  break;
                case 2:
                  drawSprite( posXSprite, posYSprite, ennemy2, 0 );
                  break;
              }
              break;
        }
        lastCurrentDataLvl[j][i] = currentDataLvl[j][i];  
      }
    } 
  }
  arduboy.display();
}


void initLvl(){
  for(uint8_t j = 0; j < 8 ; j++ ){
    for(uint8_t i = 0 ; i < 16 ; i++){
      if  ( uint8_t pgm_read_word(&dataLvl[iLvl][j][i]) == playerTile  ){
        playerX = i;
        playerY = j;
      }
      currentDataLvl[j][i] = pgm_read_word(&dataLvl[iLvl][j][i]);
      lastCurrentDataLvl[j][i] = -1;
    }
  }
}

void  drawSprite(uint8_t posX, uint8_t posY, unsigned char *sprite, uint8_t nolose ){
  Sprites::drawOverwrite(posX, posY, sprite, 0);
}

Credits

Hilaire Guillaume

Hilaire Guillaume

3 projects • 1 follower
I'm developper. I write my first code 26 years ago on an amstrad I ve started trying things with arduino by curiosity last year

Comments