From 8cdcee84349712079cb461512ce230bb89fb72a2 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Sat, 15 Nov 2025 21:12:08 -0500 Subject: dungeon: fix wonky movement --- dungeon/src/entity.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/dungeon/src/entity.rs b/dungeon/src/entity.rs index ced7656..b14f815 100644 --- a/dungeon/src/entity.rs +++ b/dungeon/src/entity.rs @@ -326,11 +326,15 @@ impl Updater<'_> { fn update_enemy_ai(&mut self, entity: &mut Entity, ai: &mut EnemyMoveState) { use EnemyMoveState as State; + // get the position in front + let front_pos = entity.pos.step(entity.dir).unwrap_or(entity.pos); + // check if player is in range if !matches!(ai, State::Attack { .. }) - && let Some(m_state) = State::attack(entity.pos, self.player_pos, self.floor) + && let Some(m_state) = State::attack(front_pos, self.player_pos, self.floor) { *ai = m_state; + entity.moving_to = Some(front_pos); return; } @@ -342,6 +346,7 @@ impl Updater<'_> { } *ai = State::roam(entity.pos, self.floor, self.rng); + entity.moving_to = Some(front_pos); } State::Roam(moves) => { if moves.is_empty() { @@ -355,8 +360,9 @@ impl Updater<'_> { } State::Attack(moves, old_player_pos) => { if *old_player_pos != self.player_pos { - *ai = State::attack(entity.pos, self.player_pos, self.floor) + *ai = State::attack(front_pos, self.player_pos, self.floor) .unwrap_or_default(); + entity.moving_to = Some(front_pos); return; } *old_player_pos = self.player_pos; -- cgit v1.2.3-freya