Fix elimination check to only eliminate when piece blocks are above visible area
Previously, players were eliminated when currentPiece.y <= 0, which was too aggressive. Pieces like I, T, S, Z, J, L spawn at y=0 but have empty top rows, so their actual blocks are at y >= 1 and visible on the board. Now we check if any part of the locked piece is actually above y=0 (not visible) before eliminating the player.
This commit is contained in:
+15
-1
@@ -226,7 +226,21 @@ class TetrisGame {
|
||||
}
|
||||
|
||||
// Check for game over (piece locked above visible area)
|
||||
if (this.currentPiece.y <= 0) {
|
||||
// Only eliminate if any part of the piece is above y=0 (not visible)
|
||||
let pieceAboveBoard = false;
|
||||
for (let row = 0; row < this.currentPiece.shape.length; row++) {
|
||||
for (let col = 0; col < this.currentPiece.shape[row].length; col++) {
|
||||
if (this.currentPiece.shape[row][col]) {
|
||||
const boardY = this.currentPiece.y + row;
|
||||
if (boardY < 0) {
|
||||
pieceAboveBoard = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pieceAboveBoard) break;
|
||||
}
|
||||
if (pieceAboveBoard) {
|
||||
this.gameOver = true;
|
||||
this.eliminated = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user