diff --git a/data/player/player.gif b/data/player/player.gif index 5ec8ae3..0b80dbb 100644 Binary files a/data/player/player.gif and b/data/player/player.gif differ diff --git a/data/player/player.yaml b/data/player/player.yaml index e209022..dd72e68 100644 --- a/data/player/player.yaml +++ b/data/player/player.yaml @@ -7,14 +7,29 @@ animations: - name: stand speed: 0 loop: -1 - frames: [0] + frames: [1] - - name: default + - name: walk speed: 0.07 loop: 0 - frames: [1, 2, 3, 0] + frames: [2, 3, 4, 1] + + - name: turn_walk + speed: 0.07 + loop: 1 + frames: [0, 2, 3, 4, 1] - name: jump speed: 0 loop: -1 - frames: [4] + frames: [6] + + - name: jump_peak + speed: 0 + loop: -1 + frames: [5] + + - name: turn + speed: 0 + loop: -1 + frames: [0] diff --git a/data/sound/jump.wav b/data/sound/jump.wav index 9d0e2e9..743d129 100644 Binary files a/data/sound/jump.wav and b/data/sound/jump.wav differ diff --git a/source/game/entities/player.cpp b/source/game/entities/player.cpp index 43b0ef4..3df6f6e 100644 --- a/source/game/entities/player.cpp +++ b/source/game/entities/player.cpp @@ -135,6 +135,16 @@ void Player::updateVelocity(float delta_time) { break; } + // Detectar cambio de dirección en el suelo + if (state_ != State::ON_AIR && target != 0.0F) { + Direction new_facing = (target > 0.0F) ? Direction::RIGHT : Direction::LEFT; + if (new_facing != facing_) { + facing_ = new_facing; + turning_ = true; + sprite_->resetAnimation(); + } + } + // Orientación del sprite if (target > 0.0F) { sprite_->setFlip(Flip::RIGHT); @@ -533,11 +543,18 @@ void Player::placeSprite() { void Player::animate(float delta_time) { // NOLINT(readability-make-member-function-const) if (state_ == State::ON_AIR) { - sprite_->setCurrentAnimation("jump"); + turning_ = false; + const bool NEAR_PEAK = vy_ > JUMP_VELOCITY * 0.5F && vy_ < -JUMP_VELOCITY * 0.5F; + sprite_->setCurrentAnimation(NEAR_PEAK ? "jump_peak" : "jump"); } else if (vx_ != 0) { - sprite_->setCurrentAnimation("default"); + if (turning_) { + sprite_->setCurrentAnimation("turn_walk"); + } else { + sprite_->setCurrentAnimation("walk"); + } sprite_->update(delta_time); } else { + turning_ = false; sprite_->setCurrentAnimation("stand"); } } @@ -581,7 +598,7 @@ void Player::initSprite(const std::string& animations_path) { // NOLINT(readabi sprite_ = std::make_unique(animation_data); sprite_->setWidth(WIDTH); sprite_->setHeight(HEIGHT); - sprite_->setCurrentAnimation("default"); + sprite_->setCurrentAnimation("walk"); } void Player::initSounds() { // NOLINT(readability-convert-member-functions-to-static) @@ -597,6 +614,7 @@ void Player::applySpawnValues(const SpawnData& spawn) { last_grounded_position_ = spawn.last_grounded_position; state_ = spawn.state; sprite_->setFlip(spawn.flip); + facing_ = (spawn.flip == Flip::LEFT) ? Direction::LEFT : Direction::RIGHT; } // ============================================================================ diff --git a/source/game/entities/player.hpp b/source/game/entities/player.hpp index cac4c13..2b1f3b9 100644 --- a/source/game/entities/player.hpp +++ b/source/game/entities/player.hpp @@ -128,6 +128,8 @@ class Player { bool is_alive_ = true; bool is_paused_ = false; bool ignore_input_ = false; + bool turning_ = false; + Direction facing_ = Direction::RIGHT; Room::Border border_ = Room::Border::TOP; int last_grounded_position_ = 0;