diff options
| author | Freya Murphy <freya@freyacat.org> | 2025-11-17 11:54:58 -0500 |
|---|---|---|
| committer | Freya Murphy <freya@freyacat.org> | 2025-11-17 11:54:58 -0500 |
| commit | 95aad715b636c7e1326b2675668bd0fa12349cf5 (patch) | |
| tree | 100bf04c68acbf62eefd66a30cac6b9749a30c99 /dungeon/src/entity.rs | |
| parent | wasm: fix C_INCLUDE_PATH for non wasm builds (diff) | |
| download | DungeonCrawl-95aad715b636c7e1326b2675668bd0fa12349cf5.tar.gz DungeonCrawl-95aad715b636c7e1326b2675668bd0fa12349cf5.tar.bz2 DungeonCrawl-95aad715b636c7e1326b2675668bd0fa12349cf5.zip | |
update min rust version to 1.88.0
Diffstat (limited to 'dungeon/src/entity.rs')
| -rw-r--r-- | dungeon/src/entity.rs | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/dungeon/src/entity.rs b/dungeon/src/entity.rs index b14f815..3463618 100644 --- a/dungeon/src/entity.rs +++ b/dungeon/src/entity.rs @@ -42,15 +42,15 @@ pub enum Item { } /// The `EntityKind` represents what kind of entity this is. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, Default, PartialEq)] pub enum EntityKind { /// The main player + #[default] Player, Zombie(EnemyMoveState), /// An item (not in an inventory) on the floor of the dungeon Item(Item), } - impl EntityKind { /// Returns the move speed value for this type of entity in tiles/s pub const fn move_speed(&self) -> f32 { @@ -61,11 +61,6 @@ impl EntityKind { } } } -impl Default for EntityKind { - fn default() -> Self { - Self::Player - } -} /// The `EnemyMoveState` enum describes the state of an enemies movement, either Idle /// Roam, or Attack. Idle carries a `f32` value to remember time waited in idle. Both Roam @@ -108,14 +103,13 @@ impl EnemyMoveState { 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() { - if let Some(data) = astar::astar(starting_pos, p, floor) { - let mut path = data.0; - path.reverse(); - return Self::Roam(path); - } - } + if let Some(p) = starting_pos.step_by(dir, dist) + && !floor.get(p).is_wall() + && let Some(data) = astar::astar(starting_pos, p, floor) + { + let mut path = data.0; + path.reverse(); + return Self::Roam(path); } // Safety check |