fixed first row
This commit is contained in:
@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user