Ja es mouen els sprites en hiscore_table.cpp, falta decidir-se per un disseny concret

This commit is contained in:
2025-01-25 22:57:49 +01:00
parent 52a0c2b91f
commit bad0a10328
3 changed files with 89 additions and 7 deletions

View File

@@ -53,9 +53,6 @@ HiScoreTable::HiScoreTable()
// Crea los sprites con los textos // Crea los sprites con los textos
createSprites(); createSprites();
// Crea el contenido de la textura con la lista de puntuaciones
fillTexture();
} }
// Destructor // Destructor
@@ -80,6 +77,9 @@ void HiScoreTable::update()
JA_PlayMusic(Resource::get()->getMusic("title.ogg")); JA_PlayMusic(Resource::get()->getMusic("title.ogg"));
} }
// Actualiza las posiciones de los sprites de texto
updateSprites();
// Actualiza el objeto screen // Actualiza el objeto screen
Screen::get()->update(); Screen::get()->update();
@@ -105,10 +105,13 @@ void HiScoreTable::update()
{ {
fade_->activate(); 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() void HiScoreTable::fillTexture()
{ {
// Pinta en el backbuffer el texto y los sprites // 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 // Crea los sprites con los textos
void HiScoreTable::createSprites() 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 // Hay 27 letras - 7 de puntos quedan 20 caracteres 20 - name_lenght 0 num_dots
constexpr int max_names = 10; constexpr int max_names = 10;
constexpr int space_between_header = 32; 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; const auto line = options.game.hi_score_table.at(i).name + dots + score;
entry_names_.emplace_back(std::make_shared<PathSprite>(text_->writeDXToTexture(TEXT_SHADOW, line, 1, orange_color, 1, shdw_txt_color))); entry_names_.emplace_back(std::make_shared<PathSprite>(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<int>(entry_names_.size()))
{
entry_names_.at(index)->enable();
}
}
}
for (auto const &entry : entry_names_)
{
entry->update();
} }
} }

View File

@@ -38,6 +38,7 @@ private:
std::shared_ptr<Text> text_; // Objeto para escribir texto std::shared_ptr<Text> text_; // Objeto para escribir texto
std::unique_ptr<Sprite> header_; // Sprite con la cabecera del texto std::unique_ptr<Sprite> header_; // Sprite con la cabecera del texto
std::vector<std::shared_ptr<PathSprite>> entry_names_; // Lista con los spritres de cada uno de los nombres de la tabla de records std::vector<std::shared_ptr<PathSprite>> entry_names_; // Lista con los spritres de cada uno de los nombres de la tabla de records
std::vector<Path> paths_; // Vector con los recorridos precalculados
// Variables // Variables
Uint16 counter_; // Contador Uint16 counter_; // Contador
@@ -60,7 +61,7 @@ private:
// Convierte un entero a un string con separadores de miles // Convierte un entero a un string con separadores de miles
std::string format(int number); std::string format(int number);
// Crea el contenido de la textura con la lista de puntuaciones // Dibuja los sprites en la textura
void fillTexture(); void fillTexture();
// Recarga todas las texturas // Recarga todas las texturas
@@ -72,6 +73,9 @@ private:
// Crea los sprites con los textos // Crea los sprites con los textos
void createSprites(); void createSprites();
// Actualiza las posiciones de los sprites de texto
void updateSprites();
public: public:
// Constructor // Constructor
HiScoreTable(); HiScoreTable();

View File

@@ -96,7 +96,7 @@ void PathSprite::addPath(std::vector<SDL_Point> spots, int waiting_counter)
// Habilita el objeto // Habilita el objeto
void PathSprite::enable() void PathSprite::enable()
{ {
if (paths_.size() == 0) if (paths_.size() == 0 || enabled_)
{ {
return; return;
} }
@@ -133,9 +133,13 @@ void PathSprite::moveThroughCurrentPath()
if (path.on_destination) if (path.on_destination)
{ {
if (path.waiting_counter == 0) if (path.waiting_counter == 0)
{
path.finished = true; path.finished = true;
}
else else
{
--path.waiting_counter; --path.waiting_counter;
}
} }
} }
@@ -144,11 +148,15 @@ void PathSprite::goToNextPathOrDie()
{ {
// Comprueba si ha terminado el recorrdo actual // Comprueba si ha terminado el recorrdo actual
if (paths_.at(current_path_).finished) if (paths_.at(current_path_).finished)
{
++current_path_; ++current_path_;
}
// Comprueba si quedan mas recorridos // Comprueba si quedan mas recorridos
if (current_path_ >= static_cast<int>(paths_.size())) if (current_path_ >= static_cast<int>(paths_.size()))
{
enabled_ = false; enabled_ = false;
}
} }
// Indica si ha terminado todos los recorridos // Indica si ha terminado todos los recorridos