turn and jump
This commit is contained in:
@@ -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<AnimatedSprite>(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;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
||||
Reference in New Issue
Block a user