Added new level sound

This commit is contained in:
2025-11-30 10:37:35 +01:00
parent 69b2521695
commit 5fd77fdaf0
7 changed files with 219 additions and 5 deletions

View File

@ -57,6 +57,9 @@ void Game::reset(int startLevel_) {
// Initialize gravity using NES timing table (ms per cell by level)
gravityMs = gravityMsForLevel(_level, gravityGlobalMultiplier);
fallAcc = 0; gameOver=false; paused=false;
hardDropShakeTimerMs = 0.0;
hardDropCells.clear();
hardDropFxId = 0;
_startTime = SDL_GetPerformanceCounter();
_pausedTime = 0;
_lastPauseStart = 0;
@ -328,6 +331,25 @@ void Game::softDropBoost(double frameMs) {
(void)frameMs;
}
void Game::updateVisualEffects(double frameMs) {
if (frameMs <= 0.0) {
return;
}
if (hardDropShakeTimerMs <= 0.0) {
hardDropShakeTimerMs = 0.0;
if (!hardDropCells.empty()) {
hardDropCells.clear();
}
return;
}
hardDropShakeTimerMs = std::max(0.0, hardDropShakeTimerMs - frameMs);
if (hardDropShakeTimerMs <= 0.0 && !hardDropCells.empty()) {
hardDropCells.clear();
}
}
void Game::hardDrop() {
if (paused) return;
// Count how many rows we drop for scoring parity with JS
@ -337,7 +359,34 @@ void Game::hardDrop() {
if (rows > 0) {
_score += rows * 1;
}
lockPiece();
hardDropCells.clear();
hardDropCells.reserve(8);
for (int cy = 0; cy < 4; ++cy) {
for (int cx = 0; cx < 4; ++cx) {
if (!cellFilled(cur, cx, cy)) {
continue;
}
int gx = cur.x + cx;
int gy = cur.y + cy;
if (gx < 0 || gx >= COLS || gy >= ROWS) {
continue;
}
if (gy >= 0) {
hardDropCells.push_back(SDL_Point{gx, gy});
}
}
}
++hardDropFxId;
lockPiece();
hardDropShakeTimerMs = HARD_DROP_SHAKE_DURATION_MS;
}
double Game::hardDropShakeStrength() const {
if (hardDropShakeTimerMs <= 0.0) {
return 0.0;
}
return std::clamp(hardDropShakeTimerMs / HARD_DROP_SHAKE_DURATION_MS, 0.0, 1.0);
}
void Game::rotate(int dir) {

View File

@ -74,6 +74,13 @@ public:
double getFallAccumulator() const { return fallAcc; } // Debug: time accumulated toward next drop
void setLevelGravityMultiplier(int level, double m);
// Visual effect hooks
void updateVisualEffects(double frameMs);
bool hasHardDropShake() const { return hardDropShakeTimerMs > 0.0; }
double hardDropShakeStrength() const;
const std::vector<SDL_Point>& getHardDropCells() const { return hardDropCells; }
uint32_t getHardDropFxId() const { return hardDropFxId; }
private:
std::array<int, COLS*ROWS> board{}; // 0 empty else color index
Piece cur{}, hold{}, nextPiece{}; // current, held & next piece
@ -109,6 +116,12 @@ private:
// Backwards-compatible accessors (delegate to gravityMgr)
double computeGravityMsForLevel(int level) const;
// Impact FX timers
double hardDropShakeTimerMs{0.0};
static constexpr double HARD_DROP_SHAKE_DURATION_MS = 320.0;
std::vector<SDL_Point> hardDropCells;
uint32_t hardDropFxId{0};
// Internal helpers ----------------------------------------------------
void refillBag();
void spawn();