.
This commit is contained in:
@@ -11,26 +11,18 @@
|
||||
#include "options.h"
|
||||
|
||||
// Constructor
|
||||
Player::Player(int id, float x, int y, bool demo, SDL_Rect *play_area, std::vector<std::shared_ptr<Texture>> texture, const std::vector<std::vector<std::string>> &animations)
|
||||
Player::Player(int id, float x, int y, bool demo, SDL_Rect &play_area, std::vector<std::shared_ptr<Texture>> texture, const 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),
|
||||
play_area_(play_area),
|
||||
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
|
||||
// Configura objetos
|
||||
power_sprite_->getTexture()->setAlpha(224);
|
||||
|
||||
// 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()));
|
||||
|
||||
@@ -46,25 +38,21 @@ void Player::init()
|
||||
pos_x_ = default_pos_x_;
|
||||
pos_y_ = default_pos_y_;
|
||||
status_walking_ = PlayerStatus::WALKING_STOP;
|
||||
status_firing_ = PlayerStatus::FIRING_NO;
|
||||
status_firing_ = PlayerStatus::FIRING_NONE;
|
||||
status_playing_ = PlayerStatus::WAITING;
|
||||
invulnerable_ = true;
|
||||
invulnerable_counter_ = PLAYER_INVULNERABLE_COUNTER;
|
||||
invulnerable_counter_ = INVULNERABLE_COUNTER_;
|
||||
power_up_ = false;
|
||||
power_up_counter_ = PLAYER_POWERUP_COUNTER;
|
||||
power_up_counter_ = POWERUP_COUNTER_;
|
||||
extra_hit_ = false;
|
||||
coffees_ = 0;
|
||||
input_ = true;
|
||||
continue_ticks_ = 0;
|
||||
continue_counter_ = 10;
|
||||
enter_name_ticks_ = 0;
|
||||
enter_name_counter_ = param.game.enter_name_seconds;
|
||||
width_ = 30;
|
||||
height_ = 30;
|
||||
collider_.r = 9;
|
||||
shiftColliders();
|
||||
vel_x_ = 0;
|
||||
vel_y_ = 0;
|
||||
base_speed_ = 1.5;
|
||||
score_ = 0;
|
||||
score_multiplier_ = 1.0f;
|
||||
cooldown_ = 10;
|
||||
@@ -107,14 +95,14 @@ void Player::setInputPlaying(InputType input)
|
||||
{
|
||||
case InputType::LEFT:
|
||||
{
|
||||
vel_x_ = -base_speed_;
|
||||
vel_x_ = -BASE_SPEED_;
|
||||
setWalkingStatus(PlayerStatus::WALKING_LEFT);
|
||||
break;
|
||||
}
|
||||
|
||||
case InputType::RIGHT:
|
||||
{
|
||||
vel_x_ = base_speed_;
|
||||
vel_x_ = BASE_SPEED_;
|
||||
setWalkingStatus(PlayerStatus::WALKING_RIGHT);
|
||||
break;
|
||||
}
|
||||
@@ -186,7 +174,7 @@ void Player::move()
|
||||
pos_x_ += vel_x_;
|
||||
|
||||
// Si el jugador abandona el area de juego por los laterales
|
||||
if ((pos_x_ < param.game.play_area.rect.x - 5) || (pos_x_ + width_ > play_area_->w + 5))
|
||||
if ((pos_x_ < param.game.play_area.rect.x - 5) || (pos_x_ + WIDTH_ > play_area_.w + 5))
|
||||
{
|
||||
// Restaura su posición
|
||||
pos_x_ -= vel_x_;
|
||||
@@ -203,7 +191,7 @@ void Player::move()
|
||||
player_sprite_->update();
|
||||
|
||||
// Si el cadaver abandona el area de juego por los laterales
|
||||
if ((player_sprite_->getPosX() < param.game.play_area.rect.x) || (player_sprite_->getPosX() + width_ > play_area_->w))
|
||||
if ((player_sprite_->getPosX() < param.game.play_area.rect.x) || (player_sprite_->getPosX() + WIDTH_ > play_area_.w))
|
||||
{
|
||||
// Restaura su posición
|
||||
const float vx = player_sprite_->getVelX();
|
||||
@@ -226,7 +214,7 @@ void Player::render()
|
||||
{
|
||||
if (power_up_ && isPlaying())
|
||||
{
|
||||
if (power_up_counter_ > (PLAYER_POWERUP_COUNTER / 4) || power_up_counter_ % 20 > 4)
|
||||
if (power_up_counter_ > (POWERUP_COUNTER_ / 4) || power_up_counter_ % 20 > 4)
|
||||
{
|
||||
power_sprite_->render();
|
||||
}
|
||||
@@ -261,7 +249,7 @@ void Player::setAnimation()
|
||||
// Establece la animación a partir de las cadenas
|
||||
if (isPlaying())
|
||||
{
|
||||
if (status_firing_ == PlayerStatus::FIRING_NO)
|
||||
if (status_firing_ == PlayerStatus::FIRING_NONE)
|
||||
{ // No esta disparando
|
||||
player_sprite_->setCurrentAnimation(a_walking);
|
||||
player_sprite_->setFlip(flip_walk);
|
||||
@@ -301,13 +289,13 @@ int Player::getPosY() const
|
||||
// Obtiene el valor de la variable
|
||||
int Player::getWidth() const
|
||||
{
|
||||
return width_;
|
||||
return WIDTH_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int Player::getHeight() const
|
||||
{
|
||||
return height_;
|
||||
return HEIGHT_;
|
||||
}
|
||||
|
||||
// Indica si el jugador puede disparar
|
||||
@@ -336,7 +324,7 @@ void Player::updateCooldown()
|
||||
}
|
||||
else
|
||||
{
|
||||
setFiringStatus(PlayerStatus::FIRING_NO);
|
||||
setFiringStatus(PlayerStatus::FIRING_NONE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -459,8 +447,8 @@ void Player::setStatusPlaying(PlayerStatus value)
|
||||
{
|
||||
case PlayerStatus::PLAYING:
|
||||
{
|
||||
status_playing_ = PlayerStatus::PLAYING;
|
||||
init();
|
||||
status_playing_ = PlayerStatus::PLAYING;
|
||||
setScoreboardMode(ScoreboardMode::SCORE);
|
||||
break;
|
||||
}
|
||||
@@ -556,7 +544,7 @@ bool Player::isInvulnerable() const
|
||||
void Player::setInvulnerable(bool value)
|
||||
{
|
||||
invulnerable_ = value;
|
||||
invulnerable_counter_ = invulnerable_ ? PLAYER_INVULNERABLE_COUNTER : 0;
|
||||
invulnerable_counter_ = invulnerable_ ? INVULNERABLE_COUNTER_ : 0;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
@@ -599,7 +587,7 @@ bool Player::isPowerUp() const
|
||||
void Player::setPowerUp()
|
||||
{
|
||||
power_up_ = true;
|
||||
power_up_counter_ = PLAYER_POWERUP_COUNTER;
|
||||
power_up_counter_ = POWERUP_COUNTER_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
@@ -654,18 +642,6 @@ void Player::removeExtraHit()
|
||||
extra_hit_ = coffees_ == 0 ? false : true;
|
||||
}
|
||||
|
||||
// Habilita la entrada de ordenes
|
||||
void Player::enableInput()
|
||||
{
|
||||
input_ = true;
|
||||
}
|
||||
|
||||
// Deshabilita la entrada de ordenes
|
||||
void Player::disableInput()
|
||||
{
|
||||
input_ = false;
|
||||
}
|
||||
|
||||
// Devuelve el número de cafes actuales
|
||||
int Player::getCoffees() const
|
||||
{
|
||||
@@ -681,8 +657,8 @@ Circle &Player::getCollider()
|
||||
// Actualiza el circulo de colisión a la posición del jugador
|
||||
void Player::shiftColliders()
|
||||
{
|
||||
collider_.x = int(pos_x_ + (width_ / 2));
|
||||
collider_.y = int(pos_y_ + (height_ / 2));
|
||||
collider_.x = static_cast<int>(pos_x_ + (WIDTH_ / 2));
|
||||
collider_.y = static_cast<int>(pos_y_ + (HEIGHT_ / 2));
|
||||
}
|
||||
|
||||
// Pone las texturas del jugador
|
||||
@@ -703,9 +679,8 @@ void Player::updateContinueCounter()
|
||||
{
|
||||
if (status_playing_ == PlayerStatus::CONTINUE)
|
||||
{
|
||||
constexpr Uint32 ticks_speed = 1000;
|
||||
|
||||
if (SDL_GetTicks() - continue_ticks_ > ticks_speed)
|
||||
constexpr int TICKS_SPEED = 1000;
|
||||
if (SDL_GetTicks() - continue_ticks_ > TICKS_SPEED)
|
||||
{
|
||||
decContinueCounter();
|
||||
}
|
||||
@@ -717,9 +692,8 @@ void Player::updateEnterNameCounter()
|
||||
{
|
||||
if (status_playing_ == PlayerStatus::ENTERING_NAME)
|
||||
{
|
||||
constexpr Uint32 ticks_speed = 1000;
|
||||
|
||||
if (SDL_GetTicks() - enter_name_ticks_ > ticks_speed)
|
||||
constexpr int TICKS_SPEED = 1000;
|
||||
if (SDL_GetTicks() - enter_name_ticks_ > TICKS_SPEED)
|
||||
{
|
||||
decEnterNameCounter();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user