Els panels del marcador ara canvien de mode a petició i no a cada frame

This commit is contained in:
2024-10-06 20:19:43 +02:00
parent 6ea6f85e3e
commit a95e5077e3
5 changed files with 90 additions and 19 deletions

View File

@@ -128,14 +128,14 @@ void Game::init(int playerID)
players.clear(); players.clear();
// Crea los dos jugadores // Crea los dos jugadores
Player *player1 = new Player(1, (param.game.playArea.firstQuarterX * ((0 * 2) + 1)) - 11, param.game.playArea.rect.h - 30, &param.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, &param.game.playArea.rect, playerTextures[0], playerAnimations);
player1->setScoreBoardPanel(SCOREBOARD_LEFT_PANEL); player1->setScoreBoardPanel(SCOREBOARD_LEFT_PANEL);
player1->setName(lang::getText(53)); player1->setName(lang::getText(53));
const int controller1 = getController(player1->getId()); const int controller1 = getController(player1->getId());
player1->setController(controller1); player1->setController(controller1);
players.push_back(player1); players.push_back(player1);
Player *player2 = new Player(2, (param.game.playArea.firstQuarterX * ((1 * 2) + 1)) - 11, param.game.playArea.rect.h - 30, &param.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, &param.game.playArea.rect, playerTextures[1], playerAnimations);
player2->setScoreBoardPanel(SCOREBOARD_RIGHT_PANEL); player2->setScoreBoardPanel(SCOREBOARD_RIGHT_PANEL);
player2->setName(lang::getText(54)); player2->setName(lang::getText(54));
const int controller2 = getController(player2->getId()); const int controller2 = getController(player2->getId());
@@ -1895,7 +1895,7 @@ void Game::update()
updatePlayers(); updatePlayers();
// Actualiza el marcador // Actualiza el marcador
checkPlayersStatusPlaying(); // checkPlayersStatusPlaying();
updateScoreboard(); updateScoreboard();
// Actualiza el fondo // Actualiza el fondo
@@ -2691,14 +2691,14 @@ void Game::checkEvents()
// Ralentiza mucho la lógica // Ralentiza mucho la lógica
case SDLK_4: case SDLK_4:
{ {
ticksSpeed *= 10; ticksSpeed *= 10;
break; break;
} }
// Acelera mucho la lógica // Acelera mucho la lógica
case SDLK_5: case SDLK_5:
{ {
ticksSpeed /= 10; ticksSpeed /= 10;
break; break;
} }
@@ -2828,7 +2828,7 @@ void Game::addScoreToScoreBoard(std::string name, int score)
} }
// Comprueba el estado de los jugadores // Comprueba el estado de los jugadores
void Game::checkPlayersStatusPlaying() /*void Game::checkPlayersStatusPlaying()
{ {
if (demo.enabled) if (demo.enabled)
{ {
@@ -2840,23 +2840,31 @@ void Game::checkPlayersStatusPlaying()
switch (player->getStatusPlaying()) switch (player->getStatusPlaying())
{ {
case playerStatus::PLAYING: case playerStatus::PLAYING:
{
scoreboard->setMode(player->getScoreBoardPanel(), scoreboardMode::SCORE); scoreboard->setMode(player->getScoreBoardPanel(), scoreboardMode::SCORE);
break; break;
}
case playerStatus::CONTINUE: case playerStatus::CONTINUE:
{
scoreboard->setMode(player->getScoreBoardPanel(), scoreboardMode::CONTINUE); scoreboard->setMode(player->getScoreBoardPanel(), scoreboardMode::CONTINUE);
scoreboard->setContinue(player->getScoreBoardPanel(), player->getContinueCounter()); scoreboard->setContinue(player->getScoreBoardPanel(), player->getContinueCounter());
break; break;
}
case playerStatus::WAITING: case playerStatus::WAITING:
{
scoreboard->setMode(player->getScoreBoardPanel(), scoreboardMode::WAITING); scoreboard->setMode(player->getScoreBoardPanel(), scoreboardMode::WAITING);
break; break;
}
case playerStatus::ENTERING_NAME: case playerStatus::ENTERING_NAME:
{
scoreboard->setMode(player->getScoreBoardPanel(), scoreboardMode::ENTER_NAME); scoreboard->setMode(player->getScoreBoardPanel(), scoreboardMode::ENTER_NAME);
scoreboard->setRecordName(player->getScoreBoardPanel(), player->getRecordName()); scoreboard->setRecordName(player->getScoreBoardPanel(), player->getRecordName());
scoreboard->setSelectorPos(player->getScoreBoardPanel(), player->getRecordNamePos()); scoreboard->setSelectorPos(player->getScoreBoardPanel(), player->getRecordNamePos());
break; break;
}
case playerStatus::DYING: case playerStatus::DYING:
break; break;
@@ -2869,20 +2877,16 @@ void Game::checkPlayersStatusPlaying()
} }
case playerStatus::GAME_OVER: case playerStatus::GAME_OVER:
{
scoreboard->setMode(player->getScoreBoardPanel(), scoreboardMode::GAME_OVER); scoreboard->setMode(player->getScoreBoardPanel(), scoreboardMode::GAME_OVER);
break; break;
}
default: default:
break; 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" // Obtiene un jugador a partir de su "id"
Player *Game::getPlayer(int id) Player *Game::getPlayer(int id)

View File

@@ -444,11 +444,8 @@ private:
// Añade una puntuación a la tabla de records // Añade una puntuación a la tabla de records
void addScoreToScoreBoard(std::string name, int score); 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 // Comprueba el estado de juego de los jugadores
void checkPlayersStatusPlaying(); //void checkPlayersStatusPlaying();
// Obtiene un jugador a partir de su "id" // Obtiene un jugador a partir de su "id"
Player *getPlayer(int id); Player *getPlayer(int id);

View File

@@ -7,9 +7,11 @@
#include "input.h" // for inputs_e #include "input.h" // for inputs_e
#include "param.h" // for param #include "param.h" // for param
#include "texture.h" // for Texture #include "texture.h" // for Texture
#include "scoreboard.h" // for Texture
#include "options.h"
// Constructor // Constructor
Player::Player(int id, float x, int y, SDL_Rect *playArea, std::vector<Texture *> texture, std::vector<std::vector<std::string> *> animations) Player::Player(int id, float x, int y, bool demo, SDL_Rect *playArea, std::vector<Texture *> texture, std::vector<std::vector<std::string> *> animations)
{ {
// Reserva memoria para los objetos // Reserva memoria para los objetos
playerSprite = std::unique_ptr<AnimatedSprite>(new AnimatedSprite(texture[0], "", animations[0])); playerSprite = std::unique_ptr<AnimatedSprite>(new AnimatedSprite(texture[0], "", animations[0]));
@@ -30,6 +32,7 @@ Player::Player(int id, float x, int y, SDL_Rect *playArea, std::vector<Texture *
// Inicializa variables // Inicializa variables
this->id = id; this->id = id;
this->demo = demo;
statusPlaying = playerStatus::WAITING; statusPlaying = playerStatus::WAITING;
scoreBoardPanel = 0; scoreBoardPanel = 0;
name = ""; name = "";
@@ -337,6 +340,7 @@ void Player::update()
updatePowerUpCounter(); updatePowerUpCounter();
updateInvulnerable(); updateInvulnerable();
updateContinueCounter(); updateContinueCounter();
updateScoreboard();
} }
// Obtiene la puntuación del jugador // Obtiene la puntuación del jugador
@@ -402,6 +406,39 @@ bool Player::isGameOver() const
return statusPlaying == playerStatus::GAME_OVER; 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 // Establece el estado del jugador en el juego
void Player::setStatusPlaying(playerStatus value) void Player::setStatusPlaying(playerStatus value)
{ {
@@ -413,6 +450,7 @@ void Player::setStatusPlaying(playerStatus value)
{ {
statusPlaying = playerStatus::PLAYING; statusPlaying = playerStatus::PLAYING;
init(); init();
setScoreboardMode(scoreboardMode::SCORE);
break; break;
} }
@@ -422,14 +460,21 @@ void Player::setStatusPlaying(playerStatus value)
continueTicks = SDL_GetTicks(); continueTicks = SDL_GetTicks();
continueCounter = 9; continueCounter = 9;
enterName->init(); enterName->init();
setScoreboardMode(scoreboardMode::CONTINUE);
break; break;
} }
case playerStatus::WAITING: case playerStatus::WAITING:
{
setScoreboardMode(scoreboardMode::WAITING);
break; break;
}
case playerStatus::ENTERING_NAME: case playerStatus::ENTERING_NAME:
{
setScoreboardMode(scoreboardMode::ENTER_NAME);
break; break;
}
case playerStatus::DYING: case playerStatus::DYING:
{ {
@@ -441,10 +486,17 @@ void Player::setStatusPlaying(playerStatus value)
} }
case playerStatus::DIED: case playerStatus::DIED:
{
const auto nextPlayerStatus = IsEligibleForHighScore() ? playerStatus::ENTERING_NAME : playerStatus::CONTINUE;
demo ? setStatusPlaying(playerStatus::WAITING) : setStatusPlaying(nextPlayerStatus);
break; break;
}
case playerStatus::GAME_OVER: case playerStatus::GAME_OVER:
{
setScoreboardMode(scoreboardMode::GAME_OVER);
break; break;
}
default: default:
break; break;
@@ -733,4 +785,10 @@ int Player::getId() const
bool Player::isRenderable() const bool Player::isRenderable() const
{ {
return isPlaying() || isDying(); 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;
} }

View File

@@ -6,6 +6,7 @@
#include <vector> // for vector #include <vector> // for vector
#include "utils.h" // for circle_t #include "utils.h" // for circle_t
#include "enter_name.h" #include "enter_name.h"
#include "scoreboard.h"
#include <memory> #include <memory>
class AnimatedSprite; class AnimatedSprite;
class Texture; class Texture;
@@ -77,6 +78,7 @@ private:
std::string name; // Nombre del jugador std::string name; // Nombre del jugador
std::string recordName; // Nombre del jugador para l atabla de mejores puntuaciones std::string recordName; // Nombre del jugador para l atabla de mejores puntuaciones
int controllerIndex; // Indice del array de mandos que utilizará para moverse 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 // Actualiza el circulo de colisión a la posición del jugador
void shiftColliders(); void shiftColliders();
@@ -90,9 +92,18 @@ private:
// Indica si el jugador se puede dibujar // Indica si el jugador se puede dibujar
bool isRenderable() const; 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: public:
// Constructor // Constructor
Player(int id, float x, int y, SDL_Rect *playArea, std::vector<Texture *> texture, std::vector<std::vector<std::string> *> animations); Player(int id, float x, int y, bool demo, SDL_Rect *playArea, std::vector<Texture *> texture, std::vector<std::vector<std::string> *> animations);
// Destructor // Destructor
~Player() = default; ~Player() = default;

View File

@@ -306,6 +306,7 @@ void Scoreboard::fillPanelTextures()
{ {
// GAME OVER // GAME OVER
textScoreBoard->writeCentered(slot4_1.x, slot4_1.y + 4, lang::getText(102)); 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; break;
} }