turn and jump
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 672 B After Width: | Height: | Size: 828 B |
@@ -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]
|
||||
|
||||
Binary file not shown.
@@ -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;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user