fixed main screen

This commit is contained in:
2025-11-23 13:41:00 +01:00
parent 1ac788b0a2
commit 6176e07ef1
2 changed files with 22 additions and 19 deletions

View File

@ -44,11 +44,11 @@ void GlobalState::shutdown() {
void GlobalState::updateFireworks(double frameMs) { void GlobalState::updateFireworks(double frameMs) {
const Uint64 currentTime = SDL_GetTicks(); const Uint64 currentTime = SDL_GetTicks();
// Create new fireworks occasionally // Create new fireworks less frequently for subtle background effect
if (currentTime - lastFireworkTime > 800 + (rand() % 1200)) { if (currentTime - lastFireworkTime > 1200 + (rand() % 1800)) { // Less frequent: 1200-3000ms
// Spawn bias similar to legacy: lower-right area // Spawn across wider area for better coverage
float x = Config::Logical::WIDTH * (0.55f + (rand() % 35) / 100.0f); // ~55% - 90% float x = Config::Logical::WIDTH * (0.15f + (rand() % 70) / 100.0f); // 15% - 85%
float y = Config::Logical::HEIGHT * (0.80f + (rand() % 15) / 100.0f); // ~80% - 95% float y = Config::Logical::HEIGHT * (0.20f + (rand() % 60) / 100.0f); // 20% - 80%
createFirework(x, y); createFirework(x, y);
lastFireworkTime = currentTime; lastFireworkTime = currentTime;
} }
@ -65,13 +65,13 @@ void GlobalState::updateFireworks(double frameMs) {
float dt = float(frameMs / 1000.0f); float dt = float(frameMs / 1000.0f);
particle.x += particle.vx * dt; particle.x += particle.vx * dt;
particle.y += particle.vy * dt; particle.y += particle.vy * dt;
particle.vx *= (1.0f - 0.6f * dt); // horizontal friction particle.vx *= (1.0f - 0.5f * dt); // Less friction for longer travel
particle.vy = particle.vy * (1.0f - 0.3f * dt) + 90.0f * dt; // gravity with damping particle.vy = particle.vy * (1.0f - 0.2f * dt) + 80.0f * dt; // Gentler gravity
particle.life -= frameMs; particle.life -= frameMs;
// Smaller particles overall // Smaller particles for subtle effect
float lifeRatio = particle.life / particle.maxLife; float lifeRatio = particle.life / particle.maxLife;
particle.size = 6.0f + 5.0f * lifeRatio; particle.size = 6.0f + 4.0f * lifeRatio; // Smaller particles
if (particle.life > 0) { if (particle.life > 0) {
hasActiveParticles = true; hasActiveParticles = true;
@ -102,8 +102,8 @@ void GlobalState::createFirework(float x, float y) {
firework->active = true; firework->active = true;
firework->particles.clear(); firework->particles.clear();
// Create particles // Create fewer particles for subtle background effect
const int particleCount = 10 + (rand() % 6); const int particleCount = 12 + (rand() % 8); // 12-20 particles per explosion
for (int i = 0; i < particleCount; ++i) { for (int i = 0; i < particleCount; ++i) {
BlockParticle particle; BlockParticle particle;
particle.x = x; particle.x = x;
@ -111,14 +111,14 @@ void GlobalState::createFirework(float x, float y) {
// Random velocity in all directions // Random velocity in all directions
float angle = (float)(rand() % 360) * 3.14159f / 180.0f; float angle = (float)(rand() % 360) * 3.14159f / 180.0f;
float speed = 70.0f + (rand() % 90); float speed = 80.0f + (rand() % 100); // Moderate speed
particle.vx = cos(angle) * speed; particle.vx = cos(angle) * speed;
particle.vy = sin(angle) * speed - 50.0f; // Slight upward bias particle.vy = sin(angle) * speed - 50.0f; // Slight upward bias
particle.type = 1 + (rand() % 7); // Random tetris piece color particle.type = 1 + (rand() % 7); // Random tetris piece color
particle.maxLife = 1200.0f + (rand() % 800); // ~1.2-2.0 seconds particle.maxLife = 1500.0f + (rand() % 1000); // Medium life: ~1.5-2.5 seconds
particle.life = particle.maxLife; particle.life = particle.maxLife;
particle.size = 6.0f + (rand() % 5); particle.size = 6.0f + (rand() % 5); // Smaller particles
firework->particles.push_back(particle); firework->particles.push_back(particle);
} }
@ -133,10 +133,10 @@ void GlobalState::drawFireworks(SDL_Renderer* renderer, SDL_Texture* blocksTex)
for (const auto& particle : firework.particles) { for (const auto& particle : firework.particles) {
if (particle.life <= 0) continue; if (particle.life <= 0) continue;
// Calculate alpha based on remaining life // Calculate alpha based on remaining life - more transparent for subtle effect
float lifeRatio = particle.life / particle.maxLife; float lifeRatio = particle.life / particle.maxLife;
// Faster fade like legacy // Reduced opacity: 50% of original for subtle background effect
Uint8 alpha = (Uint8)(255 * std::min(1.0f, lifeRatio * 1.6f)); Uint8 alpha = (Uint8)(128 * std::min(1.0f, lifeRatio * 1.6f));
// Set texture alpha // Set texture alpha
SDL_SetTextureAlphaMod(blocksTex, alpha); SDL_SetTextureAlphaMod(blocksTex, alpha);

View File

@ -148,8 +148,11 @@ void MenuState::handleEvent(const SDL_Event& e) {
} }
void MenuState::update(double frameMs) { void MenuState::update(double frameMs) {
// Update logo animation counter and particles similar to main // Update logo animation counter
(void)frameMs; GlobalState::instance().logoAnimCounter += frameMs;
// Update fireworks particles
GlobalState::instance().updateFireworks(frameMs);
} }
void MenuState::render(SDL_Renderer* renderer, float logicalScale, SDL_Rect logicalVP) { void MenuState::render(SDL_Renderer* renderer, float logicalScale, SDL_Rect logicalVP) {