1
0
Fork 0
mirror of https://github.com/doukutsu-rs/doukutsu-rs synced 2025-03-28 04:49:20 +00:00

fix weapon being desynchronized with player animation

This commit is contained in:
Alula 2021-03-23 14:28:51 +01:00
parent 8973da2840
commit f5751f6651
No known key found for this signature in database
GPG key ID: 3E00485503A1D8BA
2 changed files with 21 additions and 20 deletions

View file

@ -4,7 +4,7 @@ use num_derive::FromPrimitive;
use num_traits::clamp;
use crate::caret::CaretType;
use crate::common::{interpolate_fix9_scale, Condition, Direction, Equipment, Flag, Rect};
use crate::common::{Condition, Direction, Equipment, Flag, interpolate_fix9_scale, Rect};
use crate::entity::GameEntity;
use crate::frame::Frame;
use crate::framework::context::Context;
@ -13,8 +13,8 @@ use crate::input::dummy_player_controller::DummyPlayerController;
use crate::input::player_controller::PlayerController;
use crate::npc::list::NPCList;
use crate::npc::NPC;
use crate::player::skin::basic::BasicPlayerSkin;
use crate::player::skin::{PlayerAnimationState, PlayerAppearanceState, PlayerSkin};
use crate::player::skin::basic::BasicPlayerSkin;
use crate::rng::RNG;
use crate::shared_game_state::SharedGameState;
@ -550,7 +550,8 @@ impl Player {
if self.flags.hit_bottom_wall() {
if self.cond.interacted() {
self.skin.set_state(PlayerAnimationState::Examining);
self.anim_num = 11;
self.anim_num = 0;
self.anim_counter = 0;
} else if state.control_flags.control_enabled()
&& self.controller.move_up()
&& (self.controller.move_left() || self.controller.move_right())
@ -597,7 +598,8 @@ impl Player {
self.cond.set_fallen(false);
self.skin.set_state(PlayerAnimationState::LookingUp);
self.anim_num = 5;
self.anim_num = 0;
self.anim_counter = 0;
} else {
if self.cond.fallen() {
state.sound_manager.play_sfx(24);
@ -606,20 +608,24 @@ impl Player {
self.cond.set_fallen(false);
self.skin.set_state(PlayerAnimationState::Idle);
self.anim_num = 0;
self.anim_counter = 0;
}
} else if self.controller.look_up() {
self.skin.set_state(PlayerAnimationState::FallingLookingUp);
self.anim_num = 6;
self.anim_num = 0;
self.anim_counter = 0;
} else if self.controller.look_down() {
self.skin.set_state(PlayerAnimationState::FallingLookingDown);
self.anim_num = 10;
self.anim_num = 0;
self.anim_counter = 0;
} else {
self.skin.set_state(if self.vel_y > 0 {
PlayerAnimationState::Jumping
} else {
PlayerAnimationState::Falling
});
self.anim_num = if self.vel_y > 0 { 1 } else { 3 };
self.anim_num = 0;
self.anim_counter = 0;
}
self.weapon_offset_y = 0;
@ -628,16 +634,9 @@ impl Player {
self.weapon_rect.right = self.weapon_rect.left + 24;
self.weapon_rect.bottom = self.weapon_rect.top + 16;
match self.direction {
Direction::Left => {
self.anim_rect = state.constants.my_char.frames_left[self.anim_num as usize];
}
Direction::Right => {
self.weapon_rect.top += 16;
self.weapon_rect.bottom += 16;
self.anim_rect = state.constants.my_char.frames_right[self.anim_num as usize];
}
_ => {}
if self.direction == Direction::Right {
self.weapon_rect.top += 16;
self.weapon_rect.bottom += 16;
}
if self.up {

View file

@ -31,12 +31,12 @@ impl PlayerSkin for BasicPlayerSkin {
PlayerAnimationState::Walking => {
const WALK_INDEXES: [u16; 4] = [1, 0, 2, 0];
WALK_INDEXES[(self.tick as usize / 4) % 4]
WALK_INDEXES[(tick as usize / 5) % 4]
}
PlayerAnimationState::WalkingUp => {
const WALK_UP_INDEXES: [u16; 4] = [4, 3, 5, 3];
WALK_UP_INDEXES[(self.tick as usize / 4) % 4]
WALK_UP_INDEXES[(tick as usize / 5) % 4]
}
PlayerAnimationState::LookingUp => 3,
PlayerAnimationState::Examining => 7,
@ -64,7 +64,9 @@ impl PlayerSkin for BasicPlayerSkin {
}
fn tick(&mut self) {
self.tick = self.tick.wrapping_add(1);
if self.state == PlayerAnimationState::Walking || self.state == PlayerAnimationState::WalkingUp {
self.tick = self.tick.wrapping_add(1);
}
}
fn set_state(&mut self, state: PlayerAnimationState) {