Title: codi mes ordenat. Fade quan transiciona a Credits. Esqueleto preparat per a treballar en redefine keys/joystick
This commit is contained in:
@@ -32,7 +32,8 @@ Title::Title()
|
|||||||
first_active_letter_(0),
|
first_active_letter_(0),
|
||||||
last_active_letter_(0),
|
last_active_letter_(0),
|
||||||
state_time_(0.0F),
|
state_time_(0.0F),
|
||||||
fade_accumulator_(0.0F) {
|
fade_accumulator_(0.0F),
|
||||||
|
exit_scene_(SceneManager::Scene::GAME) {
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
state_ = SceneManager::options == SceneManager::Options::TITLE_WITH_LOADING_SCREEN ? State::SHOW_LOADING_SCREEN : State::MAIN_MENU;
|
state_ = SceneManager::options == SceneManager::Options::TITLE_WITH_LOADING_SCREEN ? State::SHOW_LOADING_SCREEN : State::MAIN_MENU;
|
||||||
SceneManager::current = SceneManager::Scene::TITLE;
|
SceneManager::current = SceneManager::Scene::TITLE;
|
||||||
@@ -80,6 +81,7 @@ void Title::handleEvents() {
|
|||||||
case State::MAIN_MENU:
|
case State::MAIN_MENU:
|
||||||
switch (event.key.key) {
|
switch (event.key.key) {
|
||||||
case SDLK_1:
|
case SDLK_1:
|
||||||
|
exit_scene_ = SceneManager::Scene::GAME;
|
||||||
transitionToState(State::FADE_MENU);
|
transitionToState(State::FADE_MENU);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -206,66 +208,31 @@ void Title::update() {
|
|||||||
void Title::updateState(float delta_time) {
|
void Title::updateState(float delta_time) {
|
||||||
switch (state_) {
|
switch (state_) {
|
||||||
case State::SHOW_LOADING_SCREEN:
|
case State::SHOW_LOADING_SCREEN:
|
||||||
state_time_ += delta_time;
|
updateShowLoadingScreen(delta_time);
|
||||||
if (state_time_ >= SHOW_LOADING_DURATION) {
|
|
||||||
transitionToState(State::FADE_LOADING_SCREEN);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case State::FADE_LOADING_SCREEN:
|
case State::FADE_LOADING_SCREEN:
|
||||||
fade_accumulator_ += delta_time;
|
updateFadeLoadingScreen(delta_time);
|
||||||
if (fade_accumulator_ >= FADE_STEP_INTERVAL) {
|
|
||||||
fade_accumulator_ = 0.0F;
|
|
||||||
if (loading_screen_surface_->fadeSubPalette()) {
|
|
||||||
transitionToState(State::MAIN_MENU);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case State::MAIN_MENU:
|
case State::MAIN_MENU:
|
||||||
// Actualiza la marquesina
|
updateMainMenu(delta_time);
|
||||||
updateMarquee(delta_time);
|
|
||||||
|
|
||||||
// Incrementa el temporizador solo en el menú principal
|
|
||||||
state_time_ += delta_time;
|
|
||||||
|
|
||||||
// Si el tiempo alcanza el timeout, va a créditos
|
|
||||||
if (state_time_ >= AUTO_CREDITS_TIMEOUT) {
|
|
||||||
SceneManager::current = SceneManager::Scene::CREDITS;
|
|
||||||
SceneManager::options = SceneManager::Options::NONE;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case State::CHEEVOS_MENU:
|
case State::CHEEVOS_MENU:
|
||||||
// Actualiza la marquesina (sigue visible en fondo)
|
updateCheevosMenu(delta_time);
|
||||||
updateMarquee(delta_time);
|
|
||||||
// No incrementar state_time_ (no timeout en este estado)
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case State::CONTROLS_MENU:
|
case State::CONTROLS_MENU:
|
||||||
// Actualiza la marquesina (sigue visible en fondo)
|
updateControlsMenu(delta_time);
|
||||||
updateMarquee(delta_time);
|
|
||||||
// No incrementar state_time_ (no timeout en este estado)
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case State::FADE_MENU:
|
case State::FADE_MENU:
|
||||||
fade_accumulator_ += delta_time;
|
updateFadeMenu(delta_time);
|
||||||
if (fade_accumulator_ >= FADE_STEP_INTERVAL) {
|
|
||||||
fade_accumulator_ = 0.0F;
|
|
||||||
if (title_surface_->fadeSubPalette()) {
|
|
||||||
transitionToState(State::POST_FADE_MENU);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Actualiza la marquesina (sigue visible en fondo)
|
|
||||||
updateMarquee(delta_time);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case State::POST_FADE_MENU:
|
case State::POST_FADE_MENU:
|
||||||
state_time_ += delta_time;
|
updatePostFadeMenu(delta_time);
|
||||||
if (state_time_ >= POST_FADE_DELAY) {
|
|
||||||
SceneManager::current = SceneManager::Scene::GAME;
|
|
||||||
SceneManager::options = SceneManager::Options::NONE;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -280,6 +247,76 @@ void Title::transitionToState(State new_state) {
|
|||||||
fade_accumulator_ = 0.0F;
|
fade_accumulator_ = 0.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Actualiza el estado SHOW_LOADING_SCREEN
|
||||||
|
void Title::updateShowLoadingScreen(float delta_time) {
|
||||||
|
state_time_ += delta_time;
|
||||||
|
if (state_time_ >= SHOW_LOADING_DURATION) {
|
||||||
|
transitionToState(State::FADE_LOADING_SCREEN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza el estado FADE_LOADING_SCREEN
|
||||||
|
void Title::updateFadeLoadingScreen(float delta_time) {
|
||||||
|
fade_accumulator_ += delta_time;
|
||||||
|
if (fade_accumulator_ >= FADE_STEP_INTERVAL) {
|
||||||
|
fade_accumulator_ = 0.0F;
|
||||||
|
if (loading_screen_surface_->fadeSubPalette()) {
|
||||||
|
transitionToState(State::MAIN_MENU);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza el estado MAIN_MENU
|
||||||
|
void Title::updateMainMenu(float delta_time) {
|
||||||
|
// Actualiza la marquesina
|
||||||
|
updateMarquee(delta_time);
|
||||||
|
|
||||||
|
// Incrementa el temporizador solo en el menú principal
|
||||||
|
state_time_ += delta_time;
|
||||||
|
|
||||||
|
// Si el tiempo alcanza el timeout, va a créditos con fade
|
||||||
|
if (state_time_ >= MAIN_MENU_IDLE_TIMEOUT) {
|
||||||
|
exit_scene_ = SceneManager::Scene::CREDITS;
|
||||||
|
transitionToState(State::FADE_MENU);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza el estado CHEEVOS_MENU
|
||||||
|
void Title::updateCheevosMenu(float delta_time) {
|
||||||
|
// Actualiza la marquesina (sigue visible en fondo)
|
||||||
|
updateMarquee(delta_time);
|
||||||
|
// No incrementar state_time_ (no timeout en este estado)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza el estado CONTROLS_MENU
|
||||||
|
void Title::updateControlsMenu(float delta_time) {
|
||||||
|
// Actualiza la marquesina (sigue visible en fondo)
|
||||||
|
updateMarquee(delta_time);
|
||||||
|
// No incrementar state_time_ (no timeout en este estado)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza el estado FADE_MENU
|
||||||
|
void Title::updateFadeMenu(float delta_time) {
|
||||||
|
fade_accumulator_ += delta_time;
|
||||||
|
if (fade_accumulator_ >= FADE_STEP_INTERVAL) {
|
||||||
|
fade_accumulator_ = 0.0F;
|
||||||
|
if (title_surface_->fadeSubPalette()) {
|
||||||
|
transitionToState(State::POST_FADE_MENU);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Actualiza la marquesina (sigue visible en fondo)
|
||||||
|
updateMarquee(delta_time);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza el estado POST_FADE_MENU
|
||||||
|
void Title::updatePostFadeMenu(float delta_time) {
|
||||||
|
state_time_ += delta_time;
|
||||||
|
if (state_time_ >= POST_FADE_DELAY) {
|
||||||
|
SceneManager::current = exit_scene_;
|
||||||
|
SceneManager::options = SceneManager::Options::NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Dibuja en pantalla
|
// Dibuja en pantalla
|
||||||
void Title::render() {
|
void Title::render() {
|
||||||
// Rellena la surface
|
// Rellena la surface
|
||||||
|
|||||||
@@ -6,10 +6,11 @@
|
|||||||
#include <string> // Para string
|
#include <string> // Para string
|
||||||
#include <vector> // Para vector
|
#include <vector> // Para vector
|
||||||
|
|
||||||
#include "utils/delta_timer.hpp" // Para DeltaTimer
|
#include "game/scene_manager.hpp" // Para SceneManager::Scene
|
||||||
class SurfaceSprite; // Forward declaration
|
#include "utils/delta_timer.hpp" // Para DeltaTimer
|
||||||
class Surface; // Forward declaration
|
class SurfaceSprite; // Forward declaration
|
||||||
class Text; // Forward declaration
|
class Surface; // Forward declaration
|
||||||
|
class Text; // Forward declaration
|
||||||
|
|
||||||
class Title {
|
class Title {
|
||||||
public:
|
public:
|
||||||
@@ -40,12 +41,12 @@ class Title {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// --- Constantes de tiempo (en segundos) ---
|
// --- Constantes de tiempo (en segundos) ---
|
||||||
static constexpr float SHOW_LOADING_DURATION = 5.0F; // Tiempo mostrando loading screen (antes 500 frames)
|
static constexpr float SHOW_LOADING_DURATION = 5.0F; // Tiempo mostrando loading screen (antes 500 frames)
|
||||||
static constexpr float FADE_STEP_INTERVAL = 0.05F; // Intervalo entre pasos de fade (antes cada 4 frames)
|
static constexpr float FADE_STEP_INTERVAL = 0.05F; // Intervalo entre pasos de fade (antes cada 4 frames)
|
||||||
static constexpr float POST_FADE_DELAY = 1.0F; // Delay después del fade (pantalla en negro)
|
static constexpr float POST_FADE_DELAY = 1.0F; // Delay después del fade (pantalla en negro)
|
||||||
static constexpr float AUTO_CREDITS_TIMEOUT = 20.0F; // Timeout para ir a créditos (antes 2200 frames)
|
static constexpr float MAIN_MENU_IDLE_TIMEOUT = 20.0F; // Timeout para ir a créditos (antes 2200 frames)
|
||||||
static constexpr float MARQUEE_SPEED = 100.0F; // Velocidad de marquesina (pixels/segundo)
|
static constexpr float MARQUEE_SPEED = 100.0F; // Velocidad de marquesina (pixels/segundo)
|
||||||
static constexpr float CHEEVOS_SCROLL_SPEED = 120.0F; // Velocidad de scroll de logros (pixels/segundo)
|
static constexpr float CHEEVOS_SCROLL_SPEED = 120.0F; // Velocidad de scroll de logros (pixels/segundo)
|
||||||
|
|
||||||
// --- Constantes de marquesina ---
|
// --- Constantes de marquesina ---
|
||||||
static constexpr float MARQUEE_START_X = 256.0F; // Posición inicial (ancho pantalla)
|
static constexpr float MARQUEE_START_X = 256.0F; // Posición inicial (ancho pantalla)
|
||||||
@@ -74,6 +75,7 @@ class Title {
|
|||||||
State state_; // Estado en el que se encuentra el bucle principal
|
State state_; // Estado en el que se encuentra el bucle principal
|
||||||
float state_time_; // Tiempo acumulado en el estado actual
|
float state_time_; // Tiempo acumulado en el estado actual
|
||||||
float fade_accumulator_; // Acumulador para controlar el fade por tiempo
|
float fade_accumulator_; // Acumulador para controlar el fade por tiempo
|
||||||
|
SceneManager::Scene exit_scene_; // Escena de destino al salir del título
|
||||||
|
|
||||||
// --- Funciones ---
|
// --- Funciones ---
|
||||||
void update(); // Actualiza las variables
|
void update(); // Actualiza las variables
|
||||||
@@ -82,6 +84,13 @@ class Title {
|
|||||||
void handleInput(float delta_time); // Comprueba las entradas
|
void handleInput(float delta_time); // Comprueba las entradas
|
||||||
void updateState(float delta_time); // Actualiza el estado actual
|
void updateState(float delta_time); // Actualiza el estado actual
|
||||||
void transitionToState(State new_state); // Transiciona a un nuevo estado
|
void transitionToState(State new_state); // Transiciona a un nuevo estado
|
||||||
|
void updateShowLoadingScreen(float delta_time); // Actualiza SHOW_LOADING_SCREEN
|
||||||
|
void updateFadeLoadingScreen(float delta_time); // Actualiza FADE_LOADING_SCREEN
|
||||||
|
void updateMainMenu(float delta_time); // Actualiza MAIN_MENU
|
||||||
|
void updateCheevosMenu(float delta_time); // Actualiza CHEEVOS_MENU
|
||||||
|
void updateControlsMenu(float delta_time); // Actualiza CONTROLS_MENU
|
||||||
|
void updateFadeMenu(float delta_time); // Actualiza FADE_MENU
|
||||||
|
void updatePostFadeMenu(float delta_time); // Actualiza POST_FADE_MENU
|
||||||
void initMarquee(); // Inicializa la marquesina
|
void initMarquee(); // Inicializa la marquesina
|
||||||
void updateMarquee(float delta_time); // Actualiza la marquesina (time-based)
|
void updateMarquee(float delta_time); // Actualiza la marquesina (time-based)
|
||||||
void renderMarquee(); // Dibuja la marquesina
|
void renderMarquee(); // Dibuja la marquesina
|
||||||
|
|||||||
Reference in New Issue
Block a user