"use strict"; let tetris = function () { const grid_x = 10; const grid_y = 30; const tetrimonios = [ /*'I'*/{ mR:2, r:[ [ [0,0],[0,1],[0,2],[0,3] ], [ [0,0],[1,0],[2,0],[3,0] ] ] }, /*'O':*/{ mR:1, r:[ [ [0,0],[0,1],[1,0],[1,1] ] ] }, /*'L':*/{ mR:4, r:[ [ [0,0],[0,1],[0,2],[1,2] ], [ [0,0],[1,0],[2,0],[0,1] ], [ [0,0],[0,1],[1,1],[1,2] ], [ [0,2],[1,2],[1,1],[1,0] ] ] }, /*'L2':*/{ mR:4, r:[ [ [1,0],[1,1],[1,2],[0,2] ], [ [0,0],[0,1],[1,1],[1,2] ], [ [1,0],[0,0],[0,1],[0,2] ], [ [0,0],[1,0],[2,0],[2,1] ] ] }, /*'Z':*/{ mR:2, r:[ [ [0,0],[1,0],[1,1],[2,1] ], [ [1,0],[1,1],[0,1],[0,2] ] ] }, /*'Z2':*/{ mR:2, r:[ [ [0,1],[1,1],[1,0],[2,0] ], [ [0,0],[0,1],[1,1],[1,2] ] ] } ]; let timer; let score, speed; let next_t; let b=[grid_x][grid_y]; let t = {t:null,x:0,y:0,r:0}; function control(e) { clean(); switch(e.key) { case 'ArrowUp': moveUp(this.t); break; case 'ArrowDown': moveDown(this.t); break; case 'ArrowLeft': moveLeft(this.t); break; case 'ArrowRight': moveRight(this.t);break; } draw(); } document.addEventListener('keydown', control); function moveUp(p) { let r = p.r; p.r = (p.r++)% p.t.mR; if ( collision(p) ) p.r = r; } function moveDown(p) { p.y++; if ( collision(p) ) glue(p); } function moveLeft(p) { p.x--; if ( collision(p) ) p.x++; } function moveRight(p) { p.x++; if ( collision(p) ) p.x--; } function collision(p) { let x,y; for(x=0;x