From 322744c2965fbb60646577529cc14bee8453aac1 Mon Sep 17 00:00:00 2001 From: Gregor Klevze Date: Sun, 21 Dec 2025 16:31:23 +0100 Subject: [PATCH] fixed first row --- src/gameplay/coop/CoopGame.cpp | 49 +++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/src/gameplay/coop/CoopGame.cpp b/src/gameplay/coop/CoopGame.cpp index d19251b..0179fce 100644 --- a/src/gameplay/coop/CoopGame.cpp +++ b/src/gameplay/coop/CoopGame.cpp @@ -104,16 +104,45 @@ void CoopGame::move(PlayerSide side, int dx) { void CoopGame::rotate(PlayerSide side, int dir) { PlayerState& ps = player(side); if (gameOver || ps.toppedOut) return; - Piece test = ps.cur; - test.rot = (test.rot + dir + 4) % 4; - // Simple wall kick: try in place, then left, then right - if (!collides(ps, test)) { - ps.cur = test; return; - } - test.x -= 1; - if (!collides(ps, test)) { ps.cur = test; return; } - test.x += 2; - if (!collides(ps, test)) { ps.cur = test; return; } + + auto minOccupiedY = [&](const Piece& p) -> int { + int minY = 999; + for (int cy = 0; cy < 4; ++cy) { + for (int cx = 0; cx < 4; ++cx) { + if (!cellFilled(p, cx, cy)) continue; + minY = std::min(minY, p.y + cy); + } + } + return (minY == 999) ? p.y : minY; + }; + + auto tryApplyWithTopKick = [&](const Piece& candidate) -> bool { + // If rotation would place any occupied cell above the visible grid, + // kick it down just enough to keep all blocks visible. + int minY = minOccupiedY(candidate); + int baseDy = (minY < 0) ? -minY : 0; + + // Try minimal adjustment first; allow a couple extra pixels/rows for safety. + for (int dy = baseDy; dy <= baseDy + 2; ++dy) { + Piece test = candidate; + test.y += dy; + if (!collides(ps, test)) { + ps.cur = test; + return true; + } + } + return false; + }; + + Piece rotated = ps.cur; + rotated.rot = (rotated.rot + dir + 4) % 4; + + // Simple wall kick: try in place, then left, then right. + if (tryApplyWithTopKick(rotated)) return; + rotated.x -= 1; + if (tryApplyWithTopKick(rotated)) return; + rotated.x += 2; + if (tryApplyWithTopKick(rotated)) return; } void CoopGame::hardDrop(PlayerSide side) {