diff options
| author | Freya Murphy <freya@freyacat.org> | 2025-10-18 00:04:25 -0400 |
|---|---|---|
| committer | Freya Murphy <freya@freyacat.org> | 2025-10-18 00:04:48 -0400 |
| commit | 1be47bcbcbcfa3aa0e06342c6d1e9bb1540cbbd3 (patch) | |
| tree | 64e9b116d2b37139fd8e7dd4d598f2f254fba645 /dungeon/src/map.rs | |
| parent | graphicsL add input functionality to (diff) | |
| download | DungeonCrawl-1be47bcbcbcfa3aa0e06342c6d1e9bb1540cbbd3.tar.gz DungeonCrawl-1be47bcbcbcfa3aa0e06342c6d1e9bb1540cbbd3.tar.bz2 DungeonCrawl-1be47bcbcbcfa3aa0e06342c6d1e9bb1540cbbd3.zip | |
dungeon: refactor into entity module, and add struct (better match proposal)
Diffstat (limited to 'dungeon/src/map.rs')
| -rw-r--r-- | dungeon/src/map.rs | 88 |
1 files changed, 2 insertions, 86 deletions
diff --git a/dungeon/src/map.rs b/dungeon/src/map.rs index 97bb36c..f962180 100644 --- a/dungeon/src/map.rs +++ b/dungeon/src/map.rs @@ -1,10 +1,7 @@ //! The `map` module contains structures of the dungeon game map -//! including the current `Floor`, map `Tile`, and `Entity`. +//! including the current `Floor`, and map `Tile`. -use crate::{ - const_pos, - pos::{Direction, Pos}, -}; +use crate::{const_pos, pos::Pos}; /// `MAP_SIZE` is the size of the size of the dungeon grid. pub const MAP_SIZE: u16 = 100; @@ -15,87 +12,6 @@ pub const MAP_SIZE_USIZE: usize = MAP_SIZE as usize; /// The number of tiles in the dungeon grid pub const TILE_COUNT: usize = MAP_SIZE_USIZE * MAP_SIZE_USIZE; -/// The `EntityKind` represents what kind of entity this is. -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -pub enum EntityKind { - Player, -} - -/// The `Entity` kind represents the main player, or any other -/// ai autonomous character that can move freely across the -/// dungeon. -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -pub struct Entity { - pos: Pos, - dir: Direction, - kind: EntityKind, -} -impl Entity { - /// Creates a new `Entity` at a given `Pos`, `Direction`, and `EntityKind`. - /// - /// # Examples - /// - /// ``` - /// use dungeon::{Pos, Direction, Entity, EntityKind}; - /// - /// let pos = Pos::new(0, 0).unwrap(); - /// let dir = Direction::North; - /// let kind = EntityKind::Player; - /// let entity = Entity::new(pos, dir, kind); - /// ``` - #[must_use] - pub const fn new(pos: Pos, dir: Direction, kind: EntityKind) -> Self { - Self { pos, dir, kind } - } - - /// Creates the Player version of the `Entity` - /// - /// # Examples - /// - /// ``` - /// use dungeon::{Pos, Entity}; - /// - /// let pos = Pos::new(0, 0).unwrap(); - /// let player = Entity::player(pos); - /// ``` - #[must_use] - pub const fn player(pos: Pos) -> Self { - let dir = Direction::East; - let kind = EntityKind::Player; - Self::new(pos, dir, kind) - } - - /// Returns the `Pos` of the entity - #[must_use] - pub const fn pos(&self) -> Pos { - self.pos - } - - /// Returns a mutable referense to the `Pos` of the entity - #[must_use] - pub const fn pos_mut(&mut self) -> &mut Pos { - &mut self.pos - } - - /// Returns the `Direction` of the entity - #[must_use] - pub const fn dir(&self) -> Direction { - self.dir - } - - /// Returns a mutable referense to the `Direction` of the entity - #[must_use] - pub const fn dir_mut(&mut self) -> &mut Direction { - &mut self.dir - } - - /// Returns the `EntityKind` of this entity - #[must_use] - pub const fn kind(&self) -> EntityKind { - self.kind - } -} - /// The `Tile` enum represents what is (or is not) at /// any given spot in the dungeon grid. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |