fixed first row

This commit is contained in:
2025-12-21 16:31:23 +01:00
parent cf3e897752
commit 322744c296

View File

@ -104,16 +104,45 @@ void CoopGame::move(PlayerSide side, int dx) {
void CoopGame::rotate(PlayerSide side, int dir) { void CoopGame::rotate(PlayerSide side, int dir) {
PlayerState& ps = player(side); PlayerState& ps = player(side);
if (gameOver || ps.toppedOut) return; if (gameOver || ps.toppedOut) return;
Piece test = ps.cur;
test.rot = (test.rot + dir + 4) % 4; auto minOccupiedY = [&](const Piece& p) -> int {
// Simple wall kick: try in place, then left, then right int minY = 999;
if (!collides(ps, test)) { for (int cy = 0; cy < 4; ++cy) {
ps.cur = test; return; for (int cx = 0; cx < 4; ++cx) {
if (!cellFilled(p, cx, cy)) continue;
minY = std::min(minY, p.y + cy);
} }
test.x -= 1; }
if (!collides(ps, test)) { ps.cur = test; return; } return (minY == 999) ? p.y : minY;
test.x += 2; };
if (!collides(ps, test)) { ps.cur = test; return; }
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) { void CoopGame::hardDrop(PlayerSide side) {