fixed score display
This commit is contained in:
@ -1369,6 +1369,7 @@ void GameRenderer::renderPlayingState(
|
||||
double sp_gravityMs = game->getGravityMs();
|
||||
double sp_fallAcc = game->getFallAccumulator();
|
||||
int sp_soft = game->isSoftDropping() ? 1 : 0;
|
||||
/*
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "SP OFFSETS: seq=%llu visX=%.3f targX=%.3f offX=%.2f offY=%.2f gravMs=%.2f fallAcc=%.2f soft=%d",
|
||||
(unsigned long long)s_activePieceSmooth.sequence,
|
||||
s_activePieceSmooth.visualX,
|
||||
@ -1379,6 +1380,7 @@ void GameRenderer::renderPlayingState(
|
||||
sp_fallAcc,
|
||||
sp_soft
|
||||
);
|
||||
*/
|
||||
}
|
||||
|
||||
// Draw ghost piece (where current piece will land)
|
||||
@ -1910,19 +1912,13 @@ void GameRenderer::renderCoopPlayingState(
|
||||
const float gridX = layoutStartX + PANEL_WIDTH + PANEL_SPACING + contentOffsetX;
|
||||
const float gridY = contentStartY + NEXT_PANEL_HEIGHT + contentOffsetY;
|
||||
|
||||
const float rightPanelX = gridX + GRID_W + PANEL_SPACING;
|
||||
|
||||
const float statsY = gridY;
|
||||
const float statsW = PANEL_WIDTH;
|
||||
const float statsH = GRID_H;
|
||||
|
||||
// Shared score panel (reuse existing art)
|
||||
SDL_FRect scorePanelBg{ statsX - 20.0f, gridY - 26.0f, statsW + 40.0f, GRID_H + 52.0f };
|
||||
if (statisticsPanelTex) {
|
||||
SDL_RenderTexture(renderer, statisticsPanelTex, nullptr, &scorePanelBg);
|
||||
} else if (scorePanelTex) {
|
||||
SDL_RenderTexture(renderer, scorePanelTex, nullptr, &scorePanelBg);
|
||||
} else {
|
||||
drawRectWithOffset(scorePanelBg.x - contentOffsetX, scorePanelBg.y - contentOffsetY, scorePanelBg.w, scorePanelBg.h, SDL_Color{12,18,32,205});
|
||||
}
|
||||
// (Score panels are drawn per-player below using scorePanelTex and classic sizing.)
|
||||
|
||||
// Handle line clearing effects (defer to LineEffect like single-player)
|
||||
if (game->hasCompletedLines() && lineEffect && !lineEffect->isActive()) {
|
||||
@ -2357,7 +2353,8 @@ void GameRenderer::renderCoopPlayingState(
|
||||
double gMsDbg = game->getGravityMs();
|
||||
double accDbg = game->getFallAccumulator(side);
|
||||
int softDbg = game->isSoftDropping(side) ? 1 : 0;
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "COOP %s OFFSETS: seq=%llu visX=%.3f targX=%.3f offX=%.2f offY=%.2f gravMs=%.2f fallAcc=%.2f soft=%d",
|
||||
/*
|
||||
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "COOP %s OFFSETS: seq=%llu visX=%.3f targX=%.3f offX=%.2f offY=%.2f gravMs=%.2f fallAcc=%.2f soft=%d",
|
||||
(side == CoopGame::PlayerSide::Left) ? "L" : "R",
|
||||
(unsigned long long)ss.seq,
|
||||
ss.visualX,
|
||||
@ -2368,6 +2365,7 @@ void GameRenderer::renderCoopPlayingState(
|
||||
accDbg,
|
||||
softDbg
|
||||
);
|
||||
*/
|
||||
}
|
||||
return std::pair<float, float>{ offsetX, offsetY };
|
||||
};
|
||||
@ -2517,10 +2515,120 @@ void GameRenderer::renderCoopPlayingState(
|
||||
drawNextPanel(nextLeftX, nextY, game->next(CoopGame::PlayerSide::Left));
|
||||
drawNextPanel(nextRightX, nextY, game->next(CoopGame::PlayerSide::Right));
|
||||
|
||||
// Simple shared score text
|
||||
char buf[128];
|
||||
std::snprintf(buf, sizeof(buf), "SCORE %d LINES %d LEVEL %d", game->score(), game->lines(), game->level());
|
||||
pixelFont->draw(renderer, gridX + GRID_W * 0.5f - 140.0f, gridY + GRID_H + 24.0f, buf, 1.2f, SDL_Color{220, 230, 255, 255});
|
||||
// Per-player scoreboards (left and right)
|
||||
auto drawPlayerScoreboard = [&](CoopGame::PlayerSide side, float columnLeftX, float columnRightX, const char* title) {
|
||||
const SDL_Color labelColor{255, 220, 0, 255};
|
||||
const SDL_Color valueColor{255, 255, 255, 255};
|
||||
const SDL_Color nextColor{80, 255, 120, 255};
|
||||
|
||||
// Match classic vertical placement feel
|
||||
const float contentTopOffset = 0.0f;
|
||||
const float contentBottomOffset = 290.0f;
|
||||
const float contentPad = 36.0f;
|
||||
float scoreContentH = (contentBottomOffset - contentTopOffset) + contentPad;
|
||||
float baseY = gridY + (GRID_H - scoreContentH) * 0.5f;
|
||||
|
||||
const float statsPanelPadLeft = 40.0f;
|
||||
const float statsPanelPadRight = 34.0f;
|
||||
const float statsPanelPadY = 28.0f;
|
||||
|
||||
const float textX = columnLeftX + statsPanelPadLeft;
|
||||
|
||||
char scoreStr[32];
|
||||
std::snprintf(scoreStr, sizeof(scoreStr), "%d", game->score(side));
|
||||
|
||||
char linesStr[16];
|
||||
std::snprintf(linesStr, sizeof(linesStr), "%03d", game->lines(side));
|
||||
|
||||
char levelStr[16];
|
||||
std::snprintf(levelStr, sizeof(levelStr), "%02d", game->level(side));
|
||||
|
||||
// Next level progression (per-player lines)
|
||||
int startLv = game->startLevelBase();
|
||||
int linesDone = game->lines(side);
|
||||
int firstThreshold = (startLv + 1) * 10;
|
||||
int nextThreshold = 0;
|
||||
if (linesDone < firstThreshold) {
|
||||
nextThreshold = firstThreshold;
|
||||
} else {
|
||||
int blocksPast = linesDone - firstThreshold;
|
||||
nextThreshold = firstThreshold + ((blocksPast / 10) + 1) * 10;
|
||||
}
|
||||
int linesForNext = std::max(0, nextThreshold - linesDone);
|
||||
char nextStr[32];
|
||||
std::snprintf(nextStr, sizeof(nextStr), "%d LINES", linesForNext);
|
||||
|
||||
// Time display (shared session time)
|
||||
int totalSecs = game->elapsed(side);
|
||||
int mins = totalSecs / 60;
|
||||
int secs = totalSecs % 60;
|
||||
char timeStr[16];
|
||||
std::snprintf(timeStr, sizeof(timeStr), "%02d:%02d", mins, secs);
|
||||
|
||||
struct StatLine {
|
||||
const char* text;
|
||||
float offsetY;
|
||||
float scale;
|
||||
SDL_Color color;
|
||||
};
|
||||
|
||||
// Keep offsets aligned with classic spacing
|
||||
std::vector<StatLine> statLines;
|
||||
statLines.reserve(12);
|
||||
statLines.push_back({title, 0.0f, 0.95f, SDL_Color{200, 220, 235, 220}});
|
||||
statLines.push_back({"SCORE", 30.0f, 1.0f, labelColor});
|
||||
statLines.push_back({scoreStr, 55.0f, 0.9f, valueColor});
|
||||
statLines.push_back({"LINES", 100.0f, 1.0f, labelColor});
|
||||
statLines.push_back({linesStr, 125.0f, 0.9f, valueColor});
|
||||
statLines.push_back({"LEVEL", 170.0f, 1.0f, labelColor});
|
||||
statLines.push_back({levelStr, 195.0f, 0.9f, valueColor});
|
||||
statLines.push_back({"NEXT LVL", 230.0f, 1.0f, labelColor});
|
||||
statLines.push_back({nextStr, 255.0f, 0.9f, nextColor});
|
||||
statLines.push_back({"TIME", 295.0f, 1.0f, labelColor});
|
||||
statLines.push_back({timeStr, 320.0f, 0.9f, valueColor});
|
||||
|
||||
// Size the panel like classic: measure the text block and fit the background.
|
||||
float statsContentTop = std::numeric_limits<float>::max();
|
||||
float statsContentBottom = std::numeric_limits<float>::lowest();
|
||||
float statsContentMaxWidth = 0.0f;
|
||||
for (const auto& line : statLines) {
|
||||
int textW = 0;
|
||||
int textH = 0;
|
||||
pixelFont->measure(line.text, line.scale, textW, textH);
|
||||
float y = baseY + line.offsetY;
|
||||
statsContentTop = std::min(statsContentTop, y);
|
||||
statsContentBottom = std::max(statsContentBottom, y + static_cast<float>(textH));
|
||||
statsContentMaxWidth = std::max(statsContentMaxWidth, static_cast<float>(textW));
|
||||
}
|
||||
|
||||
float panelW = statsPanelPadLeft + statsContentMaxWidth + statsPanelPadRight;
|
||||
float panelH = (statsContentBottom - statsContentTop) + statsPanelPadY * 2.0f;
|
||||
float panelY = statsContentTop - statsPanelPadY;
|
||||
// Left player is left-aligned in its column; right player is right-aligned.
|
||||
float panelX = (side == CoopGame::PlayerSide::Right) ? (columnRightX - panelW) : columnLeftX;
|
||||
SDL_FRect panelBg{ panelX, panelY, panelW, panelH };
|
||||
if (scorePanelTex) {
|
||||
SDL_RenderTexture(renderer, scorePanelTex, nullptr, &panelBg);
|
||||
} else {
|
||||
SDL_SetRenderDrawColor(renderer, 12, 18, 32, 205);
|
||||
SDL_RenderFillRect(renderer, &panelBg);
|
||||
}
|
||||
|
||||
float textDrawX = panelX + statsPanelPadLeft;
|
||||
for (const auto& line : statLines) {
|
||||
pixelFont->draw(renderer, textDrawX, baseY + line.offsetY, line.text, line.scale, line.color);
|
||||
}
|
||||
};
|
||||
|
||||
// Nudge panels toward the window edges for tighter symmetry.
|
||||
const float scorePanelEdgeNudge = 20.0f;
|
||||
const float leftColumnLeftX = statsX - scorePanelEdgeNudge;
|
||||
const float leftColumnRightX = leftColumnLeftX + statsW;
|
||||
const float rightColumnLeftX = rightPanelX;
|
||||
const float rightColumnRightX = rightColumnLeftX + statsW + scorePanelEdgeNudge;
|
||||
|
||||
drawPlayerScoreboard(CoopGame::PlayerSide::Left, leftColumnLeftX, leftColumnRightX, "PLAYER 1");
|
||||
drawPlayerScoreboard(CoopGame::PlayerSide::Right, rightColumnLeftX, rightColumnRightX, "PLAYER 2");
|
||||
}
|
||||
|
||||
void GameRenderer::renderExitPopup(
|
||||
|
||||
Reference in New Issue
Block a user