diff --git a/src/components.rs b/src/components.rs index de4a028..d65e9fd 100644 --- a/src/components.rs +++ b/src/components.rs @@ -70,3 +70,11 @@ impl FieldOfView { } } } + +#[derive(Clone, Copy, Debug, PartialEq)] +pub struct ProvidesHealing { + pub amount: i32, +} + +#[derive(Clone, Copy, Debug, PartialEq)] +pub struct ProvidesDungeonMap; diff --git a/src/main.rs b/src/main.rs index 7a4fac2..adc9db3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,7 +47,7 @@ impl State { map_builder .monster_spawns .iter() - .for_each(|pos| spawn_monster(&mut ecs, &mut rng, *pos)); + .for_each(|pos| spawn_entity(&mut ecs, &mut rng, *pos)); resources.insert(map_builder.map); resources.insert(Camera::new(map_builder.player_start)); @@ -71,11 +71,9 @@ impl State { spawn_player(&mut self.ecs, map_builder.player_start); spawn_amulet_of_yala(&mut self.ecs, map_builder.amulet_start); map_builder - .rooms + .monster_spawns .iter() - .skip(1) - .map(|r| r.center()) - .for_each(|pos| spawn_monster(&mut self.ecs, &mut rng, pos)); + .for_each(|pos| spawn_entity(&mut self.ecs, &mut rng, *pos)); self.resources.insert(map_builder.map); self.resources.insert(Camera::new(map_builder.player_start)); self.resources.insert(TurnState::AwaitingInput); diff --git a/src/spawner.rs b/src/spawner.rs index 3c18042..bebb728 100644 --- a/src/spawner.rs +++ b/src/spawner.rs @@ -53,6 +53,41 @@ pub fn spawn_amulet_of_yala(ecs: &mut World, pos: Point) { )); } +pub fn spawn_healing_potion(ecs: &mut World, pos: Point) { + ecs.push(( + Item, + pos, + Render { + color: ColorPair::new(WHITE, BLACK), + glyph: to_cp437('!'), + }, + Name("Healing Potion".to_string()), + ProvidesHealing { amount: 6 }, + )); +} + +pub fn spawn_magic_mapper(ecs: &mut World, pos: Point) { + ecs.push(( + Item, + pos, + Render { + color: ColorPair::new(WHITE, BLACK), + glyph: to_cp437('{'), + }, + Name("Dungeon Map".to_string()), + ProvidesDungeonMap, + )); +} + +pub fn spawn_entity(ecs: &mut World, rng: &mut RandomNumberGenerator, pos: Point) { + let roll = rng.roll_dice(1, 6); + match roll { + 1 => spawn_healing_potion(ecs, pos), + 2 => spawn_magic_mapper(ecs, pos), + _ => spawn_monster(ecs, rng, pos), + } +} + fn goblin() -> (i32, String, FontCharType) { (1, "Goblin".to_string(), to_cp437('g')) }