cleanup time-based: elimina entitats frame-based (Bullet/Item/Player/Balloon), VELX en px/s, Game::popBalloon amb vel en px/s
This commit is contained in:
@@ -67,12 +67,9 @@ void Player::init() {
|
||||
shiftColliders();
|
||||
|
||||
// Establece la velocidad inicial
|
||||
vel_x_ = 0;
|
||||
vel_y_ = 0;
|
||||
vel_x_s_ = 0.0F;
|
||||
|
||||
// Establece la velocidad base
|
||||
base_speed_ = 1.5;
|
||||
base_speed_s_ = BASE_SPEED_PX_PER_S;
|
||||
|
||||
// Establece la puntuación inicial
|
||||
@@ -105,13 +102,11 @@ void Player::init() {
|
||||
void Player::setInput(Input::Action input) {
|
||||
switch (input) {
|
||||
case Input::Action::LEFT:
|
||||
vel_x_ = -base_speed_;
|
||||
vel_x_s_ = -base_speed_s_;
|
||||
setWalkingStatus(STATUS_WALKING_LEFT);
|
||||
break;
|
||||
|
||||
case Input::Action::RIGHT:
|
||||
vel_x_ = base_speed_;
|
||||
vel_x_s_ = base_speed_s_;
|
||||
setWalkingStatus(STATUS_WALKING_RIGHT);
|
||||
break;
|
||||
@@ -129,7 +124,6 @@ void Player::setInput(Input::Action input) {
|
||||
break;
|
||||
|
||||
default:
|
||||
vel_x_ = 0;
|
||||
vel_x_s_ = 0.0F;
|
||||
setWalkingStatus(STATUS_WALKING_STOP);
|
||||
break;
|
||||
@@ -137,43 +131,6 @@ void Player::setInput(Input::Action input) {
|
||||
}
|
||||
|
||||
// Mueve el jugador a la posición y animación que le corresponde
|
||||
void Player::move() {
|
||||
if (isAlive()) {
|
||||
// Mueve el jugador a derecha o izquierda
|
||||
pos_x_ += vel_x_;
|
||||
|
||||
// Si el jugador abandona el area de juego por los laterales
|
||||
if ((pos_x_ < PLAY_AREA_LEFT - 5) || (pos_x_ + width_ > PLAY_AREA_RIGHT + 5)) { // Restaura su posición
|
||||
pos_x_ -= vel_x_;
|
||||
}
|
||||
|
||||
// Actualiza la posición del sprite
|
||||
legs_sprite_->setPosX(getPosX());
|
||||
legs_sprite_->setPosY(pos_y_);
|
||||
|
||||
body_sprite_->setPosX(getPosX());
|
||||
body_sprite_->setPosY(pos_y_);
|
||||
|
||||
head_sprite_->setPosX(getPosX());
|
||||
head_sprite_->setPosY(pos_y_);
|
||||
|
||||
fire_sprite_->setPosX(getPosX() - 2);
|
||||
fire_sprite_->setPosY(pos_y_ - 8);
|
||||
} else {
|
||||
death_sprite_->update();
|
||||
|
||||
// Si el cadaver abandona el area de juego por los laterales
|
||||
if ((death_sprite_->getPosX() < PLAY_AREA_LEFT) || (death_sprite_->getPosX() + width_ > PLAY_AREA_RIGHT)) { // Restaura su posición
|
||||
const float VX = death_sprite_->getVelX();
|
||||
death_sprite_->setPosX(death_sprite_->getPosX() - VX);
|
||||
|
||||
// Rebota
|
||||
death_sprite_->setVelX(-VX);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Mueve el jugador a la posición y animación que le corresponde (time-based)
|
||||
void Player::move(float dt_s) {
|
||||
if (isAlive()) {
|
||||
pos_x_ += vel_x_s_ * dt_s;
|
||||
@@ -240,47 +197,6 @@ void Player::setFiringStatus(Uint8 status) {
|
||||
}
|
||||
|
||||
// Establece la animación correspondiente al estado
|
||||
void Player::setAnimation() {
|
||||
// Crea cadenas de texto para componer el nombre de la animación
|
||||
std::string body_coffees;
|
||||
std::string head_coffees;
|
||||
if (coffees_ > 0) {
|
||||
body_coffees = coffees_ == 1 ? "_1C" : "_2C";
|
||||
head_coffees = "_1C";
|
||||
}
|
||||
|
||||
const std::string POWER_UP = power_up_ ? "_pwr" : "";
|
||||
const std::string WALKING = status_walking_ == STATUS_WALKING_STOP ? "stand" : "walk";
|
||||
const std::string FIRING = status_firing_ == STATUS_FIRING_UP ? "centershoot" : "sideshoot";
|
||||
|
||||
const SDL_FlipMode FLIP_WALK = status_walking_ == STATUS_WALKING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||
const SDL_FlipMode FLIP_FIRE = status_firing_ == STATUS_FIRING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||
|
||||
// Establece la animación a partir de las cadenas
|
||||
legs_sprite_->setCurrentAnimation(WALKING);
|
||||
legs_sprite_->setFlip(FLIP_WALK);
|
||||
if (status_firing_ == STATUS_FIRING_NO) { // No esta disparando
|
||||
body_sprite_->setCurrentAnimation(WALKING + body_coffees + POWER_UP);
|
||||
body_sprite_->setFlip(FLIP_WALK);
|
||||
head_sprite_->setCurrentAnimation(WALKING + head_coffees + POWER_UP);
|
||||
head_sprite_->setFlip(FLIP_WALK);
|
||||
} else { // Está disparando
|
||||
body_sprite_->setCurrentAnimation(FIRING + body_coffees + POWER_UP);
|
||||
body_sprite_->setFlip(FLIP_FIRE);
|
||||
head_sprite_->setCurrentAnimation(FIRING + head_coffees + POWER_UP);
|
||||
head_sprite_->setFlip(FLIP_FIRE);
|
||||
}
|
||||
|
||||
// Actualiza las animaciones de los sprites
|
||||
legs_sprite_->animate();
|
||||
body_sprite_->animate();
|
||||
head_sprite_->animate();
|
||||
|
||||
fire_sprite_->animate();
|
||||
fire_sprite_->setFlip(FLIP_WALK);
|
||||
}
|
||||
|
||||
// Establece la animación correspondiente al estado (time-based)
|
||||
void Player::setAnimation(float dt_s) {
|
||||
std::string body_coffees;
|
||||
std::string head_coffees;
|
||||
@@ -356,19 +272,7 @@ void Player::setFireCooldownS(float seconds) {
|
||||
cooldown_ = static_cast<int>(seconds * 60.0F);
|
||||
}
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void Player::updateCooldown() {
|
||||
if (cooldown_ > 0) {
|
||||
cooldown_--;
|
||||
if (power_up_) {
|
||||
cooldown_--;
|
||||
}
|
||||
} else {
|
||||
setFiringStatus(STATUS_FIRING_NO);
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el cooldown (time-based). Quan està en mode PowerUp, el cooldown
|
||||
// Actualiza el cooldown. Quan està en mode PowerUp, el cooldown
|
||||
// es consumeix el doble de ràpid (equivalent a decrementar 2 frames per tick).
|
||||
void Player::updateCooldown(float dt_s) {
|
||||
if (cooldown_s_ > 0.0F) {
|
||||
@@ -381,18 +285,6 @@ void Player::updateCooldown(float dt_s) {
|
||||
}
|
||||
|
||||
// Actualiza al jugador a su posicion, animación y controla los contadores
|
||||
void Player::update() {
|
||||
move();
|
||||
setAnimation();
|
||||
shiftColliders();
|
||||
updateCooldown();
|
||||
updatePowerUpCounter();
|
||||
updateInvulnerableCounter();
|
||||
updateDeathCounter();
|
||||
updatePowerUpHeadOffset();
|
||||
}
|
||||
|
||||
// Actualiza al jugador (time-based)
|
||||
void Player::update(float dt_s) {
|
||||
move(dt_s);
|
||||
setAnimation(dt_s);
|
||||
@@ -491,20 +383,8 @@ void Player::setInvulnerableCounter(Uint16 value) {
|
||||
invulnerable_counter_s_ = static_cast<float>(value) / 60.0F;
|
||||
}
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void Player::updateInvulnerableCounter() {
|
||||
if (invulnerable_) {
|
||||
if (invulnerable_counter_ > 0) {
|
||||
invulnerable_counter_--;
|
||||
} else {
|
||||
invulnerable_ = false;
|
||||
invulnerable_counter_ = INVULNERABLE_COUNTER;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el contador d'invulnerabilitat (time-based). Manté el counter
|
||||
// enter sincronitzat perquè render() segueixi parpellejant igual.
|
||||
// Actualiza el contador d'invulnerabilitat. Manté el counter enter
|
||||
// sincronitzat perquè render() segueixi parpellejant igual.
|
||||
void Player::updateInvulnerableCounter(float dt_s) {
|
||||
if (invulnerable_) {
|
||||
if (invulnerable_counter_s_ > 0.0F) {
|
||||
@@ -518,16 +398,7 @@ void Player::updateInvulnerableCounter(float dt_s) {
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void Player::updateDeathCounter() {
|
||||
if (!alive_) {
|
||||
if (death_counter_ > 0) {
|
||||
death_counter_--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el comptador de mort (time-based)
|
||||
// Actualiza el comptador de mort
|
||||
void Player::updateDeathCounter(float dt_s) {
|
||||
if (!alive_) {
|
||||
if (death_counter_s_ > 0.0F) {
|
||||
@@ -558,17 +429,7 @@ void Player::setPowerUpCounter(Uint16 value) {
|
||||
power_up_counter_s_ = static_cast<float>(value) / 60.0F;
|
||||
}
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void Player::updatePowerUpCounter() {
|
||||
if ((power_up_counter_ > 0) && (power_up_)) {
|
||||
power_up_counter_--;
|
||||
} else {
|
||||
power_up_ = false;
|
||||
power_up_counter_ = POWERUP_COUNTER;
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el comptador de PowerUp (time-based)
|
||||
// Actualiza el comptador de PowerUp
|
||||
void Player::updatePowerUpCounter(float dt_s) {
|
||||
if ((power_up_counter_s_ > 0.0F) && (power_up_)) {
|
||||
power_up_counter_s_ = std::max(0.0F, power_up_counter_s_ - dt_s);
|
||||
@@ -642,26 +503,8 @@ auto Player::getDeathCounter() const -> Uint16 {
|
||||
return death_counter_;
|
||||
}
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void Player::updatePowerUpHeadOffset() {
|
||||
if (!power_up_) {
|
||||
// powerUpHeadOffset = 0;
|
||||
} else {
|
||||
// powerUpHeadOffset = 96;
|
||||
if (power_up_counter_ < 300) {
|
||||
if (power_up_counter_ % 10 > 4) {
|
||||
// powerUpHeadOffset = 96;
|
||||
fire_sprite_->setEnabled(false);
|
||||
} else {
|
||||
// powerUpHeadOffset = 0;
|
||||
fire_sprite_->setEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza l'offset (time-based). dt_s no s'usa directament: el blink final
|
||||
// depèn de power_up_counter_s_ que ja s'està actualitzant a updatePowerUpCounter.
|
||||
// Actualiza l'offset. dt_s no s'usa directament: el blink final depèn de
|
||||
// power_up_counter_s_ que ja s'està actualitzant a updatePowerUpCounter.
|
||||
void Player::updatePowerUpHeadOffset([[maybe_unused]] float dt_s) {
|
||||
if (!power_up_) { return; }
|
||||
if (power_up_counter_s_ < POWERUP_BLINK_THRESHOLD_S) {
|
||||
|
||||
Reference in New Issue
Block a user