fixed for cooperate mode

This commit is contained in:
2025-12-22 13:48:54 +01:00
parent 694243ac89
commit 18463774e9
4 changed files with 311 additions and 1 deletions

View File

@ -494,6 +494,17 @@ int TetrisApp::Impl::init()
suppressLineVoiceForLevelUp = true;
});
// Mirror single-player level-up audio/visual behavior for Coop sessions
coopGame->setLevelUpCallback([this](int /*newLevel*/) {
if (skipNextLevelUpJingle) {
skipNextLevelUpJingle = false;
} else {
SoundEffectManager::instance().playSound("new_level", 1.0f);
SoundEffectManager::instance().playSound("lets_go", 1.0f);
}
suppressLineVoiceForLevelUp = true;
});
game->setAsteroidDestroyedCallback([](AsteroidType /*type*/) {
SoundEffectManager::instance().playSound("asteroid_destroy", 0.9f);
});

View File

@ -416,7 +416,9 @@ void CoopGame::applyLineClearRewards(PlayerState& creditPlayer, int cleared) {
}
_lines += cleared;
creditPlayer.lines += cleared;
// Credit both players with the cleared lines so cooperative play counts for both
left.lines += cleared;
right.lines += cleared;
_currentCombo += 1;
if (_currentCombo > _maxCombo) _maxCombo = _currentCombo;
@ -445,6 +447,7 @@ void CoopGame::applyLineClearRewards(PlayerState& creditPlayer, int cleared) {
if (targetLevel > _level) {
_level = targetLevel;
gravityMs = gravityMsForLevel(_level);
if (levelUpCallback) levelUpCallback(_level);
}
// Per-player level progression mirrors the shared rules but is driven by

View File

@ -57,7 +57,9 @@ public:
explicit CoopGame(int startLevel = 0);
using SoundCallback = std::function<void(int)>;
using LevelUpCallback = std::function<void(int)>;
void setSoundCallback(SoundCallback cb) { soundCallback = cb; }
void setLevelUpCallback(LevelUpCallback cb) { levelUpCallback = cb; }
void reset(int startLevel = 0);
void tickGravity(double frameMs);
@ -137,6 +139,7 @@ private:
uint32_t hardDropFxId{0};
uint64_t pieceSequence{0};
SoundCallback soundCallback;
LevelUpCallback levelUpCallback;
// Helpers ---------------------------------------------------------------
PlayerState& player(PlayerSide s) { return s == PlayerSide::Left ? left : right; }