diff --git a/tetris.js b/tetris.js index 14c61e9..2e1f5c1 100644 --- a/tetris.js +++ b/tetris.js @@ -42,6 +42,14 @@ let tetris = function () { [ [0,1],[1,1],[1,0],[2,0] ], [ [0,0],[0,1],[1,1],[1,2] ] ] + }, + /*'T':*/{ mR:4, + r:[ + [ [1,0],[0,1],[1,1],[2,1] ], + [ [0,0],[0,1],[0,2],[1,1] ], + [ [0,0],[1,0],[2,0],[1,1] ], + [ [1,0],[1,1],[1,2],[0,1] ] + ] } ]; @@ -63,15 +71,21 @@ let tetris = function () { } } - function clean(p) { ctx.fillStyle = "#FFFFFF"; drawBlocks(p,drawBlock_clean); } - function draw(p) { ctx.fillStyle = "#666666"; drawBlocks(p,drawBlock_filled); } + function clean(p) { ctx.fillStyle = "#FFFFFF";drawBlocks(p,drawBlock_clean); } + function draw(p) { ctx.fillStyle = "#F66666";drawBlocks(p,drawBlock_filled); } function drawBlocks(p, drawBlock) { p.t.r[p.r].forEach(b => drawBlock(p.x + b[0], p.y + b[1])); } function drawBlock_clean(x,y) { + ctx.fillRect(board_x + blockSize*x, board_y + blockSize*y, blockSize, blockSize); } function drawBlock_filled(x,y) { + + ctx.fillRect(board_x + blockSize*x, board_y + blockSize*y, blockSize, blockSize); + } + function drawBlock_glue(x,y) { + ctx.fillStyle = "#666666"; ctx.fillRect(board_x + blockSize*x, board_y + blockSize*y, blockSize, blockSize); } @@ -90,7 +104,8 @@ let tetris = function () { if ( collision(p) ) { p.y--; glue(p); - } + return; + } draw(t); } @@ -110,7 +125,9 @@ let tetris = function () { function glue(p) { p.t.r[p.r].forEach(b => { board[p.y+b[1]][p.x+b[0]]=1; } ); - draw(t); + + drawBlocks(p,drawBlock_glue); + deleteRows( board.filter( r=>r.filter(c=>c==1).length==grid_x ) ); dropShape(t); }