From bad0a103285c030d0d78b0263dfe86c556454e97 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sat, 25 Jan 2025 22:57:49 +0100 Subject: [PATCH] Ja es mouen els sprites en hiscore_table.cpp, falta decidir-se per un disseny concret --- source/hiscore_table.cpp | 80 +++++++++++++++++++++++++++++++++++++--- source/hiscore_table.h | 6 ++- source/path_sprite.cpp | 10 ++++- 3 files changed, 89 insertions(+), 7 deletions(-) diff --git a/source/hiscore_table.cpp b/source/hiscore_table.cpp index 3c5fee4..b697ef1 100644 --- a/source/hiscore_table.cpp +++ b/source/hiscore_table.cpp @@ -53,9 +53,6 @@ HiScoreTable::HiScoreTable() // Crea los sprites con los textos createSprites(); - - // Crea el contenido de la textura con la lista de puntuaciones - fillTexture(); } // Destructor @@ -80,6 +77,9 @@ void HiScoreTable::update() JA_PlayMusic(Resource::get()->getMusic("title.ogg")); } + // Actualiza las posiciones de los sprites de texto + updateSprites(); + // Actualiza el objeto screen Screen::get()->update(); @@ -105,10 +105,13 @@ void HiScoreTable::update() { fade_->activate(); } + + // Dibuja los sprites en la textura + fillTexture(); } } -// Crea el contenido de la textura con la lista de puntuaciones +// Dibuja los sprites en la textura void HiScoreTable::fillTexture() { // Pinta en el backbuffer el texto y los sprites @@ -265,6 +268,11 @@ std::string HiScoreTable::format(int number) // Crea los sprites con los textos void HiScoreTable::createSprites() { + // Obtiene el tamaƱo de la textura + int backbuffer_width; + int backbuffer_height; + SDL_QueryTexture(backbuffer_, nullptr, nullptr, &backbuffer_width, &backbuffer_height); + // Hay 27 letras - 7 de puntos quedan 20 caracteres 20 - name_lenght 0 num_dots constexpr int max_names = 10; constexpr int space_between_header = 32; @@ -291,6 +299,68 @@ void HiScoreTable::createSprites() const auto line = options.game.hi_score_table.at(i).name + dots + score; entry_names_.emplace_back(std::make_shared(text_->writeDXToTexture(TEXT_SHADOW, line, 1, orange_color, 1, shdw_txt_color))); - entry_names_.back()->setPosition(param.game.game_area.center_x - (entry_names_.back()->getWidth() / 2), (i * space_between_lines) + first_line + space_between_header); + if (false) + { + if (i % 1 == 0) + { + entry_names_.back()->addPath( + -entry_names_.back()->getWidth(), + (backbuffer_width - entry_names_.back()->getWidth()) / 2, + PathType::HORIZONTAL, + (i * space_between_lines) + first_line + space_between_header, + 80, + easeOutQuint, + 0); + entry_names_.back()->setPosition(-entry_names_.back()->getWidth(), 0); + } + else + { + entry_names_.back()->addPath( + backbuffer_width, + (backbuffer_width - entry_names_.back()->getWidth()) / 2, + PathType::HORIZONTAL, + (i * space_between_lines) + first_line + space_between_header, + 80, + easeOutQuint, + 0); + entry_names_.back()->setPosition(backbuffer_width, 0); + } + } + + if (true) + { + entry_names_.back()->addPath( + backbuffer_height, + (i * space_between_lines) + first_line + space_between_header, + PathType::VERTICAL, + (backbuffer_width - entry_names_.back()->getWidth()) / 2, + 80, + easeOutQuint, + 0); + entry_names_.back()->setPosition(0, backbuffer_height); + } + } +} + +// Actualiza las posiciones de los sprites de texto +void HiScoreTable::updateSprites() +{ + constexpr int init_counter = 220; + const int counter_between_entries = text_->getCharacterSize() * 2; + 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(entry_names_.size())) + { + entry_names_.at(index)->enable(); + } + } + } + for (auto const &entry : entry_names_) + { + entry->update(); } } \ No newline at end of file diff --git a/source/hiscore_table.h b/source/hiscore_table.h index 1f402f3..024ac4a 100644 --- a/source/hiscore_table.h +++ b/source/hiscore_table.h @@ -38,6 +38,7 @@ private: std::shared_ptr text_; // Objeto para escribir texto std::unique_ptr header_; // Sprite con la cabecera del texto std::vector> entry_names_; // Lista con los spritres de cada uno de los nombres de la tabla de records + std::vector paths_; // Vector con los recorridos precalculados // Variables Uint16 counter_; // Contador @@ -60,7 +61,7 @@ private: // Convierte un entero a un string con separadores de miles std::string format(int number); - // Crea el contenido de la textura con la lista de puntuaciones + // Dibuja los sprites en la textura void fillTexture(); // Recarga todas las texturas @@ -72,6 +73,9 @@ private: // Crea los sprites con los textos void createSprites(); + // Actualiza las posiciones de los sprites de texto + void updateSprites(); + public: // Constructor HiScoreTable(); diff --git a/source/path_sprite.cpp b/source/path_sprite.cpp index 4c28778..d63bea1 100644 --- a/source/path_sprite.cpp +++ b/source/path_sprite.cpp @@ -96,7 +96,7 @@ void PathSprite::addPath(std::vector spots, int waiting_counter) // Habilita el objeto void PathSprite::enable() { - if (paths_.size() == 0) + if (paths_.size() == 0 || enabled_) { return; } @@ -133,9 +133,13 @@ void PathSprite::moveThroughCurrentPath() if (path.on_destination) { if (path.waiting_counter == 0) + { path.finished = true; + } else + { --path.waiting_counter; + } } } @@ -144,11 +148,15 @@ void PathSprite::goToNextPathOrDie() { // Comprueba si ha terminado el recorrdo actual if (paths_.at(current_path_).finished) + { ++current_path_; + } // Comprueba si quedan mas recorridos if (current_path_ >= static_cast(paths_.size())) + { enabled_ = false; + } } // Indica si ha terminado todos los recorridos