From 205748edd8e70ccd4754380cb87a8ca35080eed6 Mon Sep 17 00:00:00 2001 From: Robert Kolner Date: Thu, 15 Mar 2012 18:10:52 +0100 Subject: [PATCH] Added lock for more smooth redrawing. --- tetris.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tetris.js b/tetris.js index eb24349..b77f074 100644 --- a/tetris.js +++ b/tetris.js @@ -39,7 +39,15 @@ function TetrisGame(id) { /**************/ /* Functions: */ /**************/ + this.drawLocker = false; + this.drawLock = function() { this.drawLocker = true; }; + this.drawUnlock = function() { this.drawLocker = false; }; + this.redraw = function() { + if (this.drawLocker) { + return; + } + this.canvas.drawBoard(this.board); this.drawCurrentBrick(); } @@ -230,7 +238,9 @@ function TetrisGame(id) { } this.doTurn = function() { + this.drawLock(); if (! this.moveCurrentBrickDown()) { + this.drawUnlock(); return false; } @@ -238,6 +248,7 @@ function TetrisGame(id) { for (var i = 0; i < filledLines.length; i++) { this.removeLine(filledLines[i]-i); } + this.drawUnlock(); this.redraw(); return true;