fixed statistics panel
This commit is contained in:
42
src/main.cpp
42
src/main.cpp
@ -247,6 +247,31 @@ static void renderScaledBackground(SDL_Renderer* renderer, SDL_Texture* tex, int
|
||||
SDL_SetTextureAlphaMod(tex, 255);
|
||||
}
|
||||
|
||||
static void renderDynamicBackground(SDL_Renderer* renderer, SDL_Texture* tex, int winW, int winH, float baseScale, float motionClockMs, float alphaMul = 1.0f) {
|
||||
if (!renderer || !tex) {
|
||||
return;
|
||||
}
|
||||
|
||||
const float seconds = motionClockMs * 0.001f;
|
||||
const float wobble = std::max(0.4f, baseScale + std::sin(seconds * 0.07f) * 0.02f + std::sin(seconds * 0.23f) * 0.01f);
|
||||
const float rotation = std::sin(seconds * 0.035f) * 1.25f;
|
||||
const float panX = std::sin(seconds * 0.11f) * winW * 0.02f;
|
||||
const float panY = std::cos(seconds * 0.09f) * winH * 0.015f;
|
||||
|
||||
SDL_FRect dest{
|
||||
(winW - winW * wobble) * 0.5f + panX,
|
||||
(winH - winH * wobble) * 0.5f + panY,
|
||||
winW * wobble,
|
||||
winH * wobble
|
||||
};
|
||||
SDL_FPoint center{dest.w * 0.5f, dest.h * 0.5f};
|
||||
|
||||
Uint8 alpha = static_cast<Uint8>(std::clamp(alphaMul, 0.0f, 1.0f) * 255.0f);
|
||||
SDL_SetTextureAlphaMod(tex, alpha);
|
||||
SDL_RenderTextureRotated(renderer, tex, nullptr, &dest, rotation, ¢er, SDL_FLIP_NONE);
|
||||
SDL_SetTextureAlphaMod(tex, 255);
|
||||
}
|
||||
|
||||
static void drawOverlay(SDL_Renderer* renderer, const SDL_FRect& rect, SDL_Color color, Uint8 alpha) {
|
||||
if (!renderer || alpha == 0) {
|
||||
return;
|
||||
@ -257,7 +282,7 @@ static void drawOverlay(SDL_Renderer* renderer, const SDL_FRect& rect, SDL_Color
|
||||
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
|
||||
}
|
||||
|
||||
static void renderLevelBackgrounds(const LevelBackgroundFader& fader, SDL_Renderer* renderer, int winW, int winH) {
|
||||
static void renderLevelBackgrounds(const LevelBackgroundFader& fader, SDL_Renderer* renderer, int winW, int winH, float motionClockMs) {
|
||||
if (!renderer) {
|
||||
return;
|
||||
}
|
||||
@ -265,12 +290,13 @@ static void renderLevelBackgrounds(const LevelBackgroundFader& fader, SDL_Render
|
||||
SDL_FRect fullRect{0.f, 0.f, static_cast<float>(winW), static_cast<float>(winH)};
|
||||
const float duration = std::max(1.0f, fader.phaseDurationMs);
|
||||
const float progress = (fader.phase == LevelBackgroundPhase::Idle) ? 0.0f : std::clamp(fader.phaseElapsedMs / duration, 0.0f, 1.0f);
|
||||
const float seconds = motionClockMs * 0.001f;
|
||||
|
||||
switch (fader.phase) {
|
||||
case LevelBackgroundPhase::ZoomOut: {
|
||||
const float scale = 1.0f + progress * 0.15f;
|
||||
if (fader.currentTex) {
|
||||
renderScaledBackground(renderer, fader.currentTex, winW, winH, scale, Uint8((1.0f - progress * 0.4f) * 255.0f));
|
||||
renderDynamicBackground(renderer, fader.currentTex, winW, winH, scale, motionClockMs, (1.0f - progress * 0.4f));
|
||||
drawOverlay(renderer, fullRect, SDL_Color{0, 0, 0, 255}, Uint8(progress * 200.0f));
|
||||
}
|
||||
break;
|
||||
@ -279,16 +305,18 @@ static void renderLevelBackgrounds(const LevelBackgroundFader& fader, SDL_Render
|
||||
const float scale = 1.10f - progress * 0.10f;
|
||||
const Uint8 alpha = Uint8((0.4f + progress * 0.6f) * 255.0f);
|
||||
if (fader.currentTex) {
|
||||
renderScaledBackground(renderer, fader.currentTex, winW, winH, scale, alpha);
|
||||
renderDynamicBackground(renderer, fader.currentTex, winW, winH, scale, motionClockMs, alpha / 255.0f);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case LevelBackgroundPhase::Idle:
|
||||
default:
|
||||
if (fader.currentTex) {
|
||||
renderScaledBackground(renderer, fader.currentTex, winW, winH, 1.0f, 255);
|
||||
renderDynamicBackground(renderer, fader.currentTex, winW, winH, 1.02f, motionClockMs, 1.0f);
|
||||
float pulse = 0.35f + 0.25f * (0.5f + 0.5f * std::sin(seconds * 0.5f));
|
||||
drawOverlay(renderer, fullRect, SDL_Color{5, 12, 28, 255}, Uint8(pulse * 90.0f));
|
||||
} else if (fader.nextTex) {
|
||||
renderScaledBackground(renderer, fader.nextTex, winW, winH, 1.0f, 255);
|
||||
renderDynamicBackground(renderer, fader.nextTex, winW, winH, 1.02f, motionClockMs, 1.0f);
|
||||
} else {
|
||||
drawOverlay(renderer, fullRect, SDL_Color{0, 0, 0, 255}, 255);
|
||||
}
|
||||
@ -803,6 +831,7 @@ int main(int, char **)
|
||||
int gameplayCountdownIndex = 0;
|
||||
const double GAMEPLAY_COUNTDOWN_STEP_MS = 400.0;
|
||||
const std::array<const char*, 4> GAMEPLAY_COUNTDOWN_LABELS = { "3", "2", "1", "START" };
|
||||
double gameplayBackgroundClockMs = 0.0;
|
||||
|
||||
// Instantiate state manager
|
||||
StateManager stateMgr(state);
|
||||
@ -1268,6 +1297,7 @@ int main(int, char **)
|
||||
|
||||
// Cap frame time to avoid spiral of death (max 100ms)
|
||||
if (frameMs > 100.0) frameMs = 100.0;
|
||||
gameplayBackgroundClockMs += frameMs;
|
||||
const bool *ks = SDL_GetKeyboardState(nullptr);
|
||||
bool left = state == AppState::Playing && ks[SDL_SCANCODE_LEFT];
|
||||
bool right = state == AppState::Playing && ks[SDL_SCANCODE_RIGHT];
|
||||
@ -1573,7 +1603,7 @@ int main(int, char **)
|
||||
if (state == AppState::Playing) {
|
||||
int bgLevel = std::clamp(game.level(), 0, 32);
|
||||
queueLevelBackground(levelBackgrounds, renderer, bgLevel);
|
||||
renderLevelBackgrounds(levelBackgrounds, renderer, winW, winH);
|
||||
renderLevelBackgrounds(levelBackgrounds, renderer, winW, winH, static_cast<float>(gameplayBackgroundClockMs));
|
||||
} else if (state == AppState::Loading) {
|
||||
// Use 3D starfield for loading screen (full screen)
|
||||
starfield3D.draw(renderer);
|
||||
|
||||
Reference in New Issue
Block a user