boolean[][] map = new boolean[12][23]; color[][] mapc = new color[12][23]; brick mbrick; void setup() { mbrick = new brick(); size(1280, 720); for (int i = 0; i < 23; i++) { map[0][i] = true; map[11][i] = true; } for (int i = 0; i < 12; i++) { map[i][22] = true; } } void draw() { dMap(); mbrick.step(); } void dMap() { for (int i = 1; i < 11; i++) { for (int i2 = 0; i2 < 22; i2++) { if (map[i][i2]==false) { fcube(i*24, i2*24); } else { ucube(i*24, i2*24); } } } } void fcube(int x, int y) { ellipseMode(LEFT); if (y/24%2==0) { if (x/24%2==0) { fill(200, 200, 200); } else { fill(240, 240, 240); } } else { if (x/24%2==0) { fill(240, 240, 240); } else { fill(200, 200, 200); } } rect(x, y, 24, 24); } void ucube(int x, int y) { ellipseMode(LEFT); fill(mapc[x/24][y/24]); rect(x, y, 24, 24); } int cline(int line) { int found = 0; for (int i = 1; i < 11; i++) { if (map[i][line]) { found +=1; } } return found; } void rline(int line) { for (int i = line; i > 0; i--) { for (int i2 = 1; i2<11; i2++) { map[i2][i]=map[i2][i-1]; mapc[i2][i]=mapc[i2][i-1]; } } } void checkmap() { for (int i = 0; i < 22; i++) { if (cline(i)==10) { rline(i); } } } void keyPressed() { if (key=='A'||key=='a') { mbrick.goLeft(); } if (key=='D'||key=='d') { mbrick.goRight(); } if (key=='S'||key=='s') { mbrick.goDown(); } if (key=='W'||key=='w') { mbrick.goRot(); } } class brick { Integer x, y, rot = 0, form = 6, ttmove; Integer col[][][][] = new Integer[7][4][4][2]; int mttmove = 30; color ccolor[] = new color[7]; brick() { sCol(0, 0, 0, 0, 1, 0, 0, 1, 1, 1); sCol(0, 1, 0, 0, 1, 0, 0, 1, 1, 1); sCol(0, 2, 0, 0, 1, 0, 0, 1, 1, 1); sCol(0, 3, 0, 0, 1, 0, 0, 1, 1, 1); sCol(1, 0, 1, 0, 1, 1, 0, 1, 2, 1); sCol(1, 1, 1, 0, 1, 1, 0, 1, 1, 2); sCol(1, 2, 0, 1, 2, 1, 1, 1, 1, 2); sCol(1, 3, 1, 0, 2, 1, 1, 1, 1, 2); sCol(2, 0, 1, 1, 2, 0, 1, 0, 0, 1); sCol(2, 1, 1, 1, 0, 0, 0, 1, 1, 2); sCol(2, 2, 1, 1, 2, 0, 1, 0, 0, 1); sCol(2, 3, 1, 1, 0, 0, 0, 1, 1, 2); sCol(3, 0, 0, 0, 1, 0, 1, 1, 2, 1); sCol(3, 1, 1, 0, 1, 1, 0, 1, 0, 2); sCol(3, 2, 0, 0, 1, 0, 1, 1, 2, 1); sCol(3, 3, 1, 0, 1, 1, 0, 1, 0, 2); sCol(4, 0, 1, 1, 0, 1, 2, 1, 1, 1); sCol(4, 1, 1, 1, 1, 0, 1, 2, 1, 1); sCol(4, 2, 1, 1, 0, 1, 2, 1, 1, 1); sCol(4, 3, 1, 1, 1, 0, 1, 2, 1, 1); sCol(5, 0, 1, 1, 0, 1, 2, 1, 2, 0); sCol(5, 1, 1, 1, 1, 0, 1, 2, 0, 0); sCol(5, 2, 1, 1, 0, 1, 2, 1, 0, 2); sCol(5, 3, 1, 1, 1, 0, 1, 2, 2, 2); sCol(6, 0, 1, 1, 0, 1, 2, 1, 2, 2); sCol(6, 1, 1, 1, 1, 0, 1, 2, 2, 0); sCol(6, 2, 1, 1, 0, 1, 2, 1, 0, 0); sCol(6, 3, 1, 1, 1, 0, 1, 2, 0, 2); ttmove = mttmove; ccolor[0] = color(112, 240, 85); ccolor[1] = color(255, 246, 72); ccolor[2] = color(255, 129, 10); ccolor[3] = color(255, 10, 10); ccolor[4] = color(201, 10, 255); ccolor[5] = color(10, 102, 255); ccolor[6] = color(10, 233, 255); y = 2; x = 5; } void step() { ttmove--; if (ttmove < 0) { ttmove = mttmove; goDown(); } tegn(); } void goRot() { int mrot = rot; mrot += 1; if (mrot > 3) { mrot -= 4; } if (!map[col[form][mrot][0][0]+x-1][col[form][mrot][0][1]+y-1]&&!map[col[form][mrot][1][0]+x-1][col[form][mrot][1][1]+y-1]&&!map[col[form][mrot][2][0]+x-1][col[form][mrot][2][1]+y-1]&&!map[col[form][mrot][3][0]+x-1][col[form][mrot][3][1]+y-1]) { rot += 1; if (rot > 3) { rot -= 4; } } } void goLeft() { if (!map[col[form][rot][0][0]+x-1-1][col[form][rot][0][1]+y-1]&&!map[col[form][rot][1][0]+x-1-1][col[form][rot][1][1]+y-1]&&!map[col[form][rot][2][0]+x-1-1][col[form][rot][2][1]+y-1]&&!map[col[form][rot][3][0]+x-1-1][col[form][rot][3][1]+y-1]) { x-=1; } } void goRight() { if (!map[col[form][rot][0][0]+x-1+1][col[form][rot][0][1]+y-1]&&!map[col[form][rot][1][0]+x-1+1][col[form][rot][1][1]+y-1]&&!map[col[form][rot][2][0]+x-1+1][col[form][rot][2][1]+y-1]&&!map[col[form][rot][3][0]+x-1+1][col[form][rot][3][1]+y-1]) { x+=1; } } void goDown() { if (!map[col[form][rot][0][0]+x-1][col[form][rot][0][1]+y-1+1]&&!map[col[form][rot][1][0]+x-1][col[form][rot][1][1]+y-1+1]&&!map[col[form][rot][2][0]+x-1][col[form][rot][2][1]+y-1+1]&&!map[col[form][rot][3][0]+x-1][col[form][rot][3][1]+y-1+1]) { y+=1; } else { placeBrick(); checkmap(); } } void placeBrick() { map[col[form][rot][0][0]+x-1][col[form][rot][0][1]+y-1] = true; mapc[col[form][rot][0][0]+x-1][col[form][rot][0][1]+y-1] = ccolor[form]; map[col[form][rot][1][0]+x-1][col[form][rot][1][1]+y-1] = true; mapc[col[form][rot][1][0]+x-1][col[form][rot][1][1]+y-1] = ccolor[form]; map[col[form][rot][2][0]+x-1][col[form][rot][2][1]+y-1] = true; mapc[col[form][rot][2][0]+x-1][col[form][rot][2][1]+y-1] = ccolor[form]; map[col[form][rot][3][0]+x-1][col[form][rot][3][1]+y-1] = true; mapc[col[form][rot][3][0]+x-1][col[form][rot][3][1]+y-1] = ccolor[form]; rot = 0; form = floor(random(0, 6.99)); y = 2; x = 5; } void tegn() { fill(ccolor[form]); for (int i = 0; i < 3; i++) { for (int i2 = 0; i2< 3; i2++) { if (gCol(i, i2)) { rect((x+i-1)*24, (y+i2-1)*24, 24, 24); } } } } boolean gCol(int c1, int c2) { for (int i = 0; i< 4; i++) { if (col[form][rot][i][0]==c1&&col[form][rot][i][1]==c2) { return true; } } return false; } void sCol(int i1, int i2, int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3) { col[i1][i2][0][0] = x0; col[i1][i2][0][1] = y0; col[i1][i2][1][0] = x1; col[i1][i2][1][1] = y1; col[i1][i2][2][0] = x2; col[i1][i2][2][1] = y2; col[i1][i2][3][0] = x3; col[i1][i2][3][1] = y3; } }