Abans de renombrar game.cpp
This commit is contained in:
@@ -11,32 +11,32 @@
|
||||
#include "options.h"
|
||||
|
||||
// Constructor
|
||||
Player::Player(int id, float x, int y, bool demo, SDL_Rect *playArea, std::vector<std::shared_ptr<Texture>> texture, 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, std::vector<std::vector<std::string> *> animations)
|
||||
{
|
||||
// Reserva memoria para los objetos
|
||||
playerSprite = std::make_unique<AnimatedSprite>(texture[0], "", animations[0]);
|
||||
powerSprite = std::make_unique<AnimatedSprite>(texture[1], "", animations[1]);
|
||||
powerSprite->getTexture()->setAlpha(224);
|
||||
enterName = std::make_unique<EnterName>();
|
||||
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
|
||||
this->playArea = playArea;
|
||||
play_area_ = play_area;
|
||||
|
||||
// Establece la posición inicial del jugador
|
||||
defaultPosX = posX = x;
|
||||
defaultPosY = posY = y;
|
||||
default_pos_x_ = pos_x_ = x;
|
||||
default_pos_y_ = pos_y_ = y;
|
||||
|
||||
// Establece los offsets para el sprite de PowerUp
|
||||
powerUpDespX = (powerSprite->getWidth() - playerSprite->getWidth()) / 2;
|
||||
powerSprite->setPosY(y - (powerSprite->getHeight() - playerSprite->getHeight()));
|
||||
power_up_desp_x_ = (power_sprite_->getWidth() - player_sprite_->getWidth()) / 2;
|
||||
power_sprite_->setPosY(y - (power_sprite_->getHeight() - player_sprite_->getHeight()));
|
||||
|
||||
// Inicializa variables
|
||||
this->id = id;
|
||||
this->demo = demo;
|
||||
statusPlaying = PlayerStatus::WAITING;
|
||||
scoreBoardPanel = 0;
|
||||
name = "";
|
||||
setRecordName(enterName->getName());
|
||||
id_ = id;
|
||||
demo_ = demo;
|
||||
status_playing_ = PlayerStatus::WAITING;
|
||||
scoreboard_panel_ = 0;
|
||||
name_ = "";
|
||||
setRecordName(enter_name_->getName());
|
||||
init();
|
||||
}
|
||||
|
||||
@@ -44,50 +44,54 @@ Player::Player(int id, float x, int y, bool demo, SDL_Rect *playArea, std::vecto
|
||||
void Player::init()
|
||||
{
|
||||
// Inicializa variables de estado
|
||||
posX = defaultPosX;
|
||||
posY = defaultPosY;
|
||||
statusWalking = PlayerStatus::WALKING_STOP;
|
||||
statusFiring = PlayerStatus::FIRING_NO;
|
||||
invulnerable = true;
|
||||
invulnerableCounter = PLAYER_INVULNERABLE_COUNTER;
|
||||
powerUp = false;
|
||||
powerUpCounter = PLAYER_POWERUP_COUNTER;
|
||||
extraHit = false;
|
||||
coffees = 0;
|
||||
input = true;
|
||||
continueTicks = 0;
|
||||
continueCounter = 20;
|
||||
width = 30;
|
||||
height = 30;
|
||||
collider.r = 9;
|
||||
pos_x_ = default_pos_x_;
|
||||
pos_y_ = default_pos_y_;
|
||||
status_walking_ = PlayerStatus::WALKING_STOP;
|
||||
status_firing_ = PlayerStatus::FIRING_NO;
|
||||
invulnerable_ = true;
|
||||
invulnerable_counter_ = PLAYER_INVULNERABLE_COUNTER;
|
||||
power_up_ = false;
|
||||
power_up_counter_ = PLAYER_POWERUP_COUNTER;
|
||||
extra_hit_ = false;
|
||||
coffees_ = 0;
|
||||
input_ = true;
|
||||
continue_ticks_ = 0;
|
||||
continue_counter_ = 20;
|
||||
width_ = 30;
|
||||
height_ = 30;
|
||||
collider_.r = 9;
|
||||
shiftColliders();
|
||||
velX = 0;
|
||||
velY = 0;
|
||||
baseSpeed = 1.5;
|
||||
score = 0;
|
||||
scoreMultiplier = 1.0f;
|
||||
cooldown = 10;
|
||||
vel_x_ = 0;
|
||||
vel_y_ = 0;
|
||||
base_speed_ = 1.5;
|
||||
score_ = 0;
|
||||
score_multiplier_ = 1.0f;
|
||||
cooldown_ = 10;
|
||||
|
||||
// Establece la posición del sprite
|
||||
playerSprite->setPosX(posX);
|
||||
playerSprite->setPosY(posY);
|
||||
player_sprite_->setPosX(pos_x_);
|
||||
player_sprite_->setPosY(pos_y_);
|
||||
|
||||
// Selecciona un frame para pintar
|
||||
playerSprite->setCurrentAnimation("stand");
|
||||
player_sprite_->setCurrentAnimation("stand");
|
||||
}
|
||||
|
||||
// Actua en consecuencia de la entrada recibida
|
||||
void Player::setInput(int input)
|
||||
{
|
||||
switch (statusPlaying)
|
||||
switch (status_playing_)
|
||||
{
|
||||
case PlayerStatus::PLAYING:
|
||||
{
|
||||
setInputPlaying(input);
|
||||
break;
|
||||
}
|
||||
|
||||
case PlayerStatus::ENTERING_NAME:
|
||||
{
|
||||
setInputEnteringName(input);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
@@ -100,33 +104,45 @@ void Player::setInputPlaying(int input)
|
||||
switch (input)
|
||||
{
|
||||
case input_left:
|
||||
velX = -baseSpeed;
|
||||
{
|
||||
vel_x_ = -base_speed_;
|
||||
setWalkingStatus(PlayerStatus::WALKING_LEFT);
|
||||
break;
|
||||
}
|
||||
|
||||
case input_right:
|
||||
velX = baseSpeed;
|
||||
{
|
||||
vel_x_ = base_speed_;
|
||||
setWalkingStatus(PlayerStatus::WALKING_RIGHT);
|
||||
break;
|
||||
}
|
||||
|
||||
case input_fire_center:
|
||||
{
|
||||
setFiringStatus(PlayerStatus::FIRING_UP);
|
||||
break;
|
||||
}
|
||||
|
||||
case input_fire_left:
|
||||
{
|
||||
setFiringStatus(PlayerStatus::FIRING_LEFT);
|
||||
break;
|
||||
}
|
||||
|
||||
case input_fire_right:
|
||||
{
|
||||
setFiringStatus(PlayerStatus::FIRING_RIGHT);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
velX = 0;
|
||||
{
|
||||
vel_x_ = 0;
|
||||
setWalkingStatus(PlayerStatus::WALKING_STOP);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Procesa inputs para cuando está introduciendo el nombre
|
||||
void Player::setInputEnteringName(int input)
|
||||
@@ -134,29 +150,29 @@ void Player::setInputEnteringName(int input)
|
||||
switch (input)
|
||||
{
|
||||
case input_left:
|
||||
enterName->decPos();
|
||||
enter_name_->decPos();
|
||||
break;
|
||||
|
||||
case input_right:
|
||||
enterName->incPos();
|
||||
enter_name_->incPos();
|
||||
break;
|
||||
|
||||
case input_up:
|
||||
enterName->incIndex();
|
||||
enter_name_->incIndex();
|
||||
break;
|
||||
|
||||
case input_down:
|
||||
enterName->decIndex();
|
||||
enter_name_->decIndex();
|
||||
break;
|
||||
|
||||
case input_start:
|
||||
setRecordName(enterName->getName());
|
||||
setRecordName(enter_name_->getName());
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
setRecordName(enterName->getName());
|
||||
setRecordName(enter_name_->getName());
|
||||
}
|
||||
|
||||
// Mueve el jugador a la posición y animación que le corresponde
|
||||
@@ -165,38 +181,38 @@ void Player::move()
|
||||
if (isPlaying())
|
||||
{
|
||||
// Mueve el jugador a derecha o izquierda
|
||||
posX += velX;
|
||||
pos_x_ += vel_x_;
|
||||
|
||||
// Si el jugador abandona el area de juego por los laterales
|
||||
if ((posX < param.game.play_area.rect.x - 5) || (posX + width > playArea->w + 5))
|
||||
if ((pos_x_ < param.game.play_area.rect.x - 5) || (pos_x_ + width_ > play_area_->w + 5))
|
||||
{
|
||||
// Restaura su posición
|
||||
posX -= velX;
|
||||
pos_x_ -= vel_x_;
|
||||
}
|
||||
|
||||
// Actualiza la posición del sprite
|
||||
playerSprite->setPosX(getPosX());
|
||||
playerSprite->setPosY(posY);
|
||||
player_sprite_->setPosX(getPosX());
|
||||
player_sprite_->setPosY(pos_y_);
|
||||
|
||||
powerSprite->setPosX(getPosX() - powerUpDespX);
|
||||
power_sprite_->setPosX(getPosX() - power_up_desp_x_);
|
||||
}
|
||||
else if (isDying())
|
||||
{
|
||||
playerSprite->update();
|
||||
player_sprite_->update();
|
||||
|
||||
// Si el cadaver abandona el area de juego por los laterales
|
||||
if ((playerSprite->getPosX() < param.game.play_area.rect.x) || (playerSprite->getPosX() + width > playArea->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 = playerSprite->getVelX();
|
||||
playerSprite->setPosX(playerSprite->getPosX() - vx);
|
||||
const float vx = player_sprite_->getVelX();
|
||||
player_sprite_->setPosX(player_sprite_->getPosX() - vx);
|
||||
|
||||
// Rebota
|
||||
playerSprite->setVelX(-vx);
|
||||
player_sprite_->setVelX(-vx);
|
||||
}
|
||||
|
||||
// Si el cadaver abandona el area de juego por abajo
|
||||
if (playerSprite->getPosY() > param.game.play_area.rect.h)
|
||||
if (player_sprite_->getPosY() > param.game.play_area.rect.h)
|
||||
{
|
||||
setStatusPlaying(PlayerStatus::DIED);
|
||||
}
|
||||
@@ -206,25 +222,25 @@ void Player::move()
|
||||
// Pinta el jugador en pantalla
|
||||
void Player::render()
|
||||
{
|
||||
if (powerUp && isPlaying())
|
||||
if (power_up_ && isPlaying())
|
||||
{
|
||||
if (powerUpCounter > (PLAYER_POWERUP_COUNTER / 4) || powerUpCounter % 20 > 4)
|
||||
if (power_up_counter_ > (PLAYER_POWERUP_COUNTER / 4) || power_up_counter_ % 20 > 4)
|
||||
{
|
||||
powerSprite->render();
|
||||
power_sprite_->render();
|
||||
}
|
||||
}
|
||||
|
||||
if (isRenderable())
|
||||
playerSprite->render();
|
||||
player_sprite_->render();
|
||||
}
|
||||
|
||||
// Establece el estado del jugador cuando camina
|
||||
void Player::setWalkingStatus(PlayerStatus status)
|
||||
{
|
||||
// Si cambiamos de estado, reiniciamos la animación
|
||||
if (statusWalking != status)
|
||||
if (status_walking_ != status)
|
||||
{
|
||||
statusWalking = status;
|
||||
status_walking_ = status;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,9 +248,9 @@ void Player::setWalkingStatus(PlayerStatus status)
|
||||
void Player::setFiringStatus(PlayerStatus status)
|
||||
{
|
||||
// Si cambiamos de estado, reiniciamos la animación
|
||||
if (statusFiring != status)
|
||||
if (status_firing_ != status)
|
||||
{
|
||||
statusFiring = status;
|
||||
status_firing_ = status;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,86 +258,86 @@ void Player::setFiringStatus(PlayerStatus status)
|
||||
void Player::setAnimation()
|
||||
{
|
||||
// Crea cadenas de texto para componer el nombre de la animación
|
||||
const std::string aWalking = statusWalking == PlayerStatus::WALKING_STOP ? "stand" : "walk";
|
||||
const std::string aFiring = statusFiring == PlayerStatus::FIRING_UP ? "centershoot" : "sideshoot";
|
||||
const std::string a_walking = status_walking_ == PlayerStatus::WALKING_STOP ? "stand" : "walk";
|
||||
const std::string a_firing = status_firing_ == PlayerStatus::FIRING_UP ? "centershoot" : "sideshoot";
|
||||
|
||||
const SDL_RendererFlip flipWalk = statusWalking == PlayerStatus::WALKING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||
const SDL_RendererFlip flipFire = statusFiring == PlayerStatus::FIRING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||
const SDL_RendererFlip flip_walk = status_walking_ == PlayerStatus::WALKING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||
const SDL_RendererFlip flip_fire = status_firing_ == PlayerStatus::FIRING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||
|
||||
// Establece la animación a partir de las cadenas
|
||||
if (isPlaying())
|
||||
{
|
||||
if (statusFiring == PlayerStatus::FIRING_NO)
|
||||
if (status_firing_ == PlayerStatus::FIRING_NO)
|
||||
{ // No esta disparando
|
||||
playerSprite->setCurrentAnimation(aWalking);
|
||||
playerSprite->setFlip(flipWalk);
|
||||
player_sprite_->setCurrentAnimation(a_walking);
|
||||
player_sprite_->setFlip(flip_walk);
|
||||
}
|
||||
else
|
||||
{ // Está disparando
|
||||
playerSprite->setCurrentAnimation(aWalking + "-" + aFiring);
|
||||
player_sprite_->setCurrentAnimation(a_walking + "-" + a_firing);
|
||||
// Si dispara de lado, invierte el sprite segun hacia donde dispara
|
||||
// Si dispara recto, invierte el sprite segun hacia donde camina
|
||||
aFiring == "centershoot" ? playerSprite->setFlip(flipWalk) : playerSprite->setFlip(flipFire);
|
||||
a_firing == "centershoot" ? player_sprite_->setFlip(flip_walk) : player_sprite_->setFlip(flip_fire);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
playerSprite->setCurrentAnimation("death");
|
||||
player_sprite_->setCurrentAnimation("death");
|
||||
}
|
||||
|
||||
// Actualiza las animaciones de los sprites
|
||||
playerSprite->animate();
|
||||
player_sprite_->animate();
|
||||
|
||||
// powerSprite->setFlip(flipWalk);
|
||||
powerSprite->animate();
|
||||
// powerSprite->setFlip(flip_walk);
|
||||
power_sprite_->animate();
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int Player::getPosX() const
|
||||
{
|
||||
return int(posX);
|
||||
return int(pos_x_);
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int Player::getPosY() const
|
||||
{
|
||||
return posY;
|
||||
return pos_y_;
|
||||
}
|
||||
|
||||
// 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
|
||||
bool Player::canFire() const
|
||||
{
|
||||
// Si el contador a llegado a cero, podemos disparar. En caso contrario decrementamos el contador
|
||||
return cooldown > 0 ? false : true;
|
||||
return cooldown_ > 0 ? false : true;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Player::setFireCooldown(int time)
|
||||
{
|
||||
cooldown = time;
|
||||
cooldown_ = time;
|
||||
}
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void Player::updateCooldown()
|
||||
{
|
||||
if (cooldown > 0)
|
||||
if (cooldown_ > 0)
|
||||
{
|
||||
cooldown--;
|
||||
if (powerUp)
|
||||
cooldown_--;
|
||||
if (power_up_)
|
||||
{
|
||||
cooldown--;
|
||||
cooldown_--;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -346,13 +362,13 @@ void Player::update()
|
||||
// Obtiene la puntuación del jugador
|
||||
int Player::getScore() const
|
||||
{
|
||||
return score;
|
||||
return score_;
|
||||
}
|
||||
|
||||
// Asigna un valor a la puntuación del jugador
|
||||
void Player::setScore(int score)
|
||||
{
|
||||
this->score = score;
|
||||
score_ = score;
|
||||
}
|
||||
|
||||
// Incrementa la puntuación del jugador
|
||||
@@ -360,56 +376,56 @@ void Player::addScore(int score)
|
||||
{
|
||||
if (isPlaying())
|
||||
{
|
||||
this->score += score;
|
||||
score_ += score;
|
||||
}
|
||||
}
|
||||
|
||||
// Indica si el jugador está jugando
|
||||
bool Player::isPlaying() const
|
||||
{
|
||||
return statusPlaying == PlayerStatus::PLAYING;
|
||||
return status_playing_ == PlayerStatus::PLAYING;
|
||||
}
|
||||
|
||||
// Indica si el jugador está continuando
|
||||
bool Player::isContinue() const
|
||||
{
|
||||
return statusPlaying == PlayerStatus::CONTINUE;
|
||||
return status_playing_ == PlayerStatus::CONTINUE;
|
||||
}
|
||||
|
||||
// Indica si el jugador está esperando
|
||||
bool Player::isWaiting() const
|
||||
{
|
||||
return statusPlaying == PlayerStatus::WAITING;
|
||||
return status_playing_ == PlayerStatus::WAITING;
|
||||
}
|
||||
|
||||
// Indica si el jugador está introduciendo su nombre
|
||||
bool Player::isEnteringName() const
|
||||
{
|
||||
return statusPlaying == PlayerStatus::ENTERING_NAME;
|
||||
return status_playing_ == PlayerStatus::ENTERING_NAME;
|
||||
}
|
||||
|
||||
// Indica si el jugador está muriendose
|
||||
bool Player::isDying() const
|
||||
{
|
||||
return statusPlaying == PlayerStatus::DYING;
|
||||
return status_playing_ == PlayerStatus::DYING;
|
||||
}
|
||||
|
||||
// Indica si el jugador ha terminado de morir
|
||||
bool Player::hasDied() const
|
||||
{
|
||||
return statusPlaying == PlayerStatus::DIED;
|
||||
return status_playing_ == PlayerStatus::DIED;
|
||||
}
|
||||
|
||||
// Indica si el jugador ya ha terminado de jugar
|
||||
bool Player::isGameOver() const
|
||||
{
|
||||
return statusPlaying == PlayerStatus::GAME_OVER;
|
||||
return status_playing_ == PlayerStatus::GAME_OVER;
|
||||
}
|
||||
|
||||
// Actualiza el panel del marcador
|
||||
void Player::updateScoreboard()
|
||||
{
|
||||
switch (statusPlaying)
|
||||
switch (status_playing_)
|
||||
{
|
||||
|
||||
case PlayerStatus::CONTINUE:
|
||||
@@ -433,7 +449,7 @@ void Player::updateScoreboard()
|
||||
// Cambia el modo del marcador
|
||||
void Player::setScoreboardMode(ScoreboardMode mode)
|
||||
{
|
||||
if (!demo)
|
||||
if (!demo_)
|
||||
{
|
||||
Scoreboard::get()->setMode(getScoreBoardPanel(), mode);
|
||||
}
|
||||
@@ -442,13 +458,13 @@ void Player::setScoreboardMode(ScoreboardMode mode)
|
||||
// Establece el estado del jugador en el juego
|
||||
void Player::setStatusPlaying(PlayerStatus value)
|
||||
{
|
||||
statusPlaying = value;
|
||||
status_playing_ = value;
|
||||
|
||||
switch (statusPlaying)
|
||||
switch (status_playing_)
|
||||
{
|
||||
case PlayerStatus::PLAYING:
|
||||
{
|
||||
statusPlaying = PlayerStatus::PLAYING;
|
||||
status_playing_ = PlayerStatus::PLAYING;
|
||||
init();
|
||||
setScoreboardMode(ScoreboardMode::SCORE);
|
||||
break;
|
||||
@@ -457,9 +473,9 @@ void Player::setStatusPlaying(PlayerStatus value)
|
||||
case PlayerStatus::CONTINUE:
|
||||
{
|
||||
// Inicializa el contador de continuar
|
||||
continueTicks = SDL_GetTicks();
|
||||
continueCounter = 9;
|
||||
enterName->init();
|
||||
continue_ticks_ = SDL_GetTicks();
|
||||
continue_counter_ = 9;
|
||||
enter_name_->init();
|
||||
setScoreboardMode(ScoreboardMode::CONTINUE);
|
||||
break;
|
||||
}
|
||||
@@ -479,16 +495,16 @@ void Player::setStatusPlaying(PlayerStatus value)
|
||||
case PlayerStatus::DYING:
|
||||
{
|
||||
// Activa la animación de morir
|
||||
playerSprite->setAccelY(0.2f);
|
||||
playerSprite->setVelY(-6.6f);
|
||||
rand() % 2 == 0 ? playerSprite->setVelX(3.3f) : playerSprite->setVelX(-3.3f);
|
||||
player_sprite_->setAccelY(0.2f);
|
||||
player_sprite_->setVelY(-6.6f);
|
||||
rand() % 2 == 0 ? player_sprite_->setVelX(3.3f) : player_sprite_->setVelX(-3.3f);
|
||||
break;
|
||||
}
|
||||
|
||||
case PlayerStatus::DIED:
|
||||
{
|
||||
const auto nextPlayerStatus = IsEligibleForHighScore() ? PlayerStatus::ENTERING_NAME : PlayerStatus::CONTINUE;
|
||||
demo ? setStatusPlaying(PlayerStatus::WAITING) : setStatusPlaying(nextPlayerStatus);
|
||||
demo_ ? setStatusPlaying(PlayerStatus::WAITING) : setStatusPlaying(nextPlayerStatus);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -506,74 +522,74 @@ void Player::setStatusPlaying(PlayerStatus value)
|
||||
// Obtiene el estado del jugador en el juego
|
||||
PlayerStatus Player::getStatusPlaying() const
|
||||
{
|
||||
return statusPlaying;
|
||||
return status_playing_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
float Player::getScoreMultiplier() const
|
||||
{
|
||||
return scoreMultiplier;
|
||||
return score_multiplier_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Player::setScoreMultiplier(float value)
|
||||
{
|
||||
scoreMultiplier = value;
|
||||
score_multiplier_ = value;
|
||||
}
|
||||
|
||||
// Aumenta el valor de la variable hasta un máximo
|
||||
void Player::incScoreMultiplier()
|
||||
{
|
||||
scoreMultiplier += 0.1f;
|
||||
scoreMultiplier = std::min(scoreMultiplier, 5.0f);
|
||||
score_multiplier_ += 0.1f;
|
||||
score_multiplier_ = std::min(score_multiplier_, 5.0f);
|
||||
}
|
||||
|
||||
// Decrementa el valor de la variable hasta un mínimo
|
||||
void Player::decScoreMultiplier()
|
||||
{
|
||||
scoreMultiplier -= 0.1f;
|
||||
scoreMultiplier = std::max(scoreMultiplier, 1.0f);
|
||||
score_multiplier_ -= 0.1f;
|
||||
score_multiplier_ = std::max(score_multiplier_, 1.0f);
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool Player::isInvulnerable() const
|
||||
{
|
||||
return invulnerable;
|
||||
return invulnerable_;
|
||||
}
|
||||
|
||||
// Establece el valor del estado
|
||||
void Player::setInvulnerable(bool value)
|
||||
{
|
||||
invulnerable = value;
|
||||
invulnerableCounter = invulnerable ? PLAYER_INVULNERABLE_COUNTER : 0;
|
||||
invulnerable_ = value;
|
||||
invulnerable_counter_ = invulnerable_ ? PLAYER_INVULNERABLE_COUNTER : 0;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int Player::getInvulnerableCounter() const
|
||||
{
|
||||
return invulnerableCounter;
|
||||
return invulnerable_counter_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Player::setInvulnerableCounter(int value)
|
||||
{
|
||||
invulnerableCounter = value;
|
||||
invulnerable_counter_ = value;
|
||||
}
|
||||
|
||||
// Monitoriza el estado
|
||||
void Player::updateInvulnerable()
|
||||
{
|
||||
if (invulnerable)
|
||||
if (invulnerable_)
|
||||
{
|
||||
if (invulnerableCounter > 0)
|
||||
if (invulnerable_counter_ > 0)
|
||||
{
|
||||
invulnerableCounter--;
|
||||
invulnerableCounter % 8 > 3 ? playerSprite->getTexture()->setPalette(coffees) : playerSprite->getTexture()->setPalette(3);
|
||||
invulnerable_counter_--;
|
||||
invulnerable_counter_ % 8 > 3 ? player_sprite_->getTexture()->setPalette(coffees_) : player_sprite_->getTexture()->setPalette(3);
|
||||
}
|
||||
else
|
||||
{
|
||||
setInvulnerable(false);
|
||||
playerSprite->getTexture()->setPalette(coffees);
|
||||
player_sprite_->getTexture()->setPalette(coffees_);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -581,124 +597,123 @@ void Player::updateInvulnerable()
|
||||
// Obtiene el valor de la variable
|
||||
bool Player::isPowerUp() const
|
||||
{
|
||||
return powerUp;
|
||||
return power_up_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Player::setPowerUp()
|
||||
{
|
||||
powerUp = true;
|
||||
powerUpCounter = PLAYER_POWERUP_COUNTER;
|
||||
power_up_ = true;
|
||||
power_up_counter_ = PLAYER_POWERUP_COUNTER;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int Player::getPowerUpCounter() const
|
||||
{
|
||||
return powerUpCounter;
|
||||
return power_up_counter_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Player::setPowerUpCounter(int value)
|
||||
{
|
||||
powerUpCounter = value;
|
||||
power_up_counter_ = value;
|
||||
}
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void Player::updatePowerUpCounter()
|
||||
{
|
||||
if ((powerUpCounter > 0) && (powerUp))
|
||||
if ((power_up_counter_ > 0) && (power_up_))
|
||||
{
|
||||
powerUpCounter--;
|
||||
power_up_counter_--;
|
||||
}
|
||||
else
|
||||
{
|
||||
powerUp = false;
|
||||
// powerUpCounter = PLAYER_POWERUP_COUNTER;
|
||||
power_up_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool Player::hasExtraHit() const
|
||||
{
|
||||
return extraHit;
|
||||
return extra_hit_;
|
||||
}
|
||||
|
||||
// Concede un toque extra al jugador
|
||||
void Player::giveExtraHit()
|
||||
{
|
||||
extraHit = true;
|
||||
if (coffees < 2)
|
||||
extra_hit_ = true;
|
||||
if (coffees_ < 2)
|
||||
{
|
||||
coffees++;
|
||||
playerSprite->getTexture()->setPalette(coffees);
|
||||
coffees_++;
|
||||
player_sprite_->getTexture()->setPalette(coffees_);
|
||||
}
|
||||
}
|
||||
|
||||
// Quita el toque extra al jugador
|
||||
void Player::removeExtraHit()
|
||||
{
|
||||
if (coffees > 0)
|
||||
if (coffees_ > 0)
|
||||
{
|
||||
coffees--;
|
||||
coffees_--;
|
||||
setInvulnerable(true);
|
||||
playerSprite->getTexture()->setPalette(coffees);
|
||||
player_sprite_->getTexture()->setPalette(coffees_);
|
||||
}
|
||||
|
||||
extraHit = coffees == 0 ? false : true;
|
||||
extra_hit_ = coffees_ == 0 ? false : true;
|
||||
}
|
||||
|
||||
// Habilita la entrada de ordenes
|
||||
void Player::enableInput()
|
||||
{
|
||||
input = true;
|
||||
input_ = true;
|
||||
}
|
||||
|
||||
// Deshabilita la entrada de ordenes
|
||||
void Player::disableInput()
|
||||
{
|
||||
input = false;
|
||||
input_ = false;
|
||||
}
|
||||
|
||||
// Devuelve el número de cafes actuales
|
||||
int Player::getCoffees() const
|
||||
{
|
||||
return coffees;
|
||||
return coffees_;
|
||||
}
|
||||
|
||||
// Obtiene el circulo de colisión
|
||||
Circle &Player::getCollider()
|
||||
{
|
||||
return collider;
|
||||
return collider_;
|
||||
}
|
||||
|
||||
// Actualiza el circulo de colisión a la posición del jugador
|
||||
void Player::shiftColliders()
|
||||
{
|
||||
collider.x = int(posX + (width / 2));
|
||||
collider.y = int(posY + (height / 2));
|
||||
collider_.x = int(pos_x_ + (width_ / 2));
|
||||
collider_.y = int(pos_y_ + (height_ / 2));
|
||||
}
|
||||
|
||||
// Pone las texturas del jugador
|
||||
void Player::setPlayerTextures(std::vector<std::shared_ptr<Texture>> texture)
|
||||
{
|
||||
playerSprite->setTexture(texture[0]);
|
||||
powerSprite->setTexture(texture[1]);
|
||||
player_sprite_->setTexture(texture[0]);
|
||||
power_sprite_->setTexture(texture[1]);
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int Player::getContinueCounter() const
|
||||
{
|
||||
return continueCounter;
|
||||
return continue_counter_;
|
||||
}
|
||||
|
||||
// Actualiza el contador de continue
|
||||
void Player::updateContinueCounter()
|
||||
{
|
||||
if (statusPlaying == PlayerStatus::CONTINUE)
|
||||
if (status_playing_ == PlayerStatus::CONTINUE)
|
||||
{
|
||||
const Uint32 ticksSpeed = 1000;
|
||||
constexpr Uint32 ticks_speed = 1000;
|
||||
|
||||
if (SDL_GetTicks() - continueTicks > ticksSpeed)
|
||||
if (SDL_GetTicks() - continue_ticks_ > ticks_speed)
|
||||
{
|
||||
decContinueCounter();
|
||||
}
|
||||
@@ -708,21 +723,21 @@ void Player::updateContinueCounter()
|
||||
// Le asigna un panel en el marcador al jugador
|
||||
void Player::setScoreBoardPanel(int panel)
|
||||
{
|
||||
scoreBoardPanel = panel;
|
||||
scoreboard_panel_ = panel;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int Player::getScoreBoardPanel() const
|
||||
{
|
||||
return scoreBoardPanel;
|
||||
return scoreboard_panel_;
|
||||
}
|
||||
|
||||
// Decrementa el contador de continuar
|
||||
void Player::decContinueCounter()
|
||||
{
|
||||
continueTicks = SDL_GetTicks();
|
||||
continueCounter--;
|
||||
if (continueCounter < 0)
|
||||
continue_ticks_ = SDL_GetTicks();
|
||||
continue_counter_--;
|
||||
if (continue_counter_ < 0)
|
||||
{
|
||||
setStatusPlaying(PlayerStatus::GAME_OVER);
|
||||
}
|
||||
@@ -731,33 +746,33 @@ void Player::decContinueCounter()
|
||||
// Establece el nombre del jugador
|
||||
void Player::setName(std::string name)
|
||||
{
|
||||
this->name = name;
|
||||
name_ = name;
|
||||
}
|
||||
|
||||
// Establece el nombre del jugador para la tabla de mejores puntuaciones
|
||||
void Player::setRecordName(std::string recordName)
|
||||
void Player::setRecordName(std::string record_name)
|
||||
{
|
||||
this->recordName = recordName.substr(0, 8);
|
||||
record_name_ = record_name.substr(0, 8);
|
||||
}
|
||||
|
||||
// Obtiene el nombre del jugador
|
||||
std::string Player::getName() const
|
||||
{
|
||||
return name;
|
||||
return name_;
|
||||
}
|
||||
|
||||
// Obtiene el nombre del jugador para la tabla de mejores puntuaciones
|
||||
std::string Player::getRecordName() const
|
||||
{
|
||||
return recordName;
|
||||
return record_name_;
|
||||
}
|
||||
|
||||
// Obtiene la posici´´on que se está editando del nombre del jugador para la tabla de mejores puntuaciones
|
||||
int Player::getRecordNamePos() const
|
||||
{
|
||||
if (enterName)
|
||||
if (enter_name_)
|
||||
{
|
||||
return enterName->getPos();
|
||||
return enter_name_->getPos();
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -766,19 +781,19 @@ int Player::getRecordNamePos() const
|
||||
// Establece el mando que usará para ser controlado
|
||||
void Player::setController(int index)
|
||||
{
|
||||
controllerIndex = index;
|
||||
controller_index_ = index;
|
||||
}
|
||||
|
||||
// Obtiene el mando que usa para ser controlado
|
||||
int Player::getController() const
|
||||
{
|
||||
return controllerIndex;
|
||||
return controller_index_;
|
||||
}
|
||||
|
||||
// Obtiene el "id" del jugador
|
||||
int Player::getId() const
|
||||
{
|
||||
return id;
|
||||
return id_;
|
||||
}
|
||||
|
||||
// Indica si el jugador se puede dibujar
|
||||
@@ -790,5 +805,5 @@ bool Player::isRenderable() const
|
||||
// Comprueba si la puntuación entra en la tabla de mejores puntuaciones
|
||||
bool Player::IsEligibleForHighScore()
|
||||
{
|
||||
return score > options.game.hi_score_table.back().score;
|
||||
return score_ > options.game.hi_score_table.back().score;
|
||||
}
|
||||
@@ -41,44 +41,44 @@ class Player
|
||||
{
|
||||
private:
|
||||
// Objetos y punteros
|
||||
std::unique_ptr<AnimatedSprite> playerSprite; // Sprite para dibujar el jugador
|
||||
std::unique_ptr<AnimatedSprite> powerSprite; // Sprite para dibujar el aura del jugador con el poder a tope
|
||||
std::unique_ptr<EnterName> enterName; // Clase utilizada para introducir el nombre
|
||||
SDL_Rect *playArea; // Rectangulo con la zona de juego
|
||||
std::unique_ptr<AnimatedSprite> player_sprite_; // Sprite para dibujar el jugador
|
||||
std::unique_ptr<AnimatedSprite> power_sprite_; // Sprite para dibujar el aura del jugador con el poder a tope
|
||||
std::unique_ptr<EnterName> enter_name_; // Clase utilizada para introducir el nombre
|
||||
SDL_Rect *play_area_; // Rectangulo con la zona de juego
|
||||
|
||||
// Variables
|
||||
int id; // Numero de identificación para el jugador
|
||||
float posX; // Posicion en el eje X
|
||||
int posY; // Posicion en el eje Y
|
||||
float defaultPosX; // Posición inicial para el jugador
|
||||
int defaultPosY; // Posición inicial para el jugador
|
||||
int width; // Anchura
|
||||
int height; // Altura
|
||||
float velX; // Cantidad de pixeles a desplazarse en el eje X
|
||||
int velY; // Cantidad de pixeles a desplazarse en el eje Y
|
||||
float baseSpeed; // Velocidad base del jugador
|
||||
int cooldown; // Contador durante el cual no puede disparar
|
||||
int score; // Puntos del jugador
|
||||
float scoreMultiplier; // Multiplicador de puntos
|
||||
PlayerStatus statusWalking; // Estado del jugador al moverse
|
||||
PlayerStatus statusFiring; // Estado del jugador al disparar
|
||||
PlayerStatus statusPlaying; // Estado del jugador en el juego
|
||||
bool invulnerable; // Indica si el jugador es invulnerable
|
||||
int invulnerableCounter; // Contador para la invulnerabilidad
|
||||
bool extraHit; // Indica si el jugador tiene un toque extra
|
||||
int coffees; // Indica cuantos cafes lleva acumulados
|
||||
bool powerUp; // Indica si el jugador tiene activo el modo PowerUp
|
||||
int powerUpCounter; // Temporizador para el modo PowerUp
|
||||
int powerUpDespX; // Desplazamiento del sprite de PowerUp respecto al sprite del jugador
|
||||
bool input; // Indica si puede recibir ordenes de entrada
|
||||
Circle collider; // Circulo de colisión del jugador
|
||||
int continueCounter; // Contador para poder continuar
|
||||
Uint32 continueTicks; // Variable para poder cambiar el contador de continue en función del tiempo
|
||||
int scoreBoardPanel; // Panel del marcador asociado al jugador
|
||||
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
|
||||
int id_; // Numero de identificación para el jugador
|
||||
float pos_x_; // Posicion en el eje X
|
||||
int pos_y_; // Posicion en el eje Y
|
||||
float default_pos_x_; // Posición inicial para el jugador
|
||||
int default_pos_y_; // Posición inicial para el jugador
|
||||
int width_; // Anchura
|
||||
int height_; // Altura
|
||||
float vel_x_; // Cantidad de pixeles a desplazarse en el eje X
|
||||
int vel_y_; // Cantidad de pixeles a desplazarse en el eje Y
|
||||
float base_speed_; // Velocidad base del jugador
|
||||
int cooldown_; // Contador durante el cual no puede disparar
|
||||
int score_; // Puntos del jugador
|
||||
float score_multiplier_; // Multiplicador de puntos
|
||||
PlayerStatus status_walking_; // Estado del jugador al moverse
|
||||
PlayerStatus status_firing_; // Estado del jugador al disparar
|
||||
PlayerStatus status_playing_; // Estado del jugador en el juego
|
||||
bool invulnerable_; // Indica si el jugador es invulnerable
|
||||
int invulnerable_counter_; // Contador para la invulnerabilidad
|
||||
bool extra_hit_; // Indica si el jugador tiene un toque extra
|
||||
int coffees_; // Indica cuantos cafes lleva acumulados
|
||||
bool power_up_; // Indica si el jugador tiene activo el modo PowerUp
|
||||
int power_up_counter_; // Temporizador para el modo PowerUp
|
||||
int power_up_desp_x_; // Desplazamiento del sprite de PowerUp respecto al sprite del jugador
|
||||
bool input_; // Indica si puede recibir ordenes de entrada
|
||||
Circle collider_; // Circulo de colisión del jugador
|
||||
int continue_counter_; // Contador para poder continuar
|
||||
Uint32 continue_ticks_; // Variable para poder cambiar el contador de continue en función del tiempo
|
||||
int scoreboard_panel_; // Panel del marcador asociado al jugador
|
||||
std::string name_; // Nombre del jugador
|
||||
std::string record_name_; // Nombre del jugador para l atabla de mejores puntuaciones
|
||||
int controller_index_; // 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();
|
||||
@@ -103,7 +103,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Player(int id, float x, int y, bool demo, SDL_Rect *playArea, std::vector<std::shared_ptr<Texture>> texture, std::vector<std::vector<std::string> *> animations);
|
||||
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);
|
||||
|
||||
// Destructor
|
||||
~Player() = default;
|
||||
@@ -274,7 +274,7 @@ public:
|
||||
void setName(std::string name);
|
||||
|
||||
// Establece el nombre del jugador para la tabla de mejores puntuaciones
|
||||
void setRecordName(std::string recordName);
|
||||
void setRecordName(std::string record_name);
|
||||
|
||||
// Obtiene el nombre del jugador
|
||||
std::string getName() const;
|
||||
|
||||
Reference in New Issue
Block a user