diff options
| author | Freya Murphy <freya@freyacat.org> | 2025-11-06 21:09:20 -0500 |
|---|---|---|
| committer | Freya Murphy <freya@freyacat.org> | 2025-11-06 21:09:20 -0500 |
| commit | 1be214690769e43b7ec93279748a70b29c54b045 (patch) | |
| tree | a3fbea139b49eca7489e0161412ef7772ac33d9d /dungeon/src/entity.rs | |
| parent | graphics: refactor renderer (diff) | |
| download | DungeonCrawl-1be214690769e43b7ec93279748a70b29c54b045.tar.gz DungeonCrawl-1be214690769e43b7ec93279748a70b29c54b045.tar.bz2 DungeonCrawl-1be214690769e43b7ec93279748a70b29c54b045.zip | |
fix clippy and tests (why am i the one doing this)
Diffstat (limited to '')
| -rw-r--r-- | dungeon/src/entity.rs | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/dungeon/src/entity.rs b/dungeon/src/entity.rs index 685e519..f20c534 100644 --- a/dungeon/src/entity.rs +++ b/dungeon/src/entity.rs @@ -26,7 +26,7 @@ pub enum EntityKind { Item(Item), } -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum EntityMoveSpeed { Slow, Medium, @@ -36,9 +36,9 @@ impl EntityMoveSpeed { /// Returns value in tiles/second pub fn value(&self) -> f32 { match &self { - EntityMoveSpeed::Slow => 1., - EntityMoveSpeed::Medium => 2., - EntityMoveSpeed::Fast => 3., + Self::Slow => 1., + Self::Medium => 2., + Self::Fast => 3., } } } @@ -67,13 +67,14 @@ impl Entity { /// # Examples /// /// ``` - /// use dungeon::{Pos, Direction, Entity, EntityKind}; + /// use dungeon::{Pos, Direction, Entity, EntityKind, EntityMoveSpeed}; /// /// let pos = Pos::new(0, 0).unwrap(); /// let dir = Direction::North; /// let kind = EntityKind::Player; /// let health = Some(10); - /// let entity = Entity::new(pos, dir, kind, health); + /// let move_speed = EntityMoveSpeed::Medium; + /// let entity = Entity::new(pos, dir, kind, move_speed, health); /// ``` #[must_use] pub const fn new( @@ -113,6 +114,19 @@ impl Entity { Self::new(pos, dir, kind, move_speed, health) } + /// Creates an Enemy version of the `Entity` + /// + /// # Examples + /// + /// ``` + /// use dungeon::{Pos, Entity, EntityMoveSpeed}; + /// + /// let pos = Pos::new(0, 0).unwrap(); + /// let move_speed = EntityMoveSpeed::Medium; + /// let health = 8; + /// let enemy = Entity::enemy(pos, move_speed, health); + /// ``` + #[must_use] pub const fn enemy(pos: Pos, move_speed: EntityMoveSpeed, health: u32) -> Self { let dir = Direction::East; let kind = EntityKind::Enemy; @@ -120,10 +134,8 @@ impl Entity { } pub fn move_by_dir(&mut self, dir: Direction, delta_time: f32) { - if let Some(fp) = self - .fpos - .step_by(dir, delta_time * &self.move_speed.value()) - { + if let Some(fp) = self.fpos.step_by(dir, delta_time * self.move_speed.value()) { + // TODO: collision self.fpos = fp; } } |