Els panels del marcador ara canvien de mode a petició i no a cada frame
This commit is contained in:
@@ -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 *> 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
|
||||
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
|
||||
this->id = 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;
|
||||
}
|
||||
Reference in New Issue
Block a user