Idk where is the error

so, I recently started programming on processing 3, the first game I want to do has to be a platformer, but I made a mistake and I don’t know what it is

block[] b;

int Map[][] = {
  {1,0,0,0,0,0,0,0},
  {0,1,0,0,0,1,0,0},
  {0,0,1,0,0,1,0,0},
  {0,0,0,0,0,1,0,0}
};

void setup(){
  
  b = new block[16];
  size(400, 400);
 
  for(int i = 0; i < 8; i++){
    for(int j = 0; j < 4; j++){
      for(int a = 0; a < 16; a++){
        if(Map[i][j] == 1){
          b[a] = new block(i*50, j*100, 50, 50, 100, 50, 50);
        } 
      }
    }
  }
  print(b[2]);
  
}
void draw(){
  background(158);
  for(int i = 0; i < b.length; i++){
    b[i].show();
  }
}

class block code:

class block{
  float x, y, xSize, ySize, c1, c2, c3;
  
  block(float X, float Y, float xsize, float ysize, float C1, float C2, float C3){
    x = X;
    y = Y;
    ySize = ysize;
    xSize = xsize;
    c1 = C1;
    c2 = C2;
    c3 = C3;
  }
  
  void show(){
    fill(c1, c2, c3);
    rect(x, y, xSize, ySize);
    noFill();
  }
  
}

Hi @deiwy

Welcome to the community! :slight_smile:

The error that you have is due to index array

if(Map[i][j] == 1){

Notice that this condition fails because the Map Array is 4x8, but you are trying to access a 8x4 array :wink:
Just switch j and i and you are good to go!

if(Map[j][i] == 1){

Best regards!

1 Like

@MiguelSanches
ok, thank you

2 Likes