new background for main screen
This commit is contained in:
78
src/main.cpp
78
src/main.cpp
@ -25,6 +25,7 @@
|
||||
#include "persistence/Scores.h"
|
||||
#include "graphics/effects/Starfield.h"
|
||||
#include "graphics/effects/Starfield3D.h"
|
||||
#include "graphics/effects/SpaceWarp.h"
|
||||
#include "graphics/ui/Font.h"
|
||||
#include "graphics/ui/HelpOverlay.h"
|
||||
#include "gameplay/effects/LineEffect.h"
|
||||
@ -680,16 +681,15 @@ static void drawFireworks_impl(SDL_Renderer* renderer, SDL_Texture*) {
|
||||
|
||||
SDL_SetRenderDrawBlendMode(renderer, previousBlend);
|
||||
}
|
||||
// External wrappers for use by other translation units (MenuState)
|
||||
// Expect callers to pass the blocks texture via StateContext so we avoid globals.
|
||||
void menu_drawFireworks(SDL_Renderer* renderer, SDL_Texture* blocksTex) { drawFireworks_impl(renderer, blocksTex); }
|
||||
void menu_updateFireworks(double frameMs) { updateFireworks(frameMs); }
|
||||
// External wrappers retained for compatibility; now no-ops to disable the legacy fireworks effect.
|
||||
void menu_drawFireworks(SDL_Renderer*, SDL_Texture*) {}
|
||||
void menu_updateFireworks(double) {}
|
||||
double menu_getLogoAnimCounter() { return logoAnimCounter; }
|
||||
int menu_getHoveredButton() { return hoveredButton; }
|
||||
|
||||
int main(int, char **)
|
||||
{
|
||||
// Initialize random seed for fireworks
|
||||
// Initialize random seed for procedural effects
|
||||
srand(static_cast<unsigned int>(SDL_GetTicks()));
|
||||
|
||||
// Load settings
|
||||
@ -779,6 +779,8 @@ int main(int, char **)
|
||||
starfield.init(200, LOGICAL_W, LOGICAL_H);
|
||||
Starfield3D starfield3D;
|
||||
starfield3D.init(LOGICAL_W, LOGICAL_H, 200);
|
||||
SpaceWarp spaceWarp;
|
||||
spaceWarp.init(LOGICAL_W, LOGICAL_H, 420);
|
||||
|
||||
// Initialize line clearing effects
|
||||
LineEffect lineEffect;
|
||||
@ -794,6 +796,27 @@ int main(int, char **)
|
||||
// Load menu background using SDL_image (prefers JPEG)
|
||||
SDL_Texture* backgroundTex = loadTextureFromImage(renderer, "assets/images/main_background.bmp");
|
||||
|
||||
// Load the new main screen overlay that sits above the background but below buttons
|
||||
int mainScreenW = 0;
|
||||
int mainScreenH = 0;
|
||||
SDL_Texture* mainScreenTex = loadTextureFromImage(renderer, "assets/images/main_screen_004.png", &mainScreenW, &mainScreenH);
|
||||
if (mainScreenTex) {
|
||||
SDL_SetTextureBlendMode(mainScreenTex, SDL_BLENDMODE_BLEND);
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Loaded main_screen overlay %dx%d (tex=%p)", mainScreenW, mainScreenH, (void*)mainScreenTex);
|
||||
FILE* f = fopen("tetris_trace.log", "a");
|
||||
if (f) {
|
||||
fprintf(f, "main.cpp: loaded main_screen.bmp %dx%d tex=%p\n", mainScreenW, mainScreenH, (void*)mainScreenTex);
|
||||
fclose(f);
|
||||
}
|
||||
} else {
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Failed to load assets/images/main_screen.bmp (overlay will be skipped)");
|
||||
FILE* f = fopen("tetris_trace.log", "a");
|
||||
if (f) {
|
||||
fprintf(f, "main.cpp: failed to load main_screen.bmp\n");
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
|
||||
// Note: `backgroundTex` is owned by main and passed into `StateContext::backgroundTex` below.
|
||||
// States should render using `ctx.backgroundTex` rather than accessing globals.
|
||||
|
||||
@ -971,6 +994,9 @@ int main(int, char **)
|
||||
ctx.logoSmallH = logoSmallH;
|
||||
ctx.backgroundTex = backgroundTex;
|
||||
ctx.blocksTex = blocksTex;
|
||||
ctx.mainScreenTex = mainScreenTex;
|
||||
ctx.mainScreenW = mainScreenW;
|
||||
ctx.mainScreenH = mainScreenH;
|
||||
ctx.musicEnabled = &musicEnabled;
|
||||
ctx.startLevelSelection = &startLevelSelection;
|
||||
ctx.hoveredButton = &hoveredButton;
|
||||
@ -1565,21 +1591,25 @@ int main(int, char **)
|
||||
}
|
||||
previousState = state;
|
||||
|
||||
// Update starfields based on current state
|
||||
// Update background effects
|
||||
if (state == AppState::Loading) {
|
||||
starfield3D.update(float(frameMs / 1000.0f));
|
||||
starfield3D.resize(logicalVP.w, logicalVP.h); // Update for window resize
|
||||
starfield3D.resize(winW, winH);
|
||||
} else {
|
||||
starfield.update(float(frameMs / 1000.0f), logicalVP.x * 2 + logicalVP.w, logicalVP.y * 2 + logicalVP.h);
|
||||
}
|
||||
|
||||
if (state == AppState::Menu) {
|
||||
spaceWarp.resize(winW, winH);
|
||||
spaceWarp.update(float(frameMs / 1000.0f));
|
||||
}
|
||||
|
||||
// Advance level background fade if a next texture is queued
|
||||
updateLevelBackgroundFade(levelBackgrounds, float(frameMs));
|
||||
|
||||
// Update intro animations
|
||||
if (state == AppState::Menu) {
|
||||
logoAnimCounter += frameMs * 0.0008; // Animation speed
|
||||
updateFireworks(frameMs);
|
||||
}
|
||||
|
||||
// --- Per-state update hooks (allow states to manage logic incrementally)
|
||||
@ -1671,7 +1701,7 @@ int main(int, char **)
|
||||
|
||||
// --- Render ---
|
||||
SDL_SetRenderViewport(renderer, nullptr);
|
||||
SDL_SetRenderDrawColor(renderer, 12, 12, 16, 255);
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
// Draw level-based background for gameplay, starfield for other states
|
||||
@ -1682,8 +1712,32 @@ int main(int, char **)
|
||||
} else if (state == AppState::Loading) {
|
||||
// Use 3D starfield for loading screen (full screen)
|
||||
starfield3D.draw(renderer);
|
||||
} else if (state == AppState::Menu || state == AppState::LevelSelector || state == AppState::Options) {
|
||||
// Use static background for menu, stretched to window; no starfield on sides
|
||||
} else if (state == AppState::Menu) {
|
||||
// Space flyover backdrop for the main screen
|
||||
spaceWarp.draw(renderer, 1.0f);
|
||||
|
||||
if (mainScreenTex) {
|
||||
float texW = mainScreenW > 0 ? static_cast<float>(mainScreenW) : 0.0f;
|
||||
float texH = mainScreenH > 0 ? static_cast<float>(mainScreenH) : 0.0f;
|
||||
if (texW <= 0.0f || texH <= 0.0f) {
|
||||
if (!SDL_GetTextureSize(mainScreenTex, &texW, &texH)) {
|
||||
texW = texH = 0.0f;
|
||||
}
|
||||
}
|
||||
if (texW > 0.0f && texH > 0.0f) {
|
||||
const float drawH = static_cast<float>(winH);
|
||||
const float scale = drawH / texH;
|
||||
const float drawW = texW * scale;
|
||||
SDL_FRect dst{
|
||||
(winW - drawW) * 0.5f,
|
||||
0.0f,
|
||||
drawW,
|
||||
drawH
|
||||
};
|
||||
SDL_RenderTexture(renderer, mainScreenTex, nullptr, &dst);
|
||||
}
|
||||
}
|
||||
} else if (state == AppState::LevelSelector || state == AppState::Options) {
|
||||
if (backgroundTex) {
|
||||
SDL_FRect fullRect = { 0, 0, (float)winW, (float)winH };
|
||||
SDL_RenderTexture(renderer, backgroundTex, nullptr, &fullRect);
|
||||
@ -2021,6 +2075,8 @@ int main(int, char **)
|
||||
SDL_DestroyTexture(logoTex);
|
||||
if (backgroundTex)
|
||||
SDL_DestroyTexture(backgroundTex);
|
||||
if (mainScreenTex)
|
||||
SDL_DestroyTexture(mainScreenTex);
|
||||
resetLevelBackgrounds(levelBackgrounds);
|
||||
if (blocksTex)
|
||||
SDL_DestroyTexture(blocksTex);
|
||||
|
||||
Reference in New Issue
Block a user