forked from jaildesigner-jailgames/jaildoctors_dilemma
migrat Credits a time based
This commit is contained in:
@@ -33,11 +33,11 @@ enum class Options {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// --- Variables de estado globales ---
|
// --- Variables de estado globales ---
|
||||||
#ifndef _DEBUG
|
#ifdef _DEBUG
|
||||||
inline Scene current = Scene::LOGO; // Escena actual
|
inline Scene current = Scene::CREDITS; // Escena actual
|
||||||
inline Options options = Options::LOGO_TO_LOADING_SCREEN; // Opciones de la escena actual
|
inline Options options = Options::LOGO_TO_LOADING_SCREEN; // Opciones de la escena actual
|
||||||
#else
|
#else
|
||||||
inline Scene current = Scene::GAME; // Escena actual
|
inline Scene current = Scene::LOGO; // Escena actual
|
||||||
inline Options options = Options::LOGO_TO_LOADING_SCREEN; // Opciones de la escena actual
|
inline Options options = Options::LOGO_TO_LOADING_SCREEN; // Opciones de la escena actual
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -10,15 +10,17 @@
|
|||||||
#include "core/rendering/surface_animated_sprite.hpp" // Para SAnimatedSprite
|
#include "core/rendering/surface_animated_sprite.hpp" // Para SAnimatedSprite
|
||||||
#include "core/rendering/text.hpp" // Para Text, TEXT_CENTER, TEXT_COLOR
|
#include "core/rendering/text.hpp" // Para Text, TEXT_CENTER, TEXT_COLOR
|
||||||
#include "core/resources/resource.hpp" // Para Resource
|
#include "core/resources/resource.hpp" // Para Resource
|
||||||
|
#include "core/system/global_events.hpp" // Para check
|
||||||
#include "game/options.hpp" // Para Options, options, OptionsGame, Sectio...
|
#include "game/options.hpp" // Para Options, options, OptionsGame, Sectio...
|
||||||
#include "game/scene_manager.hpp" // Para SceneManager
|
#include "game/scene_manager.hpp" // Para SceneManager
|
||||||
#include "utils/defines.hpp" // Para GAME_SPEED, PLAY_AREA_CENTER_X, PLAY_...
|
#include "utils/defines.hpp" // Para GAME_SPEED, PLAY_AREA_CENTER_X, PLAY_...
|
||||||
#include "core/system/global_events.hpp" // Para check
|
#include "utils/delta_timer.hpp" // Para DeltaTimer
|
||||||
#include "utils/utils.hpp" // Para PaletteColor
|
#include "utils/utils.hpp" // Para PaletteColor
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Credits::Credits()
|
Credits::Credits()
|
||||||
: shining_sprite_(std::make_shared<SurfaceAnimatedSprite>(Resource::get()->getAnimations("shine.ani"))) {
|
: shining_sprite_(std::make_shared<SurfaceAnimatedSprite>(Resource::get()->getAnimations("shine.ani"))),
|
||||||
|
delta_timer_(std::make_unique<DeltaTimer>()) {
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
SceneManager::current = SceneManager::Scene::CREDITS;
|
SceneManager::current = SceneManager::Scene::CREDITS;
|
||||||
SceneManager::options = SceneManager::Options::NONE;
|
SceneManager::options = SceneManager::Options::NONE;
|
||||||
@@ -148,47 +150,99 @@ void Credits::fillTexture() {
|
|||||||
cover_surface_->fillRect(&rect, color);
|
cover_surface_->fillRect(&rect, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el contador
|
// Actualiza las variables
|
||||||
void Credits::updateCounter() {
|
void Credits::update() {
|
||||||
// Incrementa el contador
|
// Obtiene el delta time
|
||||||
if (counter_enabled_) {
|
current_delta_ = delta_timer_->tick();
|
||||||
counter_++;
|
|
||||||
if (counter_ == 224 || counter_ == 544 || counter_ == 672) {
|
|
||||||
counter_enabled_ = false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sub_counter_++;
|
|
||||||
if (sub_counter_ == 100) {
|
|
||||||
counter_enabled_ = true;
|
|
||||||
sub_counter_ = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba si ha terminado la sección
|
// Comprueba las entradas
|
||||||
if (counter_ > 1200) {
|
checkInput();
|
||||||
SceneManager::current = SceneManager::Scene::DEMO;
|
|
||||||
|
// Actualiza el tiempo total
|
||||||
|
total_time_ += current_delta_;
|
||||||
|
|
||||||
|
// Actualiza la máquina de estados
|
||||||
|
updateState(current_delta_);
|
||||||
|
|
||||||
|
// Actualiza la pantalla
|
||||||
|
Screen::get()->update(current_delta_);
|
||||||
|
|
||||||
|
// Actualiza el sprite con el brillo si está después del tiempo de inicio
|
||||||
|
if (reveal_time_ > SHINE_START_TIME) {
|
||||||
|
shining_sprite_->update(current_delta_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las variables
|
// Transición entre estados
|
||||||
void Credits::update() {
|
void Credits::transitionToState(State new_state) {
|
||||||
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
state_ = new_state;
|
||||||
if (SDL_GetTicks() - ticks_ > GAME_SPEED) {
|
state_time_ = 0.0F;
|
||||||
// Actualiza el contador de ticks
|
}
|
||||||
ticks_ = SDL_GetTicks();
|
|
||||||
|
|
||||||
// Comprueba las entradas
|
// Actualiza la máquina de estados
|
||||||
checkInput();
|
void Credits::updateState(float delta_time) {
|
||||||
|
state_time_ += delta_time;
|
||||||
|
|
||||||
// Actualiza el contador
|
switch (state_) {
|
||||||
updateCounter();
|
case State::REVEALING_TEXT:
|
||||||
|
reveal_time_ += delta_time; // Incrementa reveal_time durante revelación
|
||||||
|
if (state_time_ >= REVEAL_PHASE_1_DURATION) {
|
||||||
|
transitionToState(State::PAUSE_1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
Screen::get()->update();
|
case State::PAUSE_1:
|
||||||
|
// reveal_time_ NO incrementa durante pausa (se congela)
|
||||||
|
if (state_time_ >= PAUSE_DURATION) {
|
||||||
|
transitionToState(State::REVEALING_TEXT_2);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
// Actualiza el sprite con el brillo
|
case State::REVEALING_TEXT_2:
|
||||||
if (counter_ > 770) {
|
reveal_time_ += delta_time; // Incrementa reveal_time durante revelación
|
||||||
shining_sprite_->update();
|
if (state_time_ >= REVEAL_PHASE_2_DURATION) {
|
||||||
}
|
transitionToState(State::PAUSE_2);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case State::PAUSE_2:
|
||||||
|
// reveal_time_ NO incrementa durante pausa (se congela)
|
||||||
|
if (state_time_ >= PAUSE_DURATION) {
|
||||||
|
transitionToState(State::REVEALING_TEXT_3);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case State::REVEALING_TEXT_3:
|
||||||
|
reveal_time_ += delta_time; // Incrementa reveal_time durante revelación
|
||||||
|
if (state_time_ >= REVEAL_PHASE_3_DURATION) {
|
||||||
|
transitionToState(State::PAUSE_3);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case State::PAUSE_3:
|
||||||
|
// reveal_time_ NO incrementa durante pausa (se congela)
|
||||||
|
if (state_time_ >= PAUSE_DURATION) {
|
||||||
|
transitionToState(State::DISPLAYING_WITH_SHINE);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case State::DISPLAYING_WITH_SHINE:
|
||||||
|
reveal_time_ += delta_time; // Incrementa reveal_time durante revelación
|
||||||
|
if (state_time_ >= DISPLAY_WITH_SHINE_DURATION) {
|
||||||
|
transitionToState(State::FADING_OUT);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case State::FADING_OUT:
|
||||||
|
reveal_time_ += delta_time; // Incrementa reveal_time durante fade
|
||||||
|
if (state_time_ >= FADE_OUT_DURATION) {
|
||||||
|
transitionToState(State::EXITING);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case State::EXITING:
|
||||||
|
SceneManager::current = SceneManager::Scene::DEMO;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,14 +254,15 @@ void Credits::render() {
|
|||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
Screen::get()->clearSurface(static_cast<Uint8>(PaletteColor::BLACK));
|
Screen::get()->clearSurface(static_cast<Uint8>(PaletteColor::BLACK));
|
||||||
|
|
||||||
if (counter_ < 1150) {
|
if (state_ != State::EXITING) {
|
||||||
// Dibuja la textura con el texto en pantalla
|
// Dibuja la textura con el texto en pantalla
|
||||||
text_surface_->render(0, 0);
|
text_surface_->render(0, 0);
|
||||||
|
|
||||||
// Dibuja la textura que cubre el texto
|
// Dibuja la textura que cubre el texto
|
||||||
const int OFFSET = std::min(counter_ / 8, 192 / 2);
|
// OFFSET basado en reveal_time_ (que se congela durante pausas, como counter_ original)
|
||||||
|
const float OFFSET = std::min(reveal_time_ * REVEAL_SPEED / 8.0F, 192.0F / 2.0F);
|
||||||
SDL_FRect src_rect = {0.0F, 0.0F, 256.0F, 192.0F - (OFFSET * 2.0F)};
|
SDL_FRect src_rect = {0.0F, 0.0F, 256.0F, 192.0F - (OFFSET * 2.0F)};
|
||||||
cover_surface_->render(0, OFFSET * 2, &src_rect);
|
cover_surface_->render(0, static_cast<int>(OFFSET * 2.0F), &src_rect);
|
||||||
|
|
||||||
// Dibuja el sprite con el brillo
|
// Dibuja el sprite con el brillo
|
||||||
shining_sprite_->render(1, static_cast<Uint8>(PaletteColor::BRIGHT_WHITE));
|
shining_sprite_->render(1, static_cast<Uint8>(PaletteColor::BRIGHT_WHITE));
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <vector> // Para vector
|
#include <vector> // Para vector
|
||||||
class SurfaceAnimatedSprite; // lines 11-11
|
class SurfaceAnimatedSprite; // lines 11-11
|
||||||
class Surface;
|
class Surface;
|
||||||
|
class DeltaTimer;
|
||||||
|
|
||||||
class Credits {
|
class Credits {
|
||||||
public:
|
public:
|
||||||
@@ -18,6 +19,30 @@ class Credits {
|
|||||||
void run();
|
void run();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// --- Estados ---
|
||||||
|
enum class State {
|
||||||
|
REVEALING_TEXT,
|
||||||
|
PAUSE_1,
|
||||||
|
REVEALING_TEXT_2,
|
||||||
|
PAUSE_2,
|
||||||
|
REVEALING_TEXT_3,
|
||||||
|
PAUSE_3,
|
||||||
|
DISPLAYING_WITH_SHINE,
|
||||||
|
FADING_OUT,
|
||||||
|
EXITING
|
||||||
|
};
|
||||||
|
|
||||||
|
// --- Constantes de tiempo (basado en 60 FPS) ---
|
||||||
|
static constexpr float REVEAL_PHASE_1_DURATION = 3.733F; // 224 frames @ 60fps
|
||||||
|
static constexpr float PAUSE_DURATION = 1.667F; // 100 frames @ 60fps
|
||||||
|
static constexpr float REVEAL_PHASE_2_DURATION = 5.333F; // 320 frames (544-224) @ 60fps
|
||||||
|
static constexpr float REVEAL_PHASE_3_DURATION = 2.133F; // 128 frames (672-544) @ 60fps
|
||||||
|
static constexpr float DISPLAY_WITH_SHINE_DURATION = 7.967F; // 478 frames (1150-672) @ 60fps
|
||||||
|
static constexpr float FADE_OUT_DURATION = 0.833F; // 50 frames (1200-1150) @ 60fps
|
||||||
|
static constexpr float TOTAL_DURATION = 20.0F; // 1200 frames @ 60fps
|
||||||
|
static constexpr float SHINE_START_TIME = 12.833F; // 770 frames @ 60fps
|
||||||
|
static constexpr float FADE_OUT_START = 19.167F; // 1150 frames @ 60fps
|
||||||
|
static constexpr float REVEAL_SPEED = 60.0F; // counter equivalente por segundo @ 60fps
|
||||||
struct Captions {
|
struct Captions {
|
||||||
std::string label; // Texto a escribir
|
std::string label; // Texto a escribir
|
||||||
Uint8 color; // Color del texto
|
Uint8 color; // Color del texto
|
||||||
@@ -29,18 +54,21 @@ class Credits {
|
|||||||
std::shared_ptr<SurfaceAnimatedSprite> shining_sprite_; // Sprite para el brillo del corazón
|
std::shared_ptr<SurfaceAnimatedSprite> shining_sprite_; // Sprite para el brillo del corazón
|
||||||
|
|
||||||
// --- Variables ---
|
// --- Variables ---
|
||||||
int counter_ = 0; // Contador
|
std::unique_ptr<DeltaTimer> delta_timer_; // Temporizador delta para time-based update
|
||||||
bool counter_enabled_ = true; // Indica si esta activo el contador
|
State state_ = State::REVEALING_TEXT; // Estado actual
|
||||||
int sub_counter_ = 0; // Contador secundario
|
float state_time_ = 0.0F; // Tiempo acumulado en el estado actual
|
||||||
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
|
float total_time_ = 0.0F; // Tiempo total acumulado
|
||||||
std::vector<Captions> texts_; // Vector con los textos
|
float reveal_time_ = 0.0F; // Tiempo acumulado solo durante revelación (se congela en pausas)
|
||||||
|
float current_delta_ = 0.0F; // Delta time del frame actual
|
||||||
|
std::vector<Captions> texts_; // Vector con los textos
|
||||||
|
|
||||||
// --- Funciones ---
|
// --- Funciones ---
|
||||||
void update(); // Actualiza las variables
|
void update(); // Actualiza las variables
|
||||||
void render(); // Dibuja en pantalla
|
void render(); // Dibuja en pantalla
|
||||||
static void checkEvents(); // Comprueba el manejador de eventos
|
static void checkEvents(); // Comprueba el manejador de eventos
|
||||||
static void checkInput(); // Comprueba las entradas
|
static void checkInput(); // Comprueba las entradas
|
||||||
void updateCounter(); // Actualiza el contador
|
void updateState(float delta_time); // Actualiza la máquina de estados
|
||||||
void iniTexts(); // Inicializa los textos
|
void transitionToState(State new_state); // Transición entre estados
|
||||||
void fillTexture(); // Escribe el texto en la textura
|
void iniTexts(); // Inicializa los textos
|
||||||
|
void fillTexture(); // Escribe el texto en la textura
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user