summaryrefslogtreecommitdiff
path: root/dungeon/src/entity.rs
diff options
context:
space:
mode:
Diffstat (limited to 'dungeon/src/entity.rs')
-rw-r--r--dungeon/src/entity.rs22
1 files changed, 11 insertions, 11 deletions
diff --git a/dungeon/src/entity.rs b/dungeon/src/entity.rs
index aa77d98..ebdd332 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 crate::{Direction, FPos, Pos, Tile, astar, const_pos};
+use crate::{Direction, FPos, Floor, Pos, astar, const_pos};
/// `PLAYER_FULL_HEALTH` is the starting health of the player entity
pub const PLAYER_FULL_HEALTH: u32 = 10;
@@ -57,9 +57,9 @@ impl EnemyMoveState {
Self::Idle(0.)
}
- pub fn new_attack(starting_pos: Pos, player_pos: Pos, tiles: &[Tile]) -> Option<Self> {
+ pub fn new_attack(starting_pos: Pos, player_pos: Pos, floor: &Floor) -> Option<Self> {
if player_pos.manhattan(starting_pos) < ENEMY_VISION_RADIUS {
- let data = astar::find_path(tiles, starting_pos, player_pos)?;
+ let data = astar::astar(starting_pos, player_pos, floor)?;
let mut path = data.0;
path.reverse();
return Some(Self::Attack(path));
@@ -67,14 +67,14 @@ impl EnemyMoveState {
None
}
- pub fn new_roam(starting_pos: Pos, tiles: &[Tile]) -> Self {
+ 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);
let mut loop_index = 0;
loop {
if let Some(p) = starting_pos.step_by(rand_dir, rand_tiles) {
- if !tiles[p.idx()].is_wall() {
- if let Some(data) = astar::find_path(tiles, starting_pos, p) {
+ if !floor.get(p).is_wall() {
+ if let Some(data) = astar::astar(starting_pos, p, floor) {
let mut path = data.0;
path.reverse();
return Self::Roam(path);
@@ -183,10 +183,10 @@ impl Entity {
}
}
- pub fn handle_movement(&mut self, player_pos: Pos, tiles: &[Tile], delta_time: f32) {
+ pub fn handle_movement(&mut self, player_pos: Pos, floor: &Floor, delta_time: f32) {
match &self.kind {
EntityKind::Zombie(move_state) => {
- self.zombie_movement(move_state.clone(), player_pos, delta_time, tiles);
+ self.zombie_movement(move_state.clone(), player_pos, delta_time, floor);
}
EntityKind::Player => {}
_ => {}
@@ -198,11 +198,11 @@ impl Entity {
move_state: EnemyMoveState,
player_pos: Pos,
delta_time: f32,
- tiles: &[Tile],
+ floor: &Floor,
) {
// Check if player is in range
if !matches!(move_state, EnemyMoveState::Attack { .. })
- && let Some(m_state) = EnemyMoveState::new_attack(self.pos, player_pos, tiles)
+ && let Some(m_state) = EnemyMoveState::new_attack(self.pos, player_pos, floor)
{
self.kind = EntityKind::Zombie(m_state);
return;
@@ -216,7 +216,7 @@ impl Entity {
return;
}
- self.kind = EntityKind::Zombie(EnemyMoveState::new_roam(self.pos, tiles));
+ self.kind = EntityKind::Zombie(EnemyMoveState::new_roam(self.pos, floor));
}
EnemyMoveState::Roam(mut moves) => {
let p = if let Some(p) = moves.last() {