forked from jaildesigner-jailgames/jaildoctors_dilemma
migrat Logo a time based
This commit is contained in:
@@ -86,6 +86,7 @@ set(APP_SOURCES
|
|||||||
source/game/ui/notifier.cpp
|
source/game/ui/notifier.cpp
|
||||||
|
|
||||||
# Utils
|
# Utils
|
||||||
|
source/utils/delta_timer.cpp
|
||||||
source/utils/global_events.cpp
|
source/utils/global_events.cpp
|
||||||
source/utils/utils.cpp
|
source/utils/utils.cpp
|
||||||
|
|
||||||
|
|||||||
@@ -15,18 +15,7 @@
|
|||||||
#include "utils/utils.hpp" // Para stringToBool, boolToString, safeStoi
|
#include "utils/utils.hpp" // Para stringToBool, boolToString, safeStoi
|
||||||
|
|
||||||
namespace Options {
|
namespace Options {
|
||||||
// --- Variables globales ---
|
// Declaración de función interna
|
||||||
std::string version; // Versión del fichero de configuración. Sirve para saber si las opciones son compatibles
|
|
||||||
bool console; // Indica si ha de mostrar información por la consola de texto
|
|
||||||
Cheat cheats; // Contiene trucos y ventajas para el juego
|
|
||||||
Game game; // Opciones de juego
|
|
||||||
Video video; // Opciones de video
|
|
||||||
Stats stats; // Datos con las estadisticas de juego
|
|
||||||
Notification notifications; // Opciones relativas a las notificaciones;
|
|
||||||
Window window; // Opciones relativas a la ventana
|
|
||||||
Audio audio; // Opciones relativas al audio
|
|
||||||
ControlScheme keys; // Teclas usadas para jugar
|
|
||||||
|
|
||||||
bool setOptions(const std::string& var, const std::string& value);
|
bool setOptions(const std::string& var, const std::string& value);
|
||||||
|
|
||||||
// Crea e inicializa las opciones del programa
|
// Crea e inicializa las opciones del programa
|
||||||
|
|||||||
@@ -312,17 +312,17 @@ struct Game {
|
|||||||
height(game_height) {}
|
height(game_height) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// --- Variables ---
|
// --- Variables globales (inline C++17+) ---
|
||||||
extern std::string version; // Versión del fichero de configuración. Sirve para saber si las opciones son compatibles
|
inline std::string version{}; // Versión del fichero de configuración. Sirve para saber si las opciones son compatibles
|
||||||
extern bool console; // Indica si ha de mostrar información por la consola de texto
|
inline bool console{false}; // Indica si ha de mostrar información por la consola de texto
|
||||||
extern Cheat cheats; // Contiene trucos y ventajas para el juego
|
inline Cheat cheats{}; // Contiene trucos y ventajas para el juego
|
||||||
extern Game game; // Opciones de juego
|
inline Game game{}; // Opciones de juego
|
||||||
extern Video video; // Opciones de video
|
inline Video video{}; // Opciones de video
|
||||||
extern Stats stats; // Datos con las estadisticas de juego
|
inline Stats stats{}; // Datos con las estadisticas de juego
|
||||||
extern Notification notifications; // Opciones relativas a las notificaciones;
|
inline Notification notifications{}; // Opciones relativas a las notificaciones;
|
||||||
extern Window window; // Opciones relativas a la ventana
|
inline Window window{}; // Opciones relativas a la ventana
|
||||||
extern Audio audio; // Opciones relativas al audio
|
inline Audio audio{}; // Opciones relativas al audio
|
||||||
extern ControlScheme keys; // Teclas usadas para jugar
|
inline ControlScheme keys{GameDefaults::CONTROL_SCHEME}; // Teclas usadas para jugar
|
||||||
|
|
||||||
// --- Funciones ---
|
// --- Funciones ---
|
||||||
void init(); // Crea e inicializa las opciones del programa
|
void init(); // Crea e inicializa las opciones del programa
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "game/scenes/logo.hpp"
|
#include "game/scenes/logo.hpp"
|
||||||
|
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
#include <algorithm> // Para std::clamp
|
||||||
|
|
||||||
#include "core/input/global_inputs.hpp" // Para check
|
#include "core/input/global_inputs.hpp" // Para check
|
||||||
#include "core/rendering/screen.hpp" // Para Screen
|
#include "core/rendering/screen.hpp" // Para Screen
|
||||||
@@ -9,7 +10,7 @@
|
|||||||
#include "core/resources/resource.hpp" // Para Resource
|
#include "core/resources/resource.hpp" // Para Resource
|
||||||
#include "game/options.hpp" // Para Options, SectionState, options, Section
|
#include "game/options.hpp" // Para Options, SectionState, options, Section
|
||||||
#include "game/scene_manager.hpp" // Para SceneManager
|
#include "game/scene_manager.hpp" // Para SceneManager
|
||||||
#include "utils/defines.hpp" // Para GAME_SPEED
|
#include "utils/delta_timer.hpp" // Para DeltaTimer
|
||||||
#include "utils/global_events.hpp" // Para check
|
#include "utils/global_events.hpp" // Para check
|
||||||
#include "utils/utils.hpp" // Para PaletteColor
|
#include "utils/utils.hpp" // Para PaletteColor
|
||||||
|
|
||||||
@@ -17,7 +18,10 @@
|
|||||||
Logo::Logo()
|
Logo::Logo()
|
||||||
: jailgames_surface_(Resource::get()->getSurface("jailgames.gif")),
|
: jailgames_surface_(Resource::get()->getSurface("jailgames.gif")),
|
||||||
since_1998_surface_(Resource::get()->getSurface("since_1998.gif")),
|
since_1998_surface_(Resource::get()->getSurface("since_1998.gif")),
|
||||||
since_1998_sprite_(std::make_shared<SurfaceSprite>(since_1998_surface_, (256 - since_1998_surface_->getWidth()) / 2, 83 + jailgames_surface_->getHeight() + 5, since_1998_surface_->getWidth(), since_1998_surface_->getHeight())) {
|
since_1998_sprite_(std::make_shared<SurfaceSprite>(since_1998_surface_, (256 - since_1998_surface_->getWidth()) / 2, 83 + jailgames_surface_->getHeight() + 5, since_1998_surface_->getWidth(), since_1998_surface_->getHeight())),
|
||||||
|
delta_timer_(std::make_unique<DeltaTimer>()),
|
||||||
|
state_(LogoState::INITIAL),
|
||||||
|
state_time_(0.0f) {
|
||||||
// Configura variables
|
// Configura variables
|
||||||
since_1998_sprite_->setClip(0, 0, since_1998_surface_->getWidth(), since_1998_surface_->getHeight());
|
since_1998_sprite_->setClip(0, 0, since_1998_surface_->getWidth(), since_1998_surface_->getHeight());
|
||||||
since_1998_color_ = static_cast<Uint8>(PaletteColor::BLACK);
|
since_1998_color_ = static_cast<Uint8>(PaletteColor::BLACK);
|
||||||
@@ -26,15 +30,8 @@ Logo::Logo()
|
|||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
SceneManager::current = SceneManager::Scene::LOGO;
|
SceneManager::current = SceneManager::Scene::LOGO;
|
||||||
|
|
||||||
// Crea los sprites de cada linea
|
initSprites(); // Crea los sprites de cada linea
|
||||||
for (int i = 0; i < jailgames_surface_->getHeight(); ++i) {
|
initColors(); // Inicializa el vector de colores
|
||||||
jailgames_sprite_.push_back(std::make_shared<SurfaceSprite>(jailgames_surface_, 0, i, jailgames_surface_->getWidth(), 1));
|
|
||||||
jailgames_sprite_.back()->setClip(0, i, jailgames_surface_->getWidth(), 1);
|
|
||||||
jailgames_sprite_.at(i)->setX((i % 2 == 0) ? (256 + (i * 3)) : (-181 - (i * 3)));
|
|
||||||
jailgames_sprite_.at(i)->setY(83 + i);
|
|
||||||
}
|
|
||||||
|
|
||||||
initColors(); // Inicializa el vector de colores
|
|
||||||
|
|
||||||
// Cambia el color del borde
|
// Cambia el color del borde
|
||||||
Screen::get()->setBorderColor(static_cast<Uint8>(PaletteColor::BLACK));
|
Screen::get()->setBorderColor(static_cast<Uint8>(PaletteColor::BLACK));
|
||||||
@@ -53,119 +50,140 @@ void Logo::checkInput() {
|
|||||||
globalInputs::check();
|
globalInputs::check();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gestiona el logo de JAILGAME
|
// Gestiona el logo de JAILGAME (time-based)
|
||||||
void Logo::updateJAILGAMES() {
|
void Logo::updateJAILGAMES(float delta_time) {
|
||||||
if (counter_ > 30) {
|
// Solo actualizar durante el estado JAILGAMES_SLIDE_IN
|
||||||
for (int i = 1; i < (int)jailgames_sprite_.size(); ++i) {
|
if (state_ != LogoState::JAILGAMES_SLIDE_IN) {
|
||||||
constexpr int SPEED = 8;
|
return;
|
||||||
constexpr int DEST = 37;
|
}
|
||||||
if (jailgames_sprite_.at(i)->getX() != 37) {
|
|
||||||
if (i % 2 == 0) {
|
// Calcular el desplazamiento basado en velocidad y delta time
|
||||||
jailgames_sprite_.at(i)->incX(-SPEED);
|
const float displacement = JAILGAMES_SLIDE_SPEED * delta_time;
|
||||||
if (jailgames_sprite_.at(i)->getX() < DEST) {
|
|
||||||
jailgames_sprite_.at(i)->setX(DEST);
|
// Actualizar cada línea del sprite JAILGAMES
|
||||||
}
|
for (size_t i = 1; i < jailgames_sprite_.size(); ++i) {
|
||||||
} else {
|
const int current_x = jailgames_sprite_[i]->getX();
|
||||||
jailgames_sprite_.at(i)->incX(SPEED);
|
|
||||||
if (jailgames_sprite_.at(i)->getX() > DEST) {
|
// Las líneas pares se mueven desde la derecha, las impares desde la izquierda
|
||||||
jailgames_sprite_.at(i)->setX(DEST);
|
if (i % 2 == 0) {
|
||||||
}
|
// Mover hacia la izquierda
|
||||||
}
|
if (current_x > JAILGAMES_DEST_X) {
|
||||||
|
const int new_x = static_cast<int>(current_x - displacement);
|
||||||
|
jailgames_sprite_[i]->setX(new_x < JAILGAMES_DEST_X ? JAILGAMES_DEST_X : new_x);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Mover hacia la derecha
|
||||||
|
if (current_x < JAILGAMES_DEST_X) {
|
||||||
|
const int new_x = static_cast<int>(current_x + displacement);
|
||||||
|
jailgames_sprite_[i]->setX(new_x > JAILGAMES_DEST_X ? JAILGAMES_DEST_X : new_x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calcula el índice de color según el progreso (0.0-1.0)
|
||||||
|
int Logo::getColorIndex(float progress) const {
|
||||||
|
// Asegurar que progress esté en el rango [0.0, 1.0]
|
||||||
|
progress = std::clamp(progress, 0.0f, 1.0f);
|
||||||
|
|
||||||
|
// Mapear el progreso al índice de color (0-7)
|
||||||
|
const int max_index = static_cast<int>(color_.size()) - 1;
|
||||||
|
const int index = static_cast<int>(progress * max_index);
|
||||||
|
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
// Gestiona el color de las texturas
|
// Gestiona el color de las texturas
|
||||||
void Logo::updateTextureColors() {
|
void Logo::updateTextureColors() {
|
||||||
constexpr int INI = 70;
|
switch (state_) {
|
||||||
constexpr int INC = 4;
|
case LogoState::SINCE_1998_FADE_IN: {
|
||||||
|
// Fade-in de "Since 1998" de negro a blanco
|
||||||
|
const float progress = state_time_ / SINCE_1998_FADE_DURATION;
|
||||||
|
since_1998_color_ = color_[getColorIndex(progress)];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (counter_ == INI + INC * 0) {
|
case LogoState::DISPLAY: {
|
||||||
since_1998_color_ = color_.at(0);
|
// Asegurar que ambos logos estén en blanco durante el display
|
||||||
|
jailgames_color_ = color_.back(); // BRIGHT_WHITE
|
||||||
|
since_1998_color_ = color_.back(); // BRIGHT_WHITE
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case LogoState::FADE_OUT: {
|
||||||
|
// Fade-out de ambos logos de blanco a negro
|
||||||
|
const float progress = 1.0f - (state_time_ / FADE_OUT_DURATION);
|
||||||
|
const int color_index = getColorIndex(progress);
|
||||||
|
jailgames_color_ = color_[color_index];
|
||||||
|
since_1998_color_ = color_[color_index];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
// En otros estados, mantener los colores actuales
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
else if (counter_ == INI + INC * 1) {
|
// Transiciona a un nuevo estado
|
||||||
since_1998_color_ = color_.at(1);
|
void Logo::transitionToState(LogoState new_state) {
|
||||||
}
|
state_ = new_state;
|
||||||
|
state_time_ = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
else if (counter_ == INI + INC * 2) {
|
// Actualiza el estado actual
|
||||||
since_1998_color_ = color_.at(2);
|
void Logo::updateState(float delta_time) {
|
||||||
}
|
state_time_ += delta_time;
|
||||||
|
|
||||||
else if (counter_ == INI + INC * 3) {
|
// Gestionar transiciones entre estados basándose en el tiempo
|
||||||
since_1998_color_ = color_.at(3);
|
switch (state_) {
|
||||||
}
|
case LogoState::INITIAL:
|
||||||
|
if (state_time_ >= INITIAL_DELAY) {
|
||||||
|
transitionToState(LogoState::JAILGAMES_SLIDE_IN);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
else if (counter_ == INI + INC * 4) {
|
case LogoState::JAILGAMES_SLIDE_IN:
|
||||||
since_1998_color_ = color_.at(4);
|
if (state_time_ >= JAILGAMES_SLIDE_DURATION) {
|
||||||
}
|
transitionToState(LogoState::SINCE_1998_FADE_IN);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
else if (counter_ == INI + INC * 5) {
|
case LogoState::SINCE_1998_FADE_IN:
|
||||||
since_1998_color_ = color_.at(5);
|
if (state_time_ >= SINCE_1998_FADE_DURATION) {
|
||||||
}
|
transitionToState(LogoState::DISPLAY);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
else if (counter_ == INI + INC * 6) {
|
case LogoState::DISPLAY:
|
||||||
since_1998_color_ = color_.at(6);
|
if (state_time_ >= DISPLAY_DURATION) {
|
||||||
}
|
transitionToState(LogoState::FADE_OUT);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
else if (counter_ == INI + INC * 7) {
|
case LogoState::FADE_OUT:
|
||||||
since_1998_color_ = color_.at(7);
|
if (state_time_ >= FADE_OUT_DURATION) {
|
||||||
}
|
transitionToState(LogoState::END);
|
||||||
|
endSection();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
else if (counter_ == INIT_FADE_ + INC * 0) {
|
case LogoState::END:
|
||||||
jailgames_color_ = color_.at(6);
|
// Estado final, no hacer nada
|
||||||
since_1998_color_ = color_.at(6);
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
else if (counter_ == INIT_FADE_ + INC * 1) {
|
|
||||||
jailgames_color_ = color_.at(5);
|
|
||||||
since_1998_color_ = color_.at(5);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (counter_ == INIT_FADE_ + INC * 2) {
|
|
||||||
jailgames_color_ = color_.at(4);
|
|
||||||
since_1998_color_ = color_.at(4);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (counter_ == INIT_FADE_ + INC * 3) {
|
|
||||||
jailgames_color_ = color_.at(3);
|
|
||||||
since_1998_color_ = color_.at(3);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (counter_ == INIT_FADE_ + INC * 4) {
|
|
||||||
jailgames_color_ = color_.at(2);
|
|
||||||
since_1998_color_ = color_.at(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (counter_ == INIT_FADE_ + INC * 5) {
|
|
||||||
jailgames_color_ = color_.at(1);
|
|
||||||
since_1998_color_ = color_.at(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (counter_ == INIT_FADE_ + INC * 6) {
|
|
||||||
jailgames_color_ = color_.at(0);
|
|
||||||
since_1998_color_ = color_.at(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las variables
|
// Actualiza las variables
|
||||||
void Logo::update() {
|
void Logo::update() {
|
||||||
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
// Obtener delta time desde el último frame
|
||||||
if (SDL_GetTicks() - ticks_ > GAME_SPEED) {
|
const float delta_time = delta_timer_->tick();
|
||||||
ticks_ = SDL_GetTicks(); // Actualiza el contador de ticks
|
|
||||||
|
|
||||||
checkInput(); // Comprueba las entradas
|
checkInput(); // Comprueba las entradas
|
||||||
counter_++; // Incrementa el contador
|
updateState(delta_time); // Actualiza el estado y gestiona transiciones
|
||||||
updateJAILGAMES(); // Gestiona el logo de JAILGAME
|
updateJAILGAMES(delta_time); // Gestiona el logo de JAILGAME
|
||||||
updateTextureColors(); // Gestiona el color de las texturas
|
updateTextureColors(); // Gestiona el color de las texturas
|
||||||
Screen::get()->update(); // Actualiza el objeto Screen
|
Screen::get()->update(); // Actualiza el objeto Screen
|
||||||
|
|
||||||
// Comprueba si ha terminado el logo
|
|
||||||
if (counter_ == END_LOGO_ + POST_LOGO_) {
|
|
||||||
endSection();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dibuja en pantalla
|
// Dibuja en pantalla
|
||||||
@@ -175,8 +193,8 @@ void Logo::render() {
|
|||||||
Screen::get()->clearSurface(static_cast<Uint8>(PaletteColor::BLACK));
|
Screen::get()->clearSurface(static_cast<Uint8>(PaletteColor::BLACK));
|
||||||
|
|
||||||
// Dibuja los objetos
|
// Dibuja los objetos
|
||||||
for (const auto& s : jailgames_sprite_) {
|
for (const auto& sprite : jailgames_sprite_) {
|
||||||
s->render(1, jailgames_color_);
|
sprite->render(1, jailgames_color_);
|
||||||
}
|
}
|
||||||
since_1998_sprite_->render(1, since_1998_color_);
|
since_1998_sprite_->render(1, since_1998_color_);
|
||||||
|
|
||||||
@@ -225,4 +243,15 @@ void Logo::initColors() {
|
|||||||
for (const auto& color : COLORS) {
|
for (const auto& color : COLORS) {
|
||||||
color_.push_back(color);
|
color_.push_back(color);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Crea los sprites de cada linea
|
||||||
|
void Logo::initSprites() {
|
||||||
|
const float WIDTH = jailgames_surface_->getWidth();
|
||||||
|
for (int i = 0; i < jailgames_surface_->getHeight(); ++i) {
|
||||||
|
jailgames_sprite_.push_back(std::make_shared<SurfaceSprite>(jailgames_surface_, 0, i, jailgames_surface_->getWidth(), 1));
|
||||||
|
jailgames_sprite_.back()->setClip(0, i, jailgames_surface_->getWidth(), 1);
|
||||||
|
jailgames_sprite_.at(i)->setX((i % 2 == 0) ? (256 + (i * 3)) : (-WIDTH - (i * 3)));
|
||||||
|
jailgames_sprite_.at(i)->setY(83 + i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,17 +4,39 @@
|
|||||||
|
|
||||||
#include <memory> // Para shared_ptr
|
#include <memory> // Para shared_ptr
|
||||||
#include <vector> // Para vector
|
#include <vector> // Para vector
|
||||||
class SurfaceSprite; // lines 7-7
|
#include "utils/delta_timer.hpp" // Para DeltaTimer
|
||||||
class Surface; // lines 8-8
|
class SurfaceSprite; // Forward declaration
|
||||||
|
class Surface; // Forward declaration
|
||||||
|
|
||||||
|
// Estados de la secuencia del logo
|
||||||
|
enum class LogoState {
|
||||||
|
INITIAL, // Espera inicial
|
||||||
|
JAILGAMES_SLIDE_IN, // Las líneas de JAILGAMES se deslizan hacia el centro
|
||||||
|
SINCE_1998_FADE_IN, // Aparición gradual del texto "Since 1998"
|
||||||
|
DISPLAY, // Logo completo visible
|
||||||
|
FADE_OUT, // Desaparición gradual
|
||||||
|
END // Fin de la secuencia
|
||||||
|
};
|
||||||
|
|
||||||
class Logo {
|
class Logo {
|
||||||
private:
|
public:
|
||||||
// Constantes
|
Logo(); // Constructor
|
||||||
static constexpr int INIT_FADE_ = 300; // Tiempo del contador cuando inicia el fade a negro
|
~Logo() = default; // Destructor
|
||||||
static constexpr int END_LOGO_ = 400; // Tiempo del contador para terminar el logo
|
void run(); // Bucle principal
|
||||||
static constexpr int POST_LOGO_ = 20; // Tiempo que dura el logo con el fade al maximo
|
|
||||||
|
|
||||||
// Objetos y punteros
|
private:
|
||||||
|
// --- Constantes de tiempo (en segundos) ---
|
||||||
|
static constexpr float INITIAL_DELAY = 0.5f; // Tiempo antes de que empiece la animación
|
||||||
|
static constexpr float JAILGAMES_SLIDE_DURATION = 1.2f; // Duración del slide-in de JAILGAMES
|
||||||
|
static constexpr float SINCE_1998_FADE_DURATION = 0.5f; // Duración del fade-in de "Since 1998"
|
||||||
|
static constexpr float DISPLAY_DURATION = 3.5f; // Tiempo que el logo permanece visible
|
||||||
|
static constexpr float FADE_OUT_DURATION = 0.5f; // Duración del fade-out final
|
||||||
|
|
||||||
|
// --- Constantes de animación ---
|
||||||
|
static constexpr float JAILGAMES_SLIDE_SPEED = 800.0f; // Velocidad de slide-in (pixels/segundo)
|
||||||
|
static constexpr int JAILGAMES_DEST_X = 37; // Posición X de destino para JAILGAMES
|
||||||
|
|
||||||
|
// --- Objetos y punteros ---
|
||||||
std::shared_ptr<Surface> jailgames_surface_; // Textura con los graficos "JAILGAMES"
|
std::shared_ptr<Surface> jailgames_surface_; // Textura con los graficos "JAILGAMES"
|
||||||
std::shared_ptr<Surface> since_1998_surface_; // Textura con los graficos "Since 1998"
|
std::shared_ptr<Surface> since_1998_surface_; // Textura con los graficos "Since 1998"
|
||||||
std::vector<std::shared_ptr<SurfaceSprite>> jailgames_sprite_; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES
|
std::vector<std::shared_ptr<SurfaceSprite>> jailgames_sprite_; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES
|
||||||
@@ -22,42 +44,23 @@ class Logo {
|
|||||||
Uint8 jailgames_color_ = 0; // Color para el sprite de "JAILGAMES"
|
Uint8 jailgames_color_ = 0; // Color para el sprite de "JAILGAMES"
|
||||||
Uint8 since_1998_color_ = 0; // Color para el sprite de "Since 1998"
|
Uint8 since_1998_color_ = 0; // Color para el sprite de "Since 1998"
|
||||||
|
|
||||||
// Variables
|
// --- Variables de estado ---
|
||||||
std::vector<Uint8> color_; // Vector con los colores para el fade
|
std::vector<Uint8> color_; // Vector con los colores para el fade
|
||||||
int counter_ = 0; // Contador
|
std::unique_ptr<DeltaTimer> delta_timer_; // Timer para delta time
|
||||||
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
|
LogoState state_; // Estado actual de la secuencia
|
||||||
|
float state_time_; // Tiempo acumulado en el estado actual
|
||||||
|
|
||||||
// Actualiza las variables
|
// --- Funciones ---
|
||||||
void update();
|
void update(); // Actualiza las variables
|
||||||
|
void render(); // Dibuja en pantalla
|
||||||
// Dibuja en pantalla
|
void checkEvents(); // Comprueba el manejador de eventos
|
||||||
void render();
|
void checkInput(); // Comprueba las entradas
|
||||||
|
void updateJAILGAMES(float delta_time); // Gestiona el logo de JAILGAME (time-based)
|
||||||
// Comprueba el manejador de eventos
|
void updateTextureColors(); // Gestiona el color de las texturas
|
||||||
void checkEvents();
|
void updateState(float delta_time); // Actualiza el estado actual
|
||||||
|
void transitionToState(LogoState new_state); // Transiciona a un nuevo estado
|
||||||
// Comprueba las entradas
|
int getColorIndex(float progress) const; // Calcula el índice de color según el progreso (0.0-1.0)
|
||||||
void checkInput();
|
void endSection(); // Termina la sección
|
||||||
|
void initColors(); // Inicializa el vector de colores
|
||||||
// Gestiona el logo de JAILGAME
|
void initSprites(); // Crea los sprites de cada linea
|
||||||
void updateJAILGAMES();
|
|
||||||
|
|
||||||
// Gestiona el color de las texturas
|
|
||||||
void updateTextureColors();
|
|
||||||
|
|
||||||
// Termina la sección
|
|
||||||
void endSection();
|
|
||||||
|
|
||||||
// Inicializa el vector de colores
|
|
||||||
void initColors();
|
|
||||||
|
|
||||||
public:
|
|
||||||
// Constructor
|
|
||||||
Logo();
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
~Logo() = default;
|
|
||||||
|
|
||||||
// Bucle principal
|
|
||||||
void run();
|
|
||||||
};
|
};
|
||||||
39
source/utils/delta_timer.cpp
Normal file
39
source/utils/delta_timer.cpp
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#include "utils/delta_timer.hpp"
|
||||||
|
|
||||||
|
DeltaTimer::DeltaTimer() noexcept
|
||||||
|
: last_counter_(SDL_GetPerformanceCounter()),
|
||||||
|
perf_freq_(static_cast<double>(SDL_GetPerformanceFrequency())),
|
||||||
|
time_scale_(1.0f) {
|
||||||
|
}
|
||||||
|
|
||||||
|
float DeltaTimer::tick() noexcept {
|
||||||
|
const Uint64 now = SDL_GetPerformanceCounter();
|
||||||
|
const Uint64 diff = (now > last_counter_) ? (now - last_counter_) : 0;
|
||||||
|
last_counter_ = now;
|
||||||
|
const double seconds = static_cast<double>(diff) / perf_freq_;
|
||||||
|
return static_cast<float>(seconds * static_cast<double>(time_scale_));
|
||||||
|
}
|
||||||
|
|
||||||
|
float DeltaTimer::peek() const noexcept {
|
||||||
|
const Uint64 now = SDL_GetPerformanceCounter();
|
||||||
|
const Uint64 diff = (now > last_counter_) ? (now - last_counter_) : 0;
|
||||||
|
const double seconds = static_cast<double>(diff) / perf_freq_;
|
||||||
|
return static_cast<float>(seconds * static_cast<double>(time_scale_));
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeltaTimer::reset(Uint64 counter) noexcept {
|
||||||
|
if (counter == 0) {
|
||||||
|
last_counter_ = SDL_GetPerformanceCounter();
|
||||||
|
} else {
|
||||||
|
last_counter_ = counter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeltaTimer::setTimeScale(float scale) noexcept {
|
||||||
|
time_scale_ = std::max(scale, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
float DeltaTimer::getTimeScale() const noexcept {
|
||||||
|
return time_scale_;
|
||||||
|
}
|
||||||
|
|
||||||
27
source/utils/delta_timer.hpp
Normal file
27
source/utils/delta_timer.hpp
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL3/SDL.h>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
class DeltaTimer {
|
||||||
|
public:
|
||||||
|
DeltaTimer() noexcept;
|
||||||
|
|
||||||
|
// Calcula delta en segundos y actualiza el contador interno
|
||||||
|
float tick() noexcept;
|
||||||
|
|
||||||
|
// Devuelve el delta estimado desde el último tick sin actualizar el contador
|
||||||
|
float peek() const noexcept;
|
||||||
|
|
||||||
|
// Reinicia el contador al valor actual o al valor pasado (en performance counter ticks)
|
||||||
|
void reset(Uint64 counter = 0) noexcept;
|
||||||
|
|
||||||
|
// Escala el tiempo retornado por tick/peek, por defecto 1.0f
|
||||||
|
void setTimeScale(float scale) noexcept;
|
||||||
|
float getTimeScale() const noexcept;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Uint64 last_counter_;
|
||||||
|
double perf_freq_;
|
||||||
|
float time_scale_;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user