From 6f594b9a1f03dfe4da631b94cb4d090188092053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Wed, 5 Feb 2025 15:15:48 +0100 Subject: [PATCH] La tabla de puntuacions ja mostra aquelles aconseguides amb 1CC --- data/font/smb2.gif | Bin 1153 -> 1161 bytes source/game.cpp | 6 +++--- source/game.h | 2 +- source/hiscore_table.cpp | 16 ++++++++++------ source/manage_hiscore_table.cpp | 2 +- source/manage_hiscore_table.h | 10 +++++----- source/player.cpp | 1 + source/player.h | 2 +- 8 files changed, 22 insertions(+), 17 deletions(-) diff --git a/data/font/smb2.gif b/data/font/smb2.gif index 96ae38a4e65d68380a4e4d1a26c437a79bfcbe95..c1e17d6e889eeeaba5a6c9107c50976ea73a57d7 100644 GIT binary patch delta 89 zcmV-f0H*(e35f}?I0R8n4)fRPS&t^%@#mluQR_5@9TfWMlN7614^E@*x<6HC%VV>z vyB;>#CQ)7c?rOh19U`sqzI)*R-WQ7Q!lSOSE`B#VV%R>8zu`B#_OvE_)n! nL^(options.game.hi_score_table); @@ -1649,7 +1649,7 @@ void Game::handleNameInput(const std::shared_ptr &player) if (player->getRecordNamePos() == NAME_LENGHT - 1) { player->setInput(InputType::START); - addScoreToScoreBoard(player->getRecordName(), player->getScore()); + addScoreToScoreBoard(player->getRecordName(), player->getScore(), player->get1CC()); const auto state = player->getPlayingState(); player->setPlayingState(state == PlayerState::ENTERING_NAME ? PlayerState::CONTINUE : PlayerState::LEAVING_SCREEN); } @@ -1673,7 +1673,7 @@ void Game::handleNameInput(const std::shared_ptr &player) else if (input_->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index)) { player->setInput(InputType::START); - addScoreToScoreBoard(player->getRecordName(), player->getScore()); + addScoreToScoreBoard(player->getRecordName(), player->getScore(), player->get1CC()); const auto state = player->getPlayingState(); player->setPlayingState(state == PlayerState::ENTERING_NAME ? PlayerState::CONTINUE : PlayerState::LEAVING_SCREEN); } diff --git a/source/game.h b/source/game.h index ae32daf..cb7e1c2 100644 --- a/source/game.h +++ b/source/game.h @@ -311,7 +311,7 @@ private: void pause(bool value); // Añade una puntuación a la tabla de records - void addScoreToScoreBoard(const std::string &name, int score); + void addScoreToScoreBoard(const std::string &name, int score, bool one_credit_continue); // Saca del estado de GAME OVER al jugador si el otro está activo void checkAndUpdatePlayerStatus(int active_player_index, int inactive_player_index); diff --git a/source/hiscore_table.cpp b/source/hiscore_table.cpp index c3e70d6..14a9afc 100644 --- a/source/hiscore_table.cpp +++ b/source/hiscore_table.cpp @@ -266,9 +266,9 @@ void HiScoreTable::createSprites() 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 <-- Esto no se qué coño es + constexpr int entry_lenght = 22; constexpr int max_names = 10; - constexpr int space_between_header = 32; + const int space_between_header = entry_text->getCharacterSize() * 4; const int space_between_lines = entry_text->getCharacterSize() * 2; const int size = space_between_header + space_between_lines * (max_names - 1) + entry_text->getCharacterSize(); const int first_line = (param.game.height - size) / 2; @@ -279,21 +279,25 @@ void HiScoreTable::createSprites() // Crea los sprites para las entradas en la tabla de puntuaciones const int animation = rand() % 4; + const std::string sample_line(entry_lenght + 3, ' '); + auto sample_entry = std::make_unique(entry_text->writeDXToTexture(TEXT_SHADOW, sample_line, 1, orange_color, 1, shdw_txt_color)); + const auto entry_width = sample_entry->getWidth(); for (int i = 0; i < max_names; ++i) { - // const auto table_position = (i + 1 >= 10) ? format(i + 1) + ". " : " " + format(i + 1) + ". "; const auto table_position = format(i + 1) + ". "; const auto score = format(options.game.hi_score_table.at(i).score); - const auto num_dots = 22 - options.game.hi_score_table.at(i).name.size() - score.size(); + const auto num_dots = entry_lenght - options.game.hi_score_table.at(i).name.size() - score.size(); + const auto one_cc = options.game.hi_score_table.at(i).one_credit_complete ? " }" : ""; std::string dots; for (int j = 0; j < (int)num_dots; ++j) { dots = dots + "."; } - const auto line = table_position + options.game.hi_score_table.at(i).name + dots + score; + const auto line = table_position + options.game.hi_score_table.at(i).name + dots + score + one_cc; entry_names_.emplace_back(std::make_shared(entry_text->writeDXToTexture(TEXT_SHADOW, line, 1, orange_color, 1, shdw_txt_color))); - const int pos_x = (i < 9) ? (backbuffer_width - entry_names_.front()->getWidth()) / 2 : (backbuffer_width - entry_names_.front()->getWidth()) / 2 - entry_text->getCharacterSize(); + 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) diff --git a/source/manage_hiscore_table.cpp b/source/manage_hiscore_table.cpp index 417207f..8aaa07f 100644 --- a/source/manage_hiscore_table.cpp +++ b/source/manage_hiscore_table.cpp @@ -13,7 +13,7 @@ void ManageHiScoreTable::clear() // Añade 10 entradas predefinidas table_.push_back(HiScoreEntry("BRY", 1000000)); - table_.push_back(HiScoreEntry("USUFON", 500000)); + table_.push_back(HiScoreEntry("USUFON", 500000, true)); table_.push_back(HiScoreEntry("GLUCAS", 100000)); table_.push_back(HiScoreEntry("PDLGAT", 50000)); table_.push_back(HiScoreEntry("PARRAB", 10000)); diff --git a/source/manage_hiscore_table.h b/source/manage_hiscore_table.h index e839b1b..17ef2ff 100644 --- a/source/manage_hiscore_table.h +++ b/source/manage_hiscore_table.h @@ -14,13 +14,13 @@ // Estructura para las entradas de la tabla de recirds struct HiScoreEntry { - std::string name; // Nombre - int score = 0; // Puntuación - bool one_credit_complete = false; // Indica si se ha conseguido 1CC + std::string name; // Nombre + int score; // Puntuación + bool one_credit_complete; // Indica si se ha conseguido 1CC // Constructor - explicit HiScoreEntry(const std::string &n = "", int s = 0) - : name(n), score(s) {} + explicit HiScoreEntry(const std::string &n = "", int s = 0, bool occ = false) + : name(n.substr(0, 5)), score(s), one_credit_complete(occ) {} }; // Clase ManageHiScoreTable diff --git a/source/player.cpp b/source/player.cpp index 7f8e7ac..47f713e 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -59,6 +59,7 @@ void Player::init() score_multiplier_ = 1.0f; cool_down_ = 10; enter_name_->init(); + ++credits_used_; // Establece la posición del sprite player_sprite_->clear(); diff --git a/source/player.h b/source/player.h index 3da1179..10ae8e8 100644 --- a/source/player.h +++ b/source/player.h @@ -232,7 +232,7 @@ public: int getWidth() const { return WIDTH_; } PlayerState getPlayingState() const { return playing_state_; } std::string getName() const { return name_; } - bool get1CC() const { return game_completed_ && credits_used_ == 0; } + bool get1CC() const { return game_completed_ && credits_used_ == 1; } // Setters void setController(int index) { controller_index_ = index; }