forked from jaildesigner-jailgames/jaildoctors_dilemma
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),
|
||||
last_active_letter_(0),
|
||||
state_time_(0.0F),
|
||||
fade_accumulator_(0.0F) {
|
||||
fade_accumulator_(0.0F),
|
||||
exit_scene_(SceneManager::Scene::GAME) {
|
||||
// Inicializa variables
|
||||
state_ = SceneManager::options == SceneManager::Options::TITLE_WITH_LOADING_SCREEN ? State::SHOW_LOADING_SCREEN : State::MAIN_MENU;
|
||||
SceneManager::current = SceneManager::Scene::TITLE;
|
||||
@@ -80,6 +81,7 @@ void Title::handleEvents() {
|
||||
case State::MAIN_MENU:
|
||||
switch (event.key.key) {
|
||||
case SDLK_1:
|
||||
exit_scene_ = SceneManager::Scene::GAME;
|
||||
transitionToState(State::FADE_MENU);
|
||||
break;
|
||||
|
||||
@@ -206,66 +208,31 @@ void Title::update() {
|
||||
void Title::updateState(float delta_time) {
|
||||
switch (state_) {
|
||||
case State::SHOW_LOADING_SCREEN:
|
||||
state_time_ += delta_time;
|
||||
if (state_time_ >= SHOW_LOADING_DURATION) {
|
||||
transitionToState(State::FADE_LOADING_SCREEN);
|
||||
}
|
||||
updateShowLoadingScreen(delta_time);
|
||||
break;
|
||||
|
||||
case State::FADE_LOADING_SCREEN:
|
||||
fade_accumulator_ += delta_time;
|
||||
if (fade_accumulator_ >= FADE_STEP_INTERVAL) {
|
||||
fade_accumulator_ = 0.0F;
|
||||
if (loading_screen_surface_->fadeSubPalette()) {
|
||||
transitionToState(State::MAIN_MENU);
|
||||
}
|
||||
}
|
||||
updateFadeLoadingScreen(delta_time);
|
||||
break;
|
||||
|
||||
case State::MAIN_MENU:
|
||||
// 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
|
||||
if (state_time_ >= AUTO_CREDITS_TIMEOUT) {
|
||||
SceneManager::current = SceneManager::Scene::CREDITS;
|
||||
SceneManager::options = SceneManager::Options::NONE;
|
||||
}
|
||||
updateMainMenu(delta_time);
|
||||
break;
|
||||
|
||||
case State::CHEEVOS_MENU:
|
||||
// Actualiza la marquesina (sigue visible en fondo)
|
||||
updateMarquee(delta_time);
|
||||
// No incrementar state_time_ (no timeout en este estado)
|
||||
updateCheevosMenu(delta_time);
|
||||
break;
|
||||
|
||||
case State::CONTROLS_MENU:
|
||||
// Actualiza la marquesina (sigue visible en fondo)
|
||||
updateMarquee(delta_time);
|
||||
// No incrementar state_time_ (no timeout en este estado)
|
||||
updateControlsMenu(delta_time);
|
||||
break;
|
||||
|
||||
case State::FADE_MENU:
|
||||
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);
|
||||
updateFadeMenu(delta_time);
|
||||
break;
|
||||
|
||||
case State::POST_FADE_MENU:
|
||||
state_time_ += delta_time;
|
||||
if (state_time_ >= POST_FADE_DELAY) {
|
||||
SceneManager::current = SceneManager::Scene::GAME;
|
||||
SceneManager::options = SceneManager::Options::NONE;
|
||||
}
|
||||
updatePostFadeMenu(delta_time);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -280,6 +247,76 @@ void Title::transitionToState(State new_state) {
|
||||
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
|
||||
void Title::render() {
|
||||
// Rellena la surface
|
||||
@@ -411,7 +448,7 @@ void Title::fillTitleSurface() {
|
||||
// Renderiza sobre la textura
|
||||
auto previuos_renderer = Screen::get()->getRendererSurface();
|
||||
Screen::get()->setRendererSurface(title_surface_);
|
||||
|
||||
|
||||
// Rellena la textura de color
|
||||
title_surface_->clear(static_cast<Uint8>(PaletteColor::BLACK));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user