From 2f7c963c8ffb3bceef08f760cdfac758ddae3758 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Sun, 9 Nov 2025 20:53:36 -0500 Subject: dungeon: always use seeded rand, other minor refactoring --- dungeon/src/entity.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'dungeon/src/entity.rs') diff --git a/dungeon/src/entity.rs b/dungeon/src/entity.rs index badb43c..931947c 100644 --- a/dungeon/src/entity.rs +++ b/dungeon/src/entity.rs @@ -1,5 +1,7 @@ //! The `entity` module contains structures of all entities including players and enimies. +use rand::Rng; + use crate::{Direction, FPos, Floor, Pos, astar, const_pos}; /// `PLAYER_FULL_HEALTH` is the starting health of the player entity @@ -70,12 +72,13 @@ impl EnemyMoveState { None } - pub fn new_roam(starting_pos: Pos, floor: &Floor) -> Self { - let mut rand_dir = Direction::get_random_dir(); - let mut rand_tiles = rand::random_range(MIN_ROAM_DIST..=MAX_ROAM_DIST); + pub fn new_roam(starting_pos: Pos, floor: &mut Floor) -> Self { let mut loop_index = 0; loop { - if let Some(p) = starting_pos.step_by(rand_dir, rand_tiles) { + let dir = Direction::random(floor.rand()); + let dist = floor.rand().random_range(MIN_ROAM_DIST..=MIN_ROAM_DIST); + + if let Some(p) = starting_pos.step_by(dir, dist) { if !floor.get(p).is_wall() { if let Some(data) = astar::astar(starting_pos, p, floor) { let mut path = data.0; @@ -85,9 +88,6 @@ impl EnemyMoveState { } } - rand_dir = Direction::get_random_dir(); - rand_tiles = rand::random_range(MIN_ROAM_DIST..=MAX_ROAM_DIST); - // Safety check loop_index += 1; if loop_index >= 100 { @@ -186,7 +186,7 @@ impl Entity { } } - pub fn handle_movement(&mut self, player_pos: Pos, floor: &Floor, delta_time: f32) { + pub fn handle_movement(&mut self, player_pos: Pos, floor: &mut Floor, delta_time: f32) { match &self.kind { EntityKind::Zombie(move_state) => { self.zombie_movement(move_state.clone(), player_pos, delta_time, floor); @@ -201,7 +201,7 @@ impl Entity { move_state: EnemyMoveState, player_pos: Pos, delta_time: f32, - floor: &Floor, + floor: &mut Floor, ) { // Check if player is in range if !matches!(move_state, EnemyMoveState::Attack { .. }) -- cgit v1.2.3-freya From 4fa6d40b91d73dd283d0369d06f5c2320b835be4 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Sun, 9 Nov 2025 21:13:50 -0500 Subject: oops --- dungeon/src/entity.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dungeon/src/entity.rs') diff --git a/dungeon/src/entity.rs b/dungeon/src/entity.rs index 931947c..c84fc42 100644 --- a/dungeon/src/entity.rs +++ b/dungeon/src/entity.rs @@ -76,7 +76,7 @@ impl EnemyMoveState { let mut loop_index = 0; loop { let dir = Direction::random(floor.rand()); - let dist = floor.rand().random_range(MIN_ROAM_DIST..=MIN_ROAM_DIST); + let dist = floor.rand().random_range(MIN_ROAM_DIST..=MAX_ROAM_DIST); if let Some(p) = starting_pos.step_by(dir, dist) { if !floor.get(p).is_wall() { -- cgit v1.2.3-freya