Having issues getting blocks to fall in Tetris

Hi all

My group and I are having issues getting our blocks to fall in tetris. We have created a function called fall which we call in the draw event, however it does not seem to fall when we run the program. This may be a simple oversight somewhere, but we are really unsure about how to proceed. Code below

int x=0;
int z=1;
int[][] playspace;
int[][] motion;
int[][] colour;
boolean drop=true;
boolean start=false;

void setup(){
  size(600,400);
  frameRate(4);
  playspace = new int[10][20];
  motion = new int[10][20];
  colour = new int[10][20];
  for (int i=0;i<10;i++) {
      for (int j=0;j<20;j++) {
        colour[i][j]=255;
      }
  }
  printArray(playspace);
}

void startscreen() {
  fill(50);
  textSize(60);
  text("TETRIS",200,170);
  textSize(20);
  text("Press enter",250,300);
  fill(255);
}

void draw() {
  background(200);
  if (start==false) {
    startscreen();
  }
  if (start==true) {
    if (drop==true) {
      droptetromino();
      drop=false;
    }
    for (int i=0;i<10;i++) {
      for (int j=0;j<20;j++) {
        rect(i*20,j*20,20,20);
      }
    }
    for (int i=0;i<10;i++) {
      for (int j=0;j<20;j++) {
        if (playspace[i][j]==1) {
          fill(colour[i][j]);
          rect(i*20,j*20,20,20);
          fill(255);
        }
      }
    }

    fall();
  }
}


void droptetromino() {
  int a=1;
  if (a==1) {
    playspace[1][1]=1;
    motion[1][1]=1;
    colour[1][1]=200;
    playspace[2][1]=1;
    motion[2][1]=1;
    colour[2][1]=200;
    playspace[3][1]=1;
    motion[3][1]=1;
    colour[3][1]=200;
    playspace[4][1]=1;
    motion[4][1]=1;
    colour[4][1]=200;
  }
  if (a==2) {
    playspace[1][1]=1;
    motion[1][1]=1;
    colour[1][1]=1;
    playspace[1][2]=1;
    motion[1][2]=1;
    colour[1][2]=1;
    playspace[1][3]=1;
    motion[1][3]=1;
    colour[1][3]=1;
    playspace[1][4]=1;
    motion[1][4]=1;
    colour[1][4]=1;
  }
  if (a==3) {
    playspace[1][1]=1;
    motion[1][1]=1;
    colour[1][1]=1;
    playspace[1][2]=1;
    motion[1][2]=1;
    colour[1][2]=1;
    playspace[2][2]=1;
    motion[2][2]=1;
    colour[2][2]=1;
    playspace[2][3]=1;
    motion[2][3]=1;
    colour[2][3]=1;
  }
  if (a==4) {
    playspace[1][1]=1;
    motion[1][1]=1;
    colour[1][1]=1;
    playspace[2][1]=1;
    motion[2][1]=1;
    colour[2][1]=1;
    playspace[1][2]=1;
    motion[1][2]=1;
    colour[1][2]=1;
    playspace[1][3]=1;
    motion[1][3]=1;
    colour[1][3]=1;
  }
  if (a==5) {
    playspace[1][1]=1;
    motion[1][1]=1;
    colour[1][1]=1;
    playspace[2][1]=1;
    motion[2][1]=1;
    colour[2][1]=1;
    playspace[3][1]=1;
    motion[3][1]=1;
    colour[3][1]=1;
    playspace[3][2]=1;
    motion[3][2]=1;
    colour[3][2]=1;
  }

}

void fall() {
  for (int i=0;i<10;i++) {
    for (int j=19;j>-1;j--) {
      if (motion[i][j]==1) {
        if (j+1==20) {
          motion[i][j]=0;
          drop=true;
        } else if (motion[i][j+1]==0) {
          motion[i][j]=0;
          drop=true;
        } else {
          playspace[i][j]=0;
          playspace[i][j-1]=1;
          colour[i][j]=(255);
          motion[i][j]=0;
          motion[i][j-1]=1;
          colour[i][j-1]=100;
        }
      }
    }
  }
}


void keyPressed() {
  start=true;
}

Any help would be greatly appreciated. We have only built a few of the tetrominos in the above code for testing.

Thanks in advance

Tagged:
Sign In or Register to comment.