treballant en context per a jugador 1, jugador 2 o els dos

This commit is contained in:
2025-12-12 10:43:17 +01:00
parent 0ceaa75862
commit 0c75f56cb5
6 changed files with 217 additions and 53 deletions

View File

@@ -34,6 +34,11 @@ EscenaTitol::EscenaTitol(SDLManager& sdl, ContextEscenes& context)
factor_lerp_(0.0f) {
std::cout << "Escena Titol: Inicialitzant...\n";
// Inicialitzar configuració de partida (cap jugador actiu per defecte)
config_partida_.jugador1_actiu = false;
config_partida_.jugador2_actiu = false;
config_partida_.mode = GameConfig::Mode::NORMAL;
// Processar opció del context
auto opcio = context_.consumir_opcio();
@@ -366,6 +371,25 @@ void EscenaTitol::actualitzar(float delta_time) {
// Continuar animació orbital durant la transició
actualitzar_animacio_logo(delta_time);
// [NOU] Continuar comprovant si l'altre jugador vol unir-se durant la transició
auto* input = Input::get();
for (auto action : SKIP_BUTTONS_TITOL) {
if (input->checkActionPlayer1(action, Input::DO_NOT_ALLOW_REPEAT)) {
if (!config_partida_.jugador1_actiu) {
config_partida_.jugador1_actiu = true;
context_.set_config_partida(config_partida_);
std::cout << "[EscenaTitol] P1 s'ha unit durant la transició!\n";
}
}
if (input->checkActionPlayer2(action, Input::DO_NOT_ALLOW_REPEAT)) {
if (!config_partida_.jugador2_actiu) {
config_partida_.jugador2_actiu = true;
context_.set_config_partida(config_partida_);
std::cout << "[EscenaTitol] P2 s'ha unit durant la transició!\n";
}
}
}
if (temps_acumulat_ >= DURACIO_TRANSITION) {
// Transició a JOC (la música ja s'ha parat en el fade)
GestorEscenes::actual = Escena::JOC;
@@ -391,6 +415,14 @@ void EscenaTitol::actualitzar(float delta_time) {
case EstatTitol::MAIN:
// Iniciar partida (transición a JOC)
// Configurar partida abans de canviar d'escena
context_.set_config_partida(config_partida_);
std::cout << "[EscenaTitol] Configuració de partida - P1: "
<< (config_partida_.jugador1_actiu ? "ACTIU" : "INACTIU")
<< ", P2: "
<< (config_partida_.jugador2_actiu ? "ACTIU" : "INACTIU")
<< std::endl;
context_.canviar_escena(Escena::JOC);
estat_actual_ = EstatTitol::TRANSITION_TO_GAME;
temps_acumulat_ = 0.0f;
@@ -577,13 +609,21 @@ void EscenaTitol::dibuixar() {
auto EscenaTitol::checkSkipButtonPressed() -> bool {
auto* input = Input::get();
bool p1_pressed = false;
bool p2_pressed = false;
for (auto action : SKIP_BUTTONS_TITOL) {
if (input->checkActionPlayer1(action, Input::DO_NOT_ALLOW_REPEAT) ||
input->checkActionPlayer2(action, Input::DO_NOT_ALLOW_REPEAT)) {
return true;
if (input->checkActionPlayer1(action, Input::DO_NOT_ALLOW_REPEAT)) {
p1_pressed = true;
config_partida_.jugador1_actiu = true; // Marcar P1 com a actiu
}
if (input->checkActionPlayer2(action, Input::DO_NOT_ALLOW_REPEAT)) {
p2_pressed = true;
config_partida_.jugador2_actiu = true; // Marcar P2 com a actiu
}
}
return false;
return p1_pressed || p2_pressed;
}
void EscenaTitol::processar_events(const SDL_Event& event) {