From 057d3dcfee0e380ae338d7677150556889328039 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Tue, 26 Aug 2025 08:21:33 +0200 Subject: [PATCH] bug fix: en la tabla de puntuacions, no apareix la estreleta al completar el joc amb 1CC bug fix: posant nom al completar el joc, si "passes" el mostrar el nom, mata al jugador en lloc de fer que se'n vaja Resol #92 i #98 --- data/font/smb2.png | Bin 872 -> 882 bytes source/director.cpp | 2 +- source/manage_hiscore_table.h | 8 +-- source/player.cpp | 8 +++ source/player.h | 3 +- source/sections/game.cpp | 132 +++++++++++++++++++--------------- 6 files changed, 89 insertions(+), 64 deletions(-) diff --git a/data/font/smb2.png b/data/font/smb2.png index a0d16e71c4fdb36b2b1000af802b792be3cb72fb..e18d5df1ffb9d946ba9a02d55d19086fb29028a5 100644 GIT binary patch delta 790 zcmV+x1L^$e2J!}wX@B%dL_t(og~gbGlB+NXMbT>f|3BVI0^AFU_RSl$Y%2*6v+MNa z(iL$#j-xwi1M?yl?iUTx0J;COQc8Ey2JkJ>-z`?GUcvw_2EN+9@7>i`omI1_7t~NI z5KDN04)!7O#kMU^TV$)&1Lk6-&rn`RTPnG3DyB8~(!sSl9ZJ zwOR8N%azd$fmu0hS@KjPi)ZU)K_aY7vD5pW7v5}_`*c1XWOK@ANE{(<^CQ)tZxc-U z6b05WHnPP4H=aeJ=k-{ZD@U%4PbF|CF!vL_;Wg#!`98=>z+6Y0@`ur8amB9ZKJ@Da@%r)1?^)WtrwUub=W4>}+oZ%IWJD0I;C0?CdE9`0iv@g}* zmxTvbGS>MWhPcq8VfafkxCRa<7-w9YW^=@0XP&Lj9C8jYHdl3M_d7W z0k^b{!=O&Z)~>QA&!U{vH|HfPIq;>h09=vHeiU4iSAQxBanEla=kq|k9yjRb^tEdz z*11(JmZZ&z*%YVqfa3Xli24ZVOn+AfI57+_xt`AhT89M$vO2?8H5t4z*2ejg4gy;@ zITtAYOQ1s!P5jMu*KuWzb^RejPagB}2E`czr{BEmGjR*g+!kRG4?0c#^FDBU=51x> zT5kd2W`C|p*oFFF^2XiZXMOfqCn%IjUv8&HMa=k1+*&&guI+;{;Z&f}v`{AcuHK|G zbIY6#8a&~Y=lst4?&pT}#F;-5;hG)!6vBJbf1}rq+}nBZJEO0=kk43wf*bWYsb=_o z>v7HAs?V{FzIZZs>oW`F{M)No@?L$GAgLD{-+!&o%~rI=r*^kKcQZaOHojY*uQqy? z^xW^hrO!jZ`MhW!@sATKM`(K9x~A7di$}RpWHX{Nz6X|7Y7~XzV~?LbDe&f7xwrAc|<1J UY!4)MSpWb407*qoM6N<$f-Rt%HUIzs delta 780 zcmV+n1M~dy2IvNmX@BZTL_t(og~gbSvf?lZg{k)E{oi;^0-OV+y0cp=S4#pUo$L7J zP(|F1;}}l*!2D~Z;c?L*4Uqdc+xLAq=>zzl81Ek2tzN#i8C%(1RN!anexj~ndH7&!gpU7tlJd7-*pSj2-)Q~$gbZqK}} z6q)3Ognyg4CSh-8+>tl#il6n_wN6kdwcbyShM4h}xV3f~T-z68!l^af&#+LuuC&`G zotazav}o{zQ=aoX>${&D))Qy`NQ7Iq@+ok${u{k^!3gkL{PO2&V zeCu(|UaHTrjehgVT&>SS0y%$r6-!>L&&?pIZ+~ulwLW)ypfx_VtMz%9@%iS)SL^e; z8-17b-0$9{&!ykJO`mhWdz(Jze)l$guCjTPKIeY-E`2Wj?p^x)J1hMzg!%hMN(rsK z!2)0W`1)nT&r{CdEe5(=Z~x|3<^Q(GXJq!P7IgI2eeWIj{R0)YCNcBBr>_72002ov KP6b4+LSTYFDVMSU diff --git a/source/director.cpp b/source/director.cpp index 31055e2..bbc9c43 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -42,7 +42,7 @@ Director::Director(int argc, std::span argv) { Section::name = Section::Name::GAME; Section::options = Section::Options::GAME_PLAY_1P; #elif _DEBUG - Section::name = Section::Name::GAME; + Section::name = Section::Name::HI_SCORE_TABLE; Section::options = Section::Options::GAME_PLAY_1P; #else // NORMAL GAME Section::name = Section::Name::LOGO; diff --git a/source/manage_hiscore_table.h b/source/manage_hiscore_table.h index d030c98..76a2b68 100644 --- a/source/manage_hiscore_table.h +++ b/source/manage_hiscore_table.h @@ -10,10 +10,10 @@ struct HiScoreEntry { bool one_credit_complete; // Indica si se ha conseguido 1CC // Constructor - explicit HiScoreEntry(const std::string &n = "", int s = 0, bool occ = false) - : name(n.substr(0, 6)), - score(s), - one_credit_complete(occ) {} + explicit HiScoreEntry(const std::string &name = "", int score = 0, bool one_credit_complete = false) + : name(name.substr(0, 6)), + score(score), + one_credit_complete(one_credit_complete) {} }; // --- Tipos --- diff --git a/source/player.cpp b/source/player.cpp index a18f470..62a7d2e 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -595,6 +595,14 @@ void Player::update() { updateShowingName(); } +void Player::passShowingName() { + if (game_completed_) { + setPlayingState(State::LEAVING_SCREEN); + } else { + setPlayingState(State::CONTINUE); + } +} + // Incrementa la puntuación del jugador void Player::addScore(int score, int lowest_hi_score_entry) { if (isPlaying()) { diff --git a/source/player.h b/source/player.h index 2a979c7..6e0e1af 100644 --- a/source/player.h +++ b/source/player.h @@ -170,7 +170,7 @@ class Player { [[nodiscard]] static auto getWidth() -> int { return WIDTH; } [[nodiscard]] auto getPlayingState() const -> State { return playing_state_; } [[nodiscard]] auto getName() const -> const std::string & { return name_; } - [[nodiscard]] auto get1CC() const -> bool { return game_completed_ && credits_used_ == 1; } + [[nodiscard]] auto get1CC() const -> bool { return game_completed_ && credits_used_ <= 1; } [[nodiscard]] auto getEnterNamePositionOverflow() const -> bool { return enter_name_ ? enter_name_->getPositionOverflow() : false; } // Setters inline @@ -186,6 +186,7 @@ class Player { void setWalkingState(State state) { walking_state_ = state; } void addCredit(); + void passShowingName(); void setGamepad(std::shared_ptr gamepad) { gamepad_ = std::move(gamepad); } [[nodiscard]] auto getGamepad() const -> std::shared_ptr { return gamepad_; } void setUsesKeyboard(bool value) { uses_keyboard_ = value; } diff --git a/source/sections/game.cpp b/source/sections/game.cpp index b617f2b..d307d8f 100644 --- a/source/sections/game.cpp +++ b/source/sections/game.cpp @@ -1373,17 +1373,27 @@ void Game::handleNormalPlayerInput(const std::shared_ptr &player) { // Procesa las entradas de disparo del jugador, permitiendo disparos automáticos si está habilitado. void Game::handleFireInputs(const std::shared_ptr &player, bool autofire) { + if (!player) { + return; + } + if (input_->checkAction(Input::Action::FIRE_CENTER, autofire, player->getUsesKeyboard(), player->getGamepad())) { handleFireInput(player, BulletType::UP); #ifdef RECORDING demo_.keys.fire = 1; #endif - } else if (input_->checkAction(Input::Action::FIRE_LEFT, autofire, player->getUsesKeyboard(), player->getGamepad())) { + return; + } + + if (input_->checkAction(Input::Action::FIRE_LEFT, autofire, player->getUsesKeyboard(), player->getGamepad())) { handleFireInput(player, BulletType::LEFT); #ifdef RECORDING demo_.keys.fire_left = 1; #endif - } else if (input_->checkAction(Input::Action::FIRE_RIGHT, autofire, player->getUsesKeyboard(), player->getGamepad())) { + return; + } + + if (input_->checkAction(Input::Action::FIRE_RIGHT, autofire, player->getUsesKeyboard(), player->getGamepad())) { handleFireInput(player, BulletType::RIGHT); #ifdef RECORDING demo_.keys.fire_right = 1; @@ -1397,6 +1407,7 @@ void Game::handlePlayerContinueInput(const std::shared_ptr &player) { player->setPlayingState(Player::State::RECOVER); player->addCredit(); sendPlayerToTheFront(player); + return; } // Disminuye el contador de continuación si se presiona cualquier botón de disparo. @@ -1422,39 +1433,53 @@ void Game::handlePlayerWaitingInput(const std::shared_ptr &player) { void Game::handleNameInput(const std::shared_ptr &player) { if (input_->checkAction(Input::Action::FIRE_LEFT, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) { if (player->isShowingName()) { - player->setPlayingState(Player::State::CONTINUE); - } else if (player->getEnterNamePositionOverflow()) { + player->passShowingName(); + return; + } + if (player->getEnterNamePositionOverflow()) { player->setInput(Input::Action::START); player->setPlayingState(Player::State::SHOWING_NAME); playSound("service_menu_select.wav"); updateHiScoreName(); - } else { - player->setInput(Input::Action::RIGHT); - playSound("service_menu_select.wav"); + return; } - } else if (input_->checkAction(Input::Action::FIRE_CENTER, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad()) || + player->setInput(Input::Action::RIGHT); + playSound("service_menu_select.wav"); + return; + } + + if (input_->checkAction(Input::Action::FIRE_CENTER, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad()) || input_->checkAction(Input::Action::FIRE_RIGHT, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) { if (player->isShowingName()) { - player->setPlayingState(Player::State::CONTINUE); - } else { - player->setInput(Input::Action::LEFT); - playSound("service_menu_back.wav"); + player->passShowingName(); + return; } - } else if (input_->checkAction(Input::Action::UP, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) { + player->setInput(Input::Action::LEFT); + playSound("service_menu_back.wav"); + return; + } + + if (input_->checkAction(Input::Action::UP, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) { player->setInput(Input::Action::UP); playSound("service_menu_move.wav"); - } else if (input_->checkAction(Input::Action::DOWN, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) { + return; + } + + if (input_->checkAction(Input::Action::DOWN, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) { player->setInput(Input::Action::DOWN); playSound("service_menu_move.wav"); - } else if (input_->checkAction(Input::Action::START, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) { + return; + } + + if (input_->checkAction(Input::Action::START, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) { if (player->isShowingName()) { - player->setPlayingState(Player::State::CONTINUE); - } else { - player->setInput(Input::Action::START); - player->setPlayingState(Player::State::SHOWING_NAME); - playSound("service_menu_select.wav"); - updateHiScoreName(); + player->passShowingName(); + return; } + player->setInput(Input::Action::START); + player->setPlayingState(Player::State::SHOWING_NAME); + playSound("service_menu_select.wav"); + updateHiScoreName(); } } @@ -1558,60 +1583,51 @@ void Game::initDifficultyVars() { // Inicializa los jugadores void Game::initPlayers(Player::Id player_id) { const int Y = param.game.play_area.rect.h - Player::HEIGHT + 1; // Se hunde un pixel para esconder el outline de los pies + const Player::State STATE = demo_.enabled ? Player::State::PLAYING : Player::State::ENTERING_SCREEN; // Crea al jugador uno y lo pone en modo espera - Player::Config config_player1; - config_player1.id = Player::Id::PLAYER1; - config_player1.x = param.game.play_area.first_quarter_x - (Player::WIDTH / 2); - config_player1.y = Y; - config_player1.demo = demo_.enabled; - config_player1.play_area = ¶m.game.play_area.rect; - config_player1.texture = player_textures_.at(0); - config_player1.animations = player_animations_; - config_player1.hi_score_table = &Options::settings.hi_score_table; - config_player1.glowing_entry = &Options::settings.glowing_entries.at(static_cast(Player::Id::PLAYER1) - 1); - config_player1.stage_info = stage_manager_.get(); + Player::Config config_player1{ + .id = Player::Id::PLAYER1, + .x = param.game.play_area.first_quarter_x - (Player::WIDTH / 2), + .y = Y, + .demo = demo_.enabled, + .play_area = ¶m.game.play_area.rect, + .texture = player_textures_.at(0), + .animations = player_animations_, + .hi_score_table = &Options::settings.hi_score_table, + .glowing_entry = &Options::settings.glowing_entries.at(static_cast(Player::Id::PLAYER1) - 1), + .stage_info = stage_manager_.get()}; auto player1 = std::make_unique(config_player1); player1->setScoreBoardPanel(Scoreboard::Id::LEFT); player1->setName(Lang::getText("[SCOREBOARD] 1")); player1->setGamepad(Options::gamepad_manager.getGamepad(Player::Id::PLAYER1).instance); player1->setUsesKeyboard(Player::Id::PLAYER1 == Options::keyboard.player_id); - player1->setPlayingState(Player::State::WAITING); - players_.push_back(std::move(player1)); + player1->setPlayingState((player_id == Player::Id::BOTH_PLAYERS || player_id == Player::Id::PLAYER1) ? STATE : Player::State::WAITING); // Crea al jugador dos y lo pone en modo espera - Player::Config config_player2; - config_player2.id = Player::Id::PLAYER2; - config_player2.x = param.game.play_area.third_quarter_x - (Player::WIDTH / 2); - config_player2.y = Y; - config_player2.demo = demo_.enabled; - config_player2.play_area = ¶m.game.play_area.rect; - config_player2.texture = player_textures_.at(1); - config_player2.animations = player_animations_; - config_player2.hi_score_table = &Options::settings.hi_score_table; - config_player2.glowing_entry = &Options::settings.glowing_entries.at(static_cast(Player::Id::PLAYER2) - 1); - config_player2.stage_info = stage_manager_.get(); + Player::Config config_player2{ + .id = Player::Id::PLAYER2, + .x = param.game.play_area.third_quarter_x - (Player::WIDTH / 2), + .y = Y, + .demo = demo_.enabled, + .play_area = ¶m.game.play_area.rect, + .texture = player_textures_.at(1), + .animations = player_animations_, + .hi_score_table = &Options::settings.hi_score_table, + .glowing_entry = &Options::settings.glowing_entries.at(static_cast(Player::Id::PLAYER2) - 1), + .stage_info = stage_manager_.get()}; auto player2 = std::make_unique(config_player2); player2->setScoreBoardPanel(Scoreboard::Id::RIGHT); player2->setName(Lang::getText("[SCOREBOARD] 2")); player2->setGamepad(Options::gamepad_manager.getGamepad(Player::Id::PLAYER2).instance); player2->setUsesKeyboard(Player::Id::PLAYER2 == Options::keyboard.player_id); - player2->setPlayingState(Player::State::WAITING); - players_.push_back(std::move(player2)); + player2->setPlayingState((player_id == Player::Id::BOTH_PLAYERS || player_id == Player::Id::PLAYER2) ? STATE : Player::State::WAITING); - // Activa el jugador que coincide con el "player_id" o ambos si es "0" - if (player_id == Player::Id::BOTH_PLAYERS) { - // Activa ambos jugadores - getPlayer(Player::Id::PLAYER1)->setPlayingState(demo_.enabled ? Player::State::PLAYING : Player::State::ENTERING_SCREEN); - getPlayer(Player::Id::PLAYER2)->setPlayingState(demo_.enabled ? Player::State::PLAYING : Player::State::ENTERING_SCREEN); - } else { - // Activa el jugador elegido - auto player = getPlayer(player_id); - player->setPlayingState(demo_.enabled ? Player::State::PLAYING : Player::State::ENTERING_SCREEN); - sendPlayerToTheFront(player); - } + // Añade los jugadores al vector de forma que el jugador 1 se pinte por delante del jugador 2 + players_.push_back(std::move(player2)); + players_.push_back(std::move(player1)); // Registra los jugadores en Options for (const auto &player : players_) {