Generalized another method.
This commit is contained in:
1 parent
49355f203f
commit
7cee70573c
1 file changed
+18
-5
@@ -92,13 +92,13 @@ function TetrisGame(id) {
|
|||||||
this.canvas.drawRectangle(x, y, this.bricks[this.currentBrickId]);
|
this.canvas.drawRectangle(x, y, this.bricks[this.currentBrickId]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.canCurrentBrickMove = function(dx,dy) {
|
this.isValidBrickLoc = function(brickId, brickLoc, brickRot) {
|
||||||
var shape = this.brickShape(this.currentBrickId, this.currentBrickRot);
|
var shape = this.brickShape(brickId, brickRot);
|
||||||
|
|
||||||
for (var i = 0; i < 4; i++) {
|
for (var i = 0; i < 4; i++) {
|
||||||
var x = this.currentBrickLoc[0]+shape[i][0] + dx;
|
var x = brickLoc[0] + shape[i][0];
|
||||||
var y = this.currentBrickLoc[1]+shape[i][1] + dy;
|
var y = brickLoc[1] + shape[i][1];
|
||||||
|
|
||||||
if (x < 0 || x >= this.width) { return false; }
|
if (x < 0 || x >= this.width) { return false; }
|
||||||
if (y < 0) { return false; }
|
if (y < 0) { return false; }
|
||||||
@@ -110,6 +110,19 @@ function TetrisGame(id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
this.canCurrentBrickMove = function(dx,dy) {
|
||||||
|
var newLoc = createArray(2);
|
||||||
|
newLoc[0] = this.currentBrickLoc[0] + dx;
|
||||||
|
newLoc[1] = this.currentBrickLoc[1] + dy;
|
||||||
|
|
||||||
|
return this.isValidBrickLoc(
|
||||||
|
this.currentBrickId,
|
||||||
|
newLoc,
|
||||||
|
this.currentBrickRot
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.canCurrentBrickRotate = function() {
|
this.canCurrentBrickRotate = function() {
|
||||||
|
|||||||
Reference in new issue
Block a user