Mes recomanacions de cppcheck

This commit is contained in:
2024-10-13 19:26:27 +02:00
parent 46540ad7c3
commit babf02226c
22 changed files with 291 additions and 369 deletions

View File

@@ -12,30 +12,29 @@
// Constructor
Player::Player(int id, float x, int y, bool demo, SDL_Rect *play_area, std::vector<std::shared_ptr<Texture>> texture, std::vector<std::vector<std::string> *> animations)
: player_sprite_(std::make_unique<AnimatedSprite>(texture[0], "", animations[0])),
power_sprite_(std::make_unique<AnimatedSprite>(texture[1], "", animations[1])),
enter_name_(std::make_unique<EnterName>()),
play_area_(play_area),
id_(id),
pos_x_(x),
pos_y_(y),
default_pos_x_(x),
default_pos_y_(y),
status_playing_(PlayerStatus::WAITING),
scoreboard_panel_(0),
name_(std::string()),
controller_index_(0),
demo_(demo)
{
// Reserva memoria para los objetos
player_sprite_ = std::make_unique<AnimatedSprite>(texture[0], "", animations[0]);
power_sprite_ = std::make_unique<AnimatedSprite>(texture[1], "", animations[1]);
power_sprite_->getTexture()->setAlpha(224);
enter_name_ = std::make_unique<EnterName>();
// Rectangulo con la zona de juego
play_area_ = play_area;
// Establece la posición inicial del jugador
default_pos_x_ = pos_x_ = x;
default_pos_y_ = pos_y_ = y;
// Establece los offsets para el sprite de PowerUp
power_up_desp_x_ = (power_sprite_->getWidth() - player_sprite_->getWidth()) / 2;
power_sprite_->setPosY(y - (power_sprite_->getHeight() - player_sprite_->getHeight()));
// Inicializa variables
id_ = id;
demo_ = demo;
status_playing_ = PlayerStatus::WAITING;
scoreboard_panel_ = 0;
name_.clear();
setRecordName(enter_name_->getName());
init();
}
@@ -237,21 +236,13 @@ void Player::render()
// Establece el estado del jugador cuando camina
void Player::setWalkingStatus(PlayerStatus status)
{
// Si cambiamos de estado, reiniciamos la animación
if (status_walking_ != status)
{
status_walking_ = status;
}
status_walking_ = status;
}
// Establece el estado del jugador cuando dispara
void Player::setFiringStatus(PlayerStatus status)
{
// Si cambiamos de estado, reiniciamos la animación
if (status_firing_ != status)
{
status_firing_ = status;
}
status_firing_ = status;
}
// Establece la animación correspondiente al estado
@@ -694,7 +685,7 @@ void Player::shiftColliders()
}
// Pone las texturas del jugador
void Player::setPlayerTextures(std::vector<std::shared_ptr<Texture>> texture)
void Player::setPlayerTextures(const std::vector<std::shared_ptr<Texture>> &texture)
{
player_sprite_->setTexture(texture[0]);
power_sprite_->setTexture(texture[1]);
@@ -736,7 +727,7 @@ int Player::getScoreBoardPanel() const
void Player::decContinueCounter()
{
continue_ticks_ = SDL_GetTicks();
continue_counter_--;
--continue_counter_;
if (continue_counter_ < 0)
{
setStatusPlaying(PlayerStatus::GAME_OVER);
@@ -744,13 +735,13 @@ void Player::decContinueCounter()
}
// Establece el nombre del jugador
void Player::setName(std::string name)
void Player::setName(const std::string &name)
{
name_ = name;
}
// Establece el nombre del jugador para la tabla de mejores puntuaciones
void Player::setRecordName(std::string record_name)
void Player::setRecordName(const std::string &record_name)
{
record_name_ = record_name.substr(0, 8);
}