added pause option coop gameplay

This commit is contained in:
2025-12-21 17:59:21 +01:00
parent 06aa63f548
commit 744268fedd
3 changed files with 40 additions and 7 deletions

View File

@ -1231,6 +1231,17 @@ void TetrisApp::Impl::runLoop()
}
};
if (game->isPaused()) {
// While paused, suppress all continuous input changes so pieces don't drift.
coopGame->setSoftDropping(CoopGame::PlayerSide::Left, false);
coopGame->setSoftDropping(CoopGame::PlayerSide::Right, false);
p1MoveTimerMs = 0.0;
p2MoveTimerMs = 0.0;
p1LeftHeld = false;
p1RightHeld = false;
p2LeftHeld = false;
p2RightHeld = false;
} else {
handleSide(CoopGame::PlayerSide::Left, p1LeftHeld, p1RightHeld, p1MoveTimerMs, SDL_SCANCODE_A, SDL_SCANCODE_D, SDL_SCANCODE_S);
handleSide(CoopGame::PlayerSide::Right, p2LeftHeld, p2RightHeld, p2MoveTimerMs, SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, SDL_SCANCODE_DOWN);
@ -1239,7 +1250,6 @@ void TetrisApp::Impl::runLoop()
p2LeftHeld = ks[SDL_SCANCODE_LEFT];
p2RightHeld = ks[SDL_SCANCODE_RIGHT];
if (!game->isPaused()) {
coopGame->tickGravity(frameMs);
coopGame->updateVisualEffects(frameMs);
}

View File

@ -1259,6 +1259,19 @@ void ApplicationManager::setupStateHandlers() {
const bool *ks = SDL_GetKeyboardState(nullptr);
if (coopActive) {
// Paused: suppress all continuous input so pieces don't drift while paused.
if (m_stateContext.game->isPaused()) {
m_stateContext.coopGame->setSoftDropping(CoopGame::PlayerSide::Left, false);
m_stateContext.coopGame->setSoftDropping(CoopGame::PlayerSide::Right, false);
m_p1MoveTimerMs = 0.0;
m_p2MoveTimerMs = 0.0;
m_p1LeftHeld = false;
m_p1RightHeld = false;
m_p2LeftHeld = false;
m_p2RightHeld = false;
return;
}
auto handleSide = [&](CoopGame::PlayerSide side,
bool leftHeld,
bool rightHeld,

View File

@ -133,6 +133,16 @@ void PlayingState::handleEvent(const SDL_Event& e) {
return;
}
// Pause toggle (P) - matches classic behavior; disabled during countdown
if (e.key.scancode == SDL_SCANCODE_P) {
const bool countdown = (ctx.gameplayCountdownActive && *ctx.gameplayCountdownActive) ||
(ctx.menuPlayCountdownArmed && *ctx.menuPlayCountdownArmed);
if (!countdown) {
ctx.game->setPaused(!ctx.game->isPaused());
}
return;
}
// Tetris controls (only when not paused)
if (ctx.game->isPaused()) {
return;