afegides musiques

afegit control de brillo al starfield
This commit is contained in:
2025-12-03 19:27:36 +01:00
parent 3b0354da54
commit a3aeed4b7c
11 changed files with 109 additions and 29 deletions

View File

@@ -4,6 +4,7 @@
#include "escena_titol.hpp"
#include <cfloat>
#include <cmath>
#include <iostream>
#include <string>
@@ -15,6 +16,11 @@
#include "core/system/global_events.hpp"
#include "project.h"
namespace {
// Brightness del starfield (1.0 = default, >1.0 més brillant, <1.0 menys brillant)
constexpr float BRIGHTNESS_STARFIELD = 1.2f;
} // namespace
EscenaTitol::EscenaTitol(SDLManager& sdl)
: sdl_(sdl),
text_(sdl.obte_renderer()),
@@ -40,8 +46,21 @@ EscenaTitol::EscenaTitol(SDLManager& sdl)
150 // densitat: 150 estrelles (50 per capa)
);
// Configurar brightness del starfield
starfield_->set_brightness(BRIGHTNESS_STARFIELD);
// Inicialitzar lletres del títol "ORNI ATTACK!"
inicialitzar_titol();
// Iniciar música de títol si no està sonant
if (Audio::get()->getMusicState() != Audio::MusicState::PLAYING) {
Audio::get()->playMusic("title.ogg");
}
}
EscenaTitol::~EscenaTitol() {
// Aturar música de títol quan es destrueix l'escena
Audio::get()->stopMusic();
}
void EscenaTitol::inicialitzar_titol() {
@@ -256,9 +275,18 @@ void EscenaTitol::actualitzar(float delta_time) {
estat_actual_ = EstatTitol::MAIN;
}
break;
case EstatTitol::MAIN:
// No hi ha lògica d'actualització en l'estat MAIN
break;
case EstatTitol::TRANSITION:
temps_acumulat_ += delta_time;
if (temps_acumulat_ >= DURACIO_TRANSITION) {
// Transició a JOC (la música ja s'ha parat en el fade)
GestorEscenes::actual = GestorEscenes::Escena::JOC;
}
break;
}
}
@@ -273,8 +301,8 @@ void EscenaTitol::dibuixar() {
return;
}
// Estat MAIN: Dibuixar títol i text (sobre el starfield)
if (estat_actual_ == EstatTitol::MAIN) {
// Estat MAIN i TRANSITION: Dibuixar títol i text (sobre el starfield)
if (estat_actual_ == EstatTitol::MAIN || estat_actual_ == EstatTitol::TRANSITION) {
// === Dibuixar lletres del títol "ORNI ATTACK!" ===
// Dibuixar "ORNI" (línia 1)
@@ -303,19 +331,31 @@ void EscenaTitol::dibuixar() {
);
}
// === Text "PRESS BUTTON TO PLAY" (a sota del títol) ===
const std::string main_text = "PRESS BUTTON TO PLAY";
const float escala_main = 1.0f;
const float spacing = 2.0f;
// === Text "PRESS BUTTON TO PLAY" ===
// En estat MAIN: sempre visible
// En estat TRANSITION: parpellejant (blink amb sinusoide)
float text_width = text_.get_text_width(main_text, escala_main, spacing);
const float spacing = 2.0f; // Espai entre caràcters (usat també per copyright)
float x_center = (Defaults::Game::WIDTH - text_width) / 2.0f;
// Usar posició dinàmica: ATTACK + altura lletres + separació
float altura_attack = lletres_attack_.empty() ? 50.0f : lletres_attack_[0].altura;
float y_center = y_attack_dinamica_ + altura_attack + 70.0f; // 70px sota "ATTACK!"
bool mostrar_text = true;
if (estat_actual_ == EstatTitol::TRANSITION) {
// Parpelleig: sin oscil·la entre -1 i 1, volem ON quan > 0
float fase = temps_acumulat_ * BLINK_FREQUENCY * 2.0f * 3.14159f; // 2π × freq × temps
mostrar_text = (std::sin(fase) > 0.0f);
}
text_.render(main_text, Punt{x_center, y_center}, escala_main, spacing);
if (mostrar_text) {
const std::string main_text = "PRESS BUTTON TO PLAY";
const float escala_main = 1.0f;
float text_width = text_.get_text_width(main_text, escala_main, spacing);
float x_center = (Defaults::Game::WIDTH - text_width) / 2.0f;
float altura_attack = lletres_attack_.empty() ? 50.0f : lletres_attack_[0].altura;
float y_center = y_attack_dinamica_ + altura_attack + 70.0f;
text_.render(main_text, Punt{x_center, y_center}, escala_main, spacing);
}
// === Copyright a la part inferior (centrat horitzontalment) ===
// Convert to uppercase since VectorText only supports A-Z
@@ -346,9 +386,16 @@ void EscenaTitol::processar_events(const SDL_Event& event) {
// Saltar a MAIN
estat_actual_ = EstatTitol::MAIN;
break;
case EstatTitol::MAIN:
// Anar al joc
GestorEscenes::actual = GestorEscenes::Escena::JOC;
// Iniciar transició amb fade-out de música
estat_actual_ = EstatTitol::TRANSITION;
temps_acumulat_ = 0.0f; // Reset del comptador
Audio::get()->fadeOutMusic(MUSIC_FADE); // Fade de 300ms
break;
case EstatTitol::TRANSITION:
// Ignorar inputs durant la transició
break;
}
}