revisat hiscore_table.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::INTRO;
|
||||
Section::name = Section::Name::HI_SCORE_TABLE;
|
||||
Section::options = Section::Options::GAME_PLAY_1P;
|
||||
#else // NORMAL GAME
|
||||
Section::name = Section::Name::LOGO;
|
||||
|
||||
@@ -54,7 +54,8 @@ HiScoreTable::~HiScoreTable() {
|
||||
|
||||
// Actualiza las variables
|
||||
void HiScoreTable::update(float delta_time) {
|
||||
Screen::get()->update(); // Actualiza el objeto screen
|
||||
elapsed_time_ += delta_time; // Incrementa el tiempo transcurrido
|
||||
Screen::get()->update(); // Actualiza el objeto screen
|
||||
|
||||
updateSprites(delta_time); // Actualiza las posiciones de los sprites de texto
|
||||
background_->update(delta_time); // Actualiza el fondo
|
||||
@@ -72,9 +73,10 @@ void HiScoreTable::render() {
|
||||
SCREEN->start(); // Prepara para empezar a dibujar en la textura de juego
|
||||
SCREEN->clean(); // Limpia la pantalla
|
||||
|
||||
background_->render(); // Pinta el fondo
|
||||
view_area_.y = std::max(0.0F, param.game.height - counter_ + 100); // Establece la ventana del backbuffer
|
||||
SDL_RenderTexture(renderer_, backbuffer_, nullptr, &view_area_); // Copia el backbuffer al renderizador
|
||||
background_->render(); // Pinta el fondo
|
||||
float counter_equivalent = elapsed_time_ * 60.0f; // Convertir tiempo a equivalente frame para UI
|
||||
view_area_.y = std::max(0.0F, param.game.height - counter_equivalent + 100); // Establece la ventana del backbuffer
|
||||
SDL_RenderTexture(renderer_, backbuffer_, nullptr, &view_area_); // Copia el backbuffer al renderizador
|
||||
fade_->render(); // Renderiza el fade
|
||||
|
||||
SCREEN->render(); // Vuelca el contenido del renderizador en pantalla
|
||||
@@ -117,7 +119,7 @@ void HiScoreTable::checkInput() {
|
||||
// Calcula el tiempo transcurrido desde el último frame
|
||||
float HiScoreTable::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;
|
||||
}
|
||||
@@ -217,15 +219,14 @@ void HiScoreTable::createSprites() {
|
||||
const int DEFAULT_POS_X = (backbuffer_width - ENTRY_WIDTH) / 2;
|
||||
const int POS_X = (i < 9) ? DEFAULT_POS_X : DEFAULT_POS_X - entry_text->getCharacterSize();
|
||||
const int POS_Y = (i * SPACE_BETWEEN_LINES) + FIRST_LINE + SPACE_BETWEEN_HEADER;
|
||||
constexpr int STEPS = 80;
|
||||
switch (ANIMATION) {
|
||||
case 0: // Ambos lados alternativamente
|
||||
{
|
||||
if (i % 2 == 0) {
|
||||
entry_names_.back()->addPath(-entry_names_.back()->getWidth(), POS_X, PathType::HORIZONTAL, POS_Y, STEPS, easeOutQuint);
|
||||
entry_names_.back()->addPath(-entry_names_.back()->getWidth(), POS_X, PathType::HORIZONTAL, POS_Y, ANIM_DURATION_S, easeOutQuint);
|
||||
entry_names_.back()->setPosition(-entry_names_.back()->getWidth(), 0);
|
||||
} else {
|
||||
entry_names_.back()->addPath(backbuffer_width, POS_X, PathType::HORIZONTAL, POS_Y, STEPS, easeOutQuint);
|
||||
entry_names_.back()->addPath(backbuffer_width, POS_X, PathType::HORIZONTAL, POS_Y, ANIM_DURATION_S, easeOutQuint);
|
||||
entry_names_.back()->setPosition(backbuffer_width, 0);
|
||||
}
|
||||
break;
|
||||
@@ -233,21 +234,21 @@ void HiScoreTable::createSprites() {
|
||||
|
||||
case 1: // Entran por la izquierda
|
||||
{
|
||||
entry_names_.back()->addPath(-entry_names_.back()->getWidth(), POS_X, PathType::HORIZONTAL, POS_Y, STEPS, easeOutQuint);
|
||||
entry_names_.back()->addPath(-entry_names_.back()->getWidth(), POS_X, PathType::HORIZONTAL, POS_Y, ANIM_DURATION_S, easeOutQuint);
|
||||
entry_names_.back()->setPosition(-entry_names_.back()->getWidth(), 0);
|
||||
break;
|
||||
}
|
||||
|
||||
case 2: // Entran por la derecha
|
||||
{
|
||||
entry_names_.back()->addPath(backbuffer_width, POS_X, PathType::HORIZONTAL, POS_Y, STEPS, easeOutQuint);
|
||||
entry_names_.back()->addPath(backbuffer_width, POS_X, PathType::HORIZONTAL, POS_Y, ANIM_DURATION_S, easeOutQuint);
|
||||
entry_names_.back()->setPosition(backbuffer_width, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
case 3: // Entran desde la parte inferior
|
||||
{
|
||||
entry_names_.back()->addPath(backbuffer_height, POS_Y, PathType::VERTICAL, POS_X, STEPS, easeOutQuint);
|
||||
entry_names_.back()->addPath(backbuffer_height, POS_Y, PathType::VERTICAL, POS_X, ANIM_DURATION_S, easeOutQuint);
|
||||
entry_names_.back()->setPosition(0, backbuffer_height);
|
||||
}
|
||||
|
||||
@@ -259,13 +260,13 @@ void HiScoreTable::createSprites() {
|
||||
|
||||
// Actualiza las posiciones de los sprites de texto
|
||||
void HiScoreTable::updateSprites(float delta_time) {
|
||||
constexpr int INIT_COUNTER = 190;
|
||||
const int COUNTER_BETWEEN_ENTRIES = 16;
|
||||
if (counter_ >= INIT_COUNTER) {
|
||||
const int COUNTER2 = counter_ - INIT_COUNTER;
|
||||
if (COUNTER2 % COUNTER_BETWEEN_ENTRIES == 0) {
|
||||
int index = COUNTER2 / COUNTER_BETWEEN_ENTRIES;
|
||||
if (index < static_cast<int>(entry_names_.size())) {
|
||||
if (elapsed_time_ >= INIT_DELAY_S) {
|
||||
const float elapsed_since_init = elapsed_time_ - INIT_DELAY_S;
|
||||
int index = static_cast<int>(elapsed_since_init / ENTRY_DELAY_S);
|
||||
if (index < static_cast<int>(entry_names_.size()) && index >= 0) {
|
||||
// Verificar si este índice debe activarse ahora
|
||||
float expected_time = index * ENTRY_DELAY_S;
|
||||
if (elapsed_since_init >= expected_time && elapsed_since_init < expected_time + delta_time) {
|
||||
entry_names_.at(index)->enable();
|
||||
}
|
||||
}
|
||||
@@ -290,7 +291,7 @@ void HiScoreTable::initFade() {
|
||||
void HiScoreTable::initBackground() {
|
||||
background_->setManualMode(true);
|
||||
background_->setPos(param.game.game_area.rect);
|
||||
background_->setCloudsSpeed(-0.1F);
|
||||
background_->setCloudsSpeed(CLOUDS_SPEED);
|
||||
|
||||
const int LUCKY = rand() % 3;
|
||||
switch (LUCKY) {
|
||||
@@ -355,7 +356,8 @@ void HiScoreTable::iniEntryColors() {
|
||||
|
||||
// Hace brillar los nombres de la tabla de records
|
||||
void HiScoreTable::glowEntryNames() {
|
||||
const Color ENTRY_COLOR = getEntryColor(counter_ / 5);
|
||||
int color_counter = static_cast<int>(elapsed_time_ * 60.0f / 5.0f); // Convertir tiempo a equivalente frame
|
||||
const Color ENTRY_COLOR = getEntryColor(color_counter);
|
||||
for (const auto &entry_index : Options::settings.glowing_entries) {
|
||||
if (entry_index != -1) {
|
||||
entry_names_.at(entry_index)->getTexture()->setColor(ENTRY_COLOR);
|
||||
@@ -365,14 +367,17 @@ void HiScoreTable::glowEntryNames() {
|
||||
|
||||
// Gestiona el contador
|
||||
void HiScoreTable::updateCounter() {
|
||||
++counter_;
|
||||
static bool background_changed = false;
|
||||
static bool fade_activated = false;
|
||||
|
||||
if (counter_ == 150) {
|
||||
if (elapsed_time_ >= BACKGROUND_CHANGE_S && !background_changed) {
|
||||
background_->setColor(background_fade_color_.DARKEN());
|
||||
background_->setAlpha(96);
|
||||
background_changed = true;
|
||||
}
|
||||
|
||||
if (counter_ == COUNTER_END) {
|
||||
if (elapsed_time_ >= COUNTER_END_S && !fade_activated) {
|
||||
fade_->activate();
|
||||
fade_activated = true;
|
||||
}
|
||||
}
|
||||
@@ -30,8 +30,13 @@ class HiScoreTable {
|
||||
void run();
|
||||
|
||||
private:
|
||||
// --- Constantes ---
|
||||
static constexpr Uint16 COUNTER_END = 800; // Valor final para el contador
|
||||
// --- Constantes (en segundos) ---
|
||||
static constexpr float COUNTER_END_S = 800.0f / 60.0f; // Tiempo final (≈13.33s)
|
||||
static constexpr float INIT_DELAY_S = 190.0f / 60.0f; // Retraso inicial (≈3.17s)
|
||||
static constexpr float ENTRY_DELAY_S = 16.0f / 60.0f; // Retraso entre entradas (≈0.27s)
|
||||
static constexpr float BACKGROUND_CHANGE_S = 150.0f / 60.0f; // Tiempo cambio fondo (≈2.5s)
|
||||
static constexpr float ANIM_DURATION_S = 80.0f / 60.0f; // Duración animación (≈1.33s)
|
||||
static constexpr float CLOUDS_SPEED = -6.0f; // Velocidad nubes (pixels/s)
|
||||
|
||||
// --- Objetos y punteros ---
|
||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||
@@ -44,7 +49,7 @@ class HiScoreTable {
|
||||
std::vector<Path> paths_; // Vector con los recorridos precalculados
|
||||
|
||||
// --- Variables ---
|
||||
Uint16 counter_ = 0; // Contador
|
||||
float elapsed_time_ = 0.0f; // Tiempo transcurrido (segundos)
|
||||
Uint64 last_time_ = 0; // Último timestamp para calcular delta-time
|
||||
SDL_FRect view_area_; // Parte de la textura que se muestra en pantalla
|
||||
Fade::Mode fade_mode_; // Modo de fade a utilizar
|
||||
|
||||
Reference in New Issue
Block a user