Add ghost piece preview showing where block will land
- Add getGhostY() method to TetrisGame class (game.js) - Add ghostY to getState() output - Add getGhostY() helper to server (server/index.js) - Include ghostY in getStates() broadcast - Add drawGhostPiece() and drawGhostCell() methods (renderer.js) - Ghost renders as semi-transparent outline at landing position
This commit is contained in:
@@ -338,6 +338,16 @@ function addGarbageToPlayer(player) {
|
||||
// Elimination is handled by spawnPiece when a new piece can't fit
|
||||
}
|
||||
|
||||
function getGhostY(piece, board) {
|
||||
if (!piece) return null;
|
||||
|
||||
let ghostY = piece.y;
|
||||
while (isValidPosition(piece, piece.x, ghostY + 1, board)) {
|
||||
ghostY++;
|
||||
}
|
||||
return ghostY;
|
||||
}
|
||||
|
||||
function startGame() {
|
||||
lobby.gameStarted = true;
|
||||
|
||||
@@ -391,6 +401,7 @@ function getStates() {
|
||||
playerId: p.id,
|
||||
board: JSON.parse(JSON.stringify(p.board)),
|
||||
currentPiece: p.currentPiece ? JSON.parse(JSON.stringify(p.currentPiece)) : null,
|
||||
ghostY: p.currentPiece ? getGhostY(p.currentPiece, p.board) : null,
|
||||
nextPiece: p.nextPiece ? JSON.parse(JSON.stringify(p.nextPiece)) : null,
|
||||
holdPiece: p.holdPiece ? JSON.parse(JSON.stringify(p.holdPiece)) : null,
|
||||
canHold: p.canHold,
|
||||
|
||||
Reference in New Issue
Block a user