revisat logo.cpp
This commit is contained in:
@@ -42,7 +42,7 @@ Director::Director(int argc, std::span<char *> argv) {
|
||||
Section::name = Section::Name::GAME;
|
||||
Section::options = Section::Options::GAME_PLAY_1P;
|
||||
#elif _DEBUG
|
||||
Section::name = Section::Name::TITLE;
|
||||
Section::name = Section::Name::LOGO;
|
||||
Section::options = Section::Options::GAME_PLAY_1P;
|
||||
#else // NORMAL GAME
|
||||
Section::name = Section::Name::LOGO;
|
||||
|
||||
@@ -790,7 +790,7 @@ void Game::throwCoffee(int x, int y) {
|
||||
smart_sprites_.back()->setDestX(x + (smart_sprites_.back()->getVelX() * 50));
|
||||
smart_sprites_.back()->setDestY(param.game.height + 1);
|
||||
smart_sprites_.back()->setEnabled(true);
|
||||
smart_sprites_.back()->setFinishedCounter(1);
|
||||
smart_sprites_.back()->setFinishedDelay(0.0F);
|
||||
smart_sprites_.back()->setSpriteClip(0, param.game.item_size, param.game.item_size, param.game.item_size);
|
||||
smart_sprites_.back()->setRotatingCenter({param.game.item_size / 2, param.game.item_size / 2});
|
||||
smart_sprites_.back()->setRotate(true);
|
||||
|
||||
@@ -82,7 +82,7 @@ void Logo::checkInput() {
|
||||
void Logo::handleSound() {
|
||||
static bool sound_triggered = false;
|
||||
|
||||
if (!sound_triggered && elapsed_time_ms_ >= SOUND_TRIGGER_TIME_MS) {
|
||||
if (!sound_triggered && elapsed_time_s_ >= SOUND_TRIGGER_TIME_S) {
|
||||
Audio::get()->playSound("logo.wav");
|
||||
sound_triggered = true;
|
||||
}
|
||||
@@ -90,8 +90,8 @@ void Logo::handleSound() {
|
||||
|
||||
// Gestiona el logo de JAILGAMES
|
||||
void Logo::updateJAILGAMES(float delta_time) {
|
||||
if (elapsed_time_ms_ > SOUND_TRIGGER_TIME_MS) {
|
||||
const float PIXELS_TO_MOVE = LOGO_SPEED_PX_PER_MS * delta_time;
|
||||
if (elapsed_time_s_ > SOUND_TRIGGER_TIME_S) {
|
||||
const float PIXELS_TO_MOVE = LOGO_SPEED_PX_PER_S * delta_time;
|
||||
|
||||
for (size_t i = 0; i < jail_sprite_.size(); ++i) {
|
||||
if (jail_sprite_[i]->getX() != dest_.x) {
|
||||
@@ -111,7 +111,7 @@ void Logo::updateJAILGAMES(float delta_time) {
|
||||
}
|
||||
|
||||
// Comprueba si ha terminado el logo
|
||||
if (elapsed_time_ms_ >= END_LOGO_TIME_MS + POST_LOGO_DURATION_MS) {
|
||||
if (elapsed_time_s_ >= END_LOGO_TIME_S + POST_LOGO_DURATION_S) {
|
||||
Section::name = Section::Name::INTRO;
|
||||
}
|
||||
}
|
||||
@@ -120,16 +120,16 @@ void Logo::updateJAILGAMES(float delta_time) {
|
||||
void Logo::updateTextureColors(float delta_time) {
|
||||
// Manejo de 'sinceTexture'
|
||||
for (int i = 0; i <= MAX_SINCE_COLOR_INDEX; ++i) {
|
||||
const float target_time = SHOW_SINCE_SPRITE_TIME_MS + COLOR_CHANGE_INTERVAL_MS * i;
|
||||
if (elapsed_time_ms_ >= target_time && elapsed_time_ms_ - delta_time < target_time) {
|
||||
const float target_time = SHOW_SINCE_SPRITE_TIME_S + COLOR_CHANGE_INTERVAL_S * i;
|
||||
if (elapsed_time_s_ >= target_time && elapsed_time_s_ - delta_time < target_time) {
|
||||
since_texture_->setColor(color_[i].r, color_[i].g, color_[i].b);
|
||||
}
|
||||
}
|
||||
|
||||
// Manejo de 'jailTexture' y 'sinceTexture' en el fade
|
||||
for (int i = 0; i <= MAX_FADE_COLOR_INDEX; ++i) {
|
||||
const float target_time = INIT_FADE_TIME_MS + COLOR_CHANGE_INTERVAL_MS * i;
|
||||
if (elapsed_time_ms_ >= target_time && elapsed_time_ms_ - delta_time < target_time) {
|
||||
const float target_time = INIT_FADE_TIME_S + COLOR_CHANGE_INTERVAL_S * i;
|
||||
if (elapsed_time_s_ >= target_time && elapsed_time_s_ - delta_time < target_time) {
|
||||
jail_texture_->setColor(color_[MAX_FADE_COLOR_INDEX - i].r, color_[MAX_FADE_COLOR_INDEX - i].g, color_[MAX_FADE_COLOR_INDEX - i].b);
|
||||
since_texture_->setColor(color_[MAX_FADE_COLOR_INDEX - i].r, color_[MAX_FADE_COLOR_INDEX - i].g, color_[MAX_FADE_COLOR_INDEX - i].b);
|
||||
}
|
||||
@@ -138,7 +138,7 @@ void Logo::updateTextureColors(float delta_time) {
|
||||
|
||||
// Actualiza las variables
|
||||
void Logo::update(float delta_time) {
|
||||
elapsed_time_ms_ += delta_time; // Acumula el tiempo transcurrido
|
||||
elapsed_time_s_ += delta_time; // Acumula el tiempo transcurrido
|
||||
|
||||
Screen::get()->update(); // Actualiza el objeto screen
|
||||
Audio::update(); // Actualiza el objeto audio
|
||||
@@ -163,7 +163,7 @@ void Logo::render() {
|
||||
// Calcula el tiempo transcurrido desde el último frame
|
||||
float Logo::calculateDeltaTime() {
|
||||
const Uint64 current_time = SDL_GetTicks();
|
||||
const float delta_time = static_cast<float>(current_time - last_time_);
|
||||
const float delta_time = static_cast<float>(current_time - last_time_) / 1000.0f; // Convertir ms a segundos
|
||||
last_time_ = current_time;
|
||||
return delta_time;
|
||||
}
|
||||
@@ -189,7 +189,7 @@ void Logo::renderJAILGAMES() {
|
||||
sprite->render();
|
||||
}
|
||||
|
||||
if (elapsed_time_ms_ >= SHOW_SINCE_SPRITE_TIME_MS) {
|
||||
if (elapsed_time_s_ >= SHOW_SINCE_SPRITE_TIME_S) {
|
||||
since_sprite_->render();
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ class Texture;
|
||||
// • Transición temporal: duración controlada con paso automático al siguiente estado
|
||||
// • Sistema delta-time: animaciones suaves independientes del framerate
|
||||
//
|
||||
// La clase utiliza un sistema de tiempo basado en milisegundos para garantizar
|
||||
// La clase utiliza un sistema de tiempo basado en segundos para garantizar
|
||||
// consistencia visual en diferentes velocidades de procesamiento.
|
||||
|
||||
class Logo {
|
||||
@@ -35,14 +35,14 @@ class Logo {
|
||||
void run();
|
||||
|
||||
private:
|
||||
// --- Constantes de tiempo (en milisegundos) ---
|
||||
static constexpr float SOUND_TRIGGER_TIME_MS = 500.0f; // Tiempo para activar el sonido del logo
|
||||
static constexpr float SHOW_SINCE_SPRITE_TIME_MS = 1167.0f; // Tiempo para mostrar el sprite "SINCE 1998"
|
||||
static constexpr float INIT_FADE_TIME_MS = 5000.0f; // Tiempo de inicio del fade a negro
|
||||
static constexpr float END_LOGO_TIME_MS = 6668.0f; // Tiempo de finalización del logo
|
||||
static constexpr float POST_LOGO_DURATION_MS = 333.0f; // Duración adicional después del fade
|
||||
static constexpr float LOGO_SPEED_PX_PER_MS = 8.0f / 16.67f; // Velocidad de desplazamiento (píxeles por ms)
|
||||
static constexpr float COLOR_CHANGE_INTERVAL_MS = 66.7f; // Intervalo entre cambios de color (~4 frames a 60fps)
|
||||
// --- Constantes de tiempo (en segundos) ---
|
||||
static constexpr float SOUND_TRIGGER_TIME_S = 0.5f; // Tiempo para activar el sonido del logo
|
||||
static constexpr float SHOW_SINCE_SPRITE_TIME_S = 1.167f; // Tiempo para mostrar el sprite "SINCE 1998"
|
||||
static constexpr float INIT_FADE_TIME_S = 5.0f; // Tiempo de inicio del fade a negro
|
||||
static constexpr float END_LOGO_TIME_S = 6.668f; // Tiempo de finalización del logo
|
||||
static constexpr float POST_LOGO_DURATION_S = 0.333f; // Duración adicional después del fade
|
||||
static constexpr float LOGO_SPEED_PX_PER_S = 480.0f; // Velocidad de desplazamiento (píxeles por segundo) - 8.0f/16.67f*1000
|
||||
static constexpr float COLOR_CHANGE_INTERVAL_S = 0.0667f; // Intervalo entre cambios de color (~4 frames a 60fps)
|
||||
|
||||
// --- Constantes de layout ---
|
||||
static constexpr int SINCE_SPRITE_Y_OFFSET = 83; // Posición Y base del sprite "Since 1998"
|
||||
@@ -73,7 +73,7 @@ class Logo {
|
||||
|
||||
// --- Variables ---
|
||||
std::vector<Color> color_; // Vector con los colores para el fade
|
||||
float elapsed_time_ms_ = 0.0f; // Tiempo transcurrido en milisegundos
|
||||
float elapsed_time_s_ = 0.0f; // Tiempo transcurrido en segundos
|
||||
Uint64 last_time_ = 0; // Último timestamp para calcular delta-time
|
||||
SDL_FPoint dest_; // Posición donde dibujar el logo
|
||||
|
||||
|
||||
Reference in New Issue
Block a user