summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-11-15 21:12:08 -0500
committerFreya Murphy <freya@freyacat.org>2025-11-15 21:12:08 -0500
commit8cdcee84349712079cb461512ce230bb89fb72a2 (patch)
tree389ab0430a6f2cc97a1315e33a70487b80a9db42
parentzombie texture (diff)
downloadDungeonCrawl-8cdcee84349712079cb461512ce230bb89fb72a2.tar.gz
DungeonCrawl-8cdcee84349712079cb461512ce230bb89fb72a2.tar.bz2
DungeonCrawl-8cdcee84349712079cb461512ce230bb89fb72a2.zip
dungeon: fix wonky movement
-rw-r--r--dungeon/src/entity.rs10
1 files 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;