summaryrefslogtreecommitdiff
path: root/dungeon/src/lib.rs
blob: cfd2fbe143fda924f906aa6507b884945ce737d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! The `dungon` crate contains the core functionality for
//! interacting with a `Dungeon` and its components.

pub mod astar;
pub mod bsp;
pub mod entity;
pub mod map;
pub mod pos;

pub use bsp::*;
pub use entity::*;
pub use map::*;
pub use pos::*;

/// The `Dungeon` type represents the game state of the
/// dungeon crawler.
#[derive(Clone, Debug, PartialEq)]
pub struct Dungeon {
	pub floor: Floor,
	pub player: Player,
	pub enemies: Vec<Entity>,
}
impl Dungeon {
	/// Creates a new `Dungeon`.
	///
	/// # Examples
	///
	/// ```no_run
	/// use dungeon::Dungeon;
	///
	/// let dungeon = Dungeon::new();
	/// ```
	#[must_use]
	pub fn new() -> Self {
		Self::from(Floor::generate())
	}

	/// Creates a new `Dungeon` with a provided seed.
	///
	/// # Examples
	///
	/// ```no_run
	/// use dungeon::Dungeon;
	///
	/// let seed = 234690523482u64;
	/// let dungeon = Dungeon::new_seeded(seed);
	/// ```
	#[must_use]
	pub fn new_seeded(seed: u64) -> Self {
		Self::from(Floor::generate_seeded(seed))
	}

	/// Returns the current position of the camera (viewer)
	#[must_use]
	pub fn camera(&self) -> FPos {
		self.player.entity.fpos
	}
}
impl Default for Dungeon {
	fn default() -> Self {
		Self::from(Floor::default())
	}
}
impl From<Floor> for Dungeon {
	fn from(mut floor: Floor) -> Self {
		let player = Player::new(floor.player_start());

		// TODO: initalize rest of game state

		// TODO: Randomize enemy positions/types
		let enemies = vec![Entity::zombie(floor.random_pos())];

		Self {
			floor,
			player,
			enemies,
		}
	}
}