From 4e639f9179c21dbf5753bfdb880ed7f6e9b4d65e Mon Sep 17 00:00:00 2001 From: Daniel Lynn Date: Sat, 10 Jul 2021 18:56:42 -0500 Subject: [PATCH] Add healing potions and maps to maps --- src/components.rs | 8 ++++++++ src/main.rs | 8 +++----- src/spawner.rs | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) 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')) }