time-based: Player::setAnimation(dt_s) propaga dt_s als animate() dels sprites (corregeix animacio del jugador a 144Hz)

This commit is contained in:
2026-05-19 17:52:33 +02:00
parent 36d50ade82
commit 54ef4c85eb
2 changed files with 41 additions and 2 deletions
+39 -1
View File
@@ -280,6 +280,44 @@ void Player::setAnimation() {
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;
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;
legs_sprite_->setCurrentAnimation(WALKING);
legs_sprite_->setFlip(FLIP_WALK);
if (status_firing_ == STATUS_FIRING_NO) {
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 {
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);
}
legs_sprite_->animate(dt_s);
body_sprite_->animate(dt_s);
head_sprite_->animate(dt_s);
fire_sprite_->animate(dt_s);
fire_sprite_->setFlip(FLIP_WALK);
}
// Obtiene el valor de la variable
auto Player::getPosX() const -> int {
return int(pos_x_);
@@ -357,7 +395,7 @@ void Player::update() {
// Actualiza al jugador (time-based)
void Player::update(float dt_s) {
move(dt_s);
setAnimation();
setAnimation(dt_s);
shiftColliders();
updateCooldown(dt_s);
updatePowerUpCounter(dt_s);