diff options
Diffstat (limited to 'dungeon/src/entity.rs')
| -rw-r--r-- | dungeon/src/entity.rs | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/dungeon/src/entity.rs b/dungeon/src/entity.rs index de21c28..e3b8fbd 100644 --- a/dungeon/src/entity.rs +++ b/dungeon/src/entity.rs @@ -1,6 +1,6 @@ //! The `entity` module contains structures of all entities including players and enimies. -use rand::Rng; +use rand::{Rng, rngs::SmallRng}; use crate::{Direction, FPos, Floor, Pos, astar, const_pos}; @@ -90,11 +90,11 @@ impl EnemyMoveState { /// /// Will randomly pick a direction and number of tiles within roaming range to move. /// If an invalid tile is selected 50 times in a row, `EnemyMoveState::Idle` is returned instead. - pub fn new_roam(starting_pos: Pos, floor: &mut Floor) -> Self { + pub fn new_roam(starting_pos: Pos, floor: &Floor, rng: &mut SmallRng) -> Self { let mut loop_index = 0; loop { - let dir = floor.rng().random(); - let dist = floor.rng().random_range(MIN_ROAM_DIST..=MAX_ROAM_DIST); + let dir = rng.random(); + let dist = rng.random_range(MIN_ROAM_DIST..=MAX_ROAM_DIST); if let Some(p) = starting_pos.step_by(dir, dist) { if !floor.get(p).is_wall() { @@ -201,10 +201,22 @@ impl Entity { /// /// TODO: Merge this implementation (and Self::zombie_movement and Self::movement_helper) with the player movement /// in lib.rs. - pub fn handle_movement(&mut self, player_pos: Pos, floor: &mut Floor, delta_time: f32) { + pub fn handle_movement( + &mut self, + player_pos: Pos, + floor: &Floor, + rng: &mut SmallRng, + delta_time: f32, + ) { match &self.kind { EntityKind::Zombie(move_state) => { - self.zombie_movement(move_state.clone(), player_pos, delta_time, floor); + self.zombie_movement( + move_state.clone(), + player_pos, + delta_time, + floor, + rng, + ); } EntityKind::Player => {} _ => {} @@ -217,7 +229,8 @@ impl Entity { move_state: EnemyMoveState, player_pos: Pos, delta_time: f32, - floor: &mut Floor, + floor: &Floor, + rng: &mut SmallRng, ) { // Check if player is in range if !matches!(move_state, EnemyMoveState::Attack { .. }) @@ -235,7 +248,8 @@ impl Entity { return; } - self.kind = EntityKind::Zombie(EnemyMoveState::new_roam(self.pos, floor)); + self.kind = + EntityKind::Zombie(EnemyMoveState::new_roam(self.pos, floor, rng)); } EnemyMoveState::Roam(mut moves) => { let p = if let Some(p) = moves.last() { |