From a95e5077e381602c6a732c91e1357f1cf5109955 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sun, 6 Oct 2024 20:19:43 +0200 Subject: [PATCH] =?UTF-8?q?Els=20panels=20del=20marcador=20ara=20canvien?= =?UTF-8?q?=20de=20mode=20a=20petici=C3=B3=20i=20no=20a=20cada=20frame?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/game.cpp | 30 ++++++++++++---------- source/game.h | 5 +--- source/player.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++- source/player.h | 13 +++++++++- source/scoreboard.cpp | 1 + 5 files changed, 90 insertions(+), 19 deletions(-) diff --git a/source/game.cpp b/source/game.cpp index d7a6274..3d21d15 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -128,14 +128,14 @@ void Game::init(int playerID) players.clear(); // Crea los dos jugadores - Player *player1 = new Player(1, (param.game.playArea.firstQuarterX * ((0 * 2) + 1)) - 11, param.game.playArea.rect.h - 30, ¶m.game.playArea.rect, playerTextures[0], playerAnimations); + Player *player1 = new Player(1, (param.game.playArea.firstQuarterX * ((0 * 2) + 1)) - 11, param.game.playArea.rect.h - 30, demo.enabled, ¶m.game.playArea.rect, playerTextures[0], playerAnimations); player1->setScoreBoardPanel(SCOREBOARD_LEFT_PANEL); player1->setName(lang::getText(53)); const int controller1 = getController(player1->getId()); player1->setController(controller1); players.push_back(player1); - Player *player2 = new Player(2, (param.game.playArea.firstQuarterX * ((1 * 2) + 1)) - 11, param.game.playArea.rect.h - 30, ¶m.game.playArea.rect, playerTextures[1], playerAnimations); + Player *player2 = new Player(2, (param.game.playArea.firstQuarterX * ((1 * 2) + 1)) - 11, param.game.playArea.rect.h - 30, demo.enabled, ¶m.game.playArea.rect, playerTextures[1], playerAnimations); player2->setScoreBoardPanel(SCOREBOARD_RIGHT_PANEL); player2->setName(lang::getText(54)); const int controller2 = getController(player2->getId()); @@ -1895,7 +1895,7 @@ void Game::update() updatePlayers(); // Actualiza el marcador - checkPlayersStatusPlaying(); + // checkPlayersStatusPlaying(); updateScoreboard(); // Actualiza el fondo @@ -2691,14 +2691,14 @@ void Game::checkEvents() // Ralentiza mucho la lógica case SDLK_4: { - ticksSpeed *= 10; + ticksSpeed *= 10; break; } // Acelera mucho la lógica case SDLK_5: { - ticksSpeed /= 10; + ticksSpeed /= 10; break; } @@ -2828,7 +2828,7 @@ void Game::addScoreToScoreBoard(std::string name, int score) } // Comprueba el estado de los jugadores -void Game::checkPlayersStatusPlaying() +/*void Game::checkPlayersStatusPlaying() { if (demo.enabled) { @@ -2840,23 +2840,31 @@ void Game::checkPlayersStatusPlaying() switch (player->getStatusPlaying()) { case playerStatus::PLAYING: + { scoreboard->setMode(player->getScoreBoardPanel(), scoreboardMode::SCORE); break; + } case playerStatus::CONTINUE: + { scoreboard->setMode(player->getScoreBoardPanel(), scoreboardMode::CONTINUE); scoreboard->setContinue(player->getScoreBoardPanel(), player->getContinueCounter()); break; + } case playerStatus::WAITING: + { scoreboard->setMode(player->getScoreBoardPanel(), scoreboardMode::WAITING); break; + } case playerStatus::ENTERING_NAME: + { scoreboard->setMode(player->getScoreBoardPanel(), scoreboardMode::ENTER_NAME); scoreboard->setRecordName(player->getScoreBoardPanel(), player->getRecordName()); scoreboard->setSelectorPos(player->getScoreBoardPanel(), player->getRecordNamePos()); break; + } case playerStatus::DYING: break; @@ -2869,20 +2877,16 @@ void Game::checkPlayersStatusPlaying() } case playerStatus::GAME_OVER: + { scoreboard->setMode(player->getScoreBoardPanel(), scoreboardMode::GAME_OVER); break; + } default: break; } } -} - -// Comprueba si la puntuación entra en la tabla de mejores puntuaciones -bool Game::IsEligibleForHighScore(int score) -{ - return score > options.game.hiScoreTable.back().score; -} +}*/ // Obtiene un jugador a partir de su "id" Player *Game::getPlayer(int id) diff --git a/source/game.h b/source/game.h index 6492125..592c5fe 100644 --- a/source/game.h +++ b/source/game.h @@ -444,11 +444,8 @@ private: // Añade una puntuación a la tabla de records void addScoreToScoreBoard(std::string name, int score); - // Comprueba si la puntuación entra en la tabla de mejores puntuaciones - bool IsEligibleForHighScore(int score); - // Comprueba el estado de juego de los jugadores - void checkPlayersStatusPlaying(); + //void checkPlayersStatusPlaying(); // Obtiene un jugador a partir de su "id" Player *getPlayer(int id); diff --git a/source/player.cpp b/source/player.cpp index 4c7cccb..679a314 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -7,9 +7,11 @@ #include "input.h" // for inputs_e #include "param.h" // for param #include "texture.h" // for Texture +#include "scoreboard.h" // for Texture +#include "options.h" // Constructor -Player::Player(int id, float x, int y, SDL_Rect *playArea, std::vector texture, std::vector *> animations) +Player::Player(int id, float x, int y, bool demo, SDL_Rect *playArea, std::vector texture, std::vector *> animations) { // Reserva memoria para los objetos playerSprite = std::unique_ptr(new AnimatedSprite(texture[0], "", animations[0])); @@ -30,6 +32,7 @@ Player::Player(int id, float x, int y, SDL_Rect *playArea, std::vectorid = id; + this->demo = demo; statusPlaying = playerStatus::WAITING; scoreBoardPanel = 0; name = ""; @@ -337,6 +340,7 @@ void Player::update() updatePowerUpCounter(); updateInvulnerable(); updateContinueCounter(); + updateScoreboard(); } // Obtiene la puntuación del jugador @@ -402,6 +406,39 @@ bool Player::isGameOver() const return statusPlaying == playerStatus::GAME_OVER; } +// Actualiza el panel del marcador +void Player::updateScoreboard() +{ + switch (statusPlaying) + { + + case playerStatus::CONTINUE: + { + Scoreboard::get()->setContinue(getScoreBoardPanel(), getContinueCounter()); + break; + } + + case playerStatus::ENTERING_NAME: + { + Scoreboard::get()->setRecordName(getScoreBoardPanel(), getRecordName()); + Scoreboard::get()->setSelectorPos(getScoreBoardPanel(), getRecordNamePos()); + break; + } + + default: + break; + } +} + +// Cambia el modo del marcador +void Player::setScoreboardMode(scoreboardMode mode) +{ + if (!demo) + { + Scoreboard::get()->setMode(getScoreBoardPanel(), mode); + } +} + // Establece el estado del jugador en el juego void Player::setStatusPlaying(playerStatus value) { @@ -413,6 +450,7 @@ void Player::setStatusPlaying(playerStatus value) { statusPlaying = playerStatus::PLAYING; init(); + setScoreboardMode(scoreboardMode::SCORE); break; } @@ -422,14 +460,21 @@ void Player::setStatusPlaying(playerStatus value) continueTicks = SDL_GetTicks(); continueCounter = 9; enterName->init(); + setScoreboardMode(scoreboardMode::CONTINUE); break; } case playerStatus::WAITING: + { + setScoreboardMode(scoreboardMode::WAITING); break; + } case playerStatus::ENTERING_NAME: + { + setScoreboardMode(scoreboardMode::ENTER_NAME); break; + } case playerStatus::DYING: { @@ -441,10 +486,17 @@ void Player::setStatusPlaying(playerStatus value) } case playerStatus::DIED: + { + const auto nextPlayerStatus = IsEligibleForHighScore() ? playerStatus::ENTERING_NAME : playerStatus::CONTINUE; + demo ? setStatusPlaying(playerStatus::WAITING) : setStatusPlaying(nextPlayerStatus); break; + } case playerStatus::GAME_OVER: + { + setScoreboardMode(scoreboardMode::GAME_OVER); break; + } default: break; @@ -733,4 +785,10 @@ int Player::getId() const bool Player::isRenderable() const { return isPlaying() || isDying(); +} + +// Comprueba si la puntuación entra en la tabla de mejores puntuaciones +bool Player::IsEligibleForHighScore() +{ + return score > options.game.hiScoreTable.back().score; } \ No newline at end of file diff --git a/source/player.h b/source/player.h index 53628f4..cc5e826 100644 --- a/source/player.h +++ b/source/player.h @@ -6,6 +6,7 @@ #include // for vector #include "utils.h" // for circle_t #include "enter_name.h" +#include "scoreboard.h" #include class AnimatedSprite; class Texture; @@ -77,6 +78,7 @@ private: std::string name; // Nombre del jugador std::string recordName; // Nombre del jugador para l atabla de mejores puntuaciones int controllerIndex; // Indice del array de mandos que utilizará para moverse + bool demo; // Para que el jugador sepa si está en el modo demostración // Actualiza el circulo de colisión a la posición del jugador void shiftColliders(); @@ -90,9 +92,18 @@ private: // Indica si el jugador se puede dibujar bool isRenderable() const; + // Actualiza el panel del marcador + void updateScoreboard(); + + // Comprueba si la puntuación entra en la tabla de mejores puntuaciones + bool IsEligibleForHighScore(); + + // Cambia el modo del marcador + void setScoreboardMode(scoreboardMode mode); + public: // Constructor - Player(int id, float x, int y, SDL_Rect *playArea, std::vector texture, std::vector *> animations); + Player(int id, float x, int y, bool demo, SDL_Rect *playArea, std::vector texture, std::vector *> animations); // Destructor ~Player() = default; diff --git a/source/scoreboard.cpp b/source/scoreboard.cpp index cb1f167..b7b446a 100644 --- a/source/scoreboard.cpp +++ b/source/scoreboard.cpp @@ -306,6 +306,7 @@ void Scoreboard::fillPanelTextures() { // GAME OVER textScoreBoard->writeCentered(slot4_1.x, slot4_1.y + 4, lang::getText(102)); + textScoreBoard->writeCentered(slot4_3.x, slot4_3.y + 4, lang::getText(114)); break; }