Add healing potions and maps to maps

This commit is contained in:
Daniel Lynn 2021-07-10 18:56:42 -05:00
parent 81b99c632c
commit 4e639f9179
3 changed files with 46 additions and 5 deletions

View File

@ -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;

View File

@ -47,7 +47,7 @@ impl State {
map_builder map_builder
.monster_spawns .monster_spawns
.iter() .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(map_builder.map);
resources.insert(Camera::new(map_builder.player_start)); resources.insert(Camera::new(map_builder.player_start));
@ -71,11 +71,9 @@ impl State {
spawn_player(&mut self.ecs, map_builder.player_start); spawn_player(&mut self.ecs, map_builder.player_start);
spawn_amulet_of_yala(&mut self.ecs, map_builder.amulet_start); spawn_amulet_of_yala(&mut self.ecs, map_builder.amulet_start);
map_builder map_builder
.rooms .monster_spawns
.iter() .iter()
.skip(1) .for_each(|pos| spawn_entity(&mut self.ecs, &mut rng, *pos));
.map(|r| r.center())
.for_each(|pos| spawn_monster(&mut self.ecs, &mut rng, pos));
self.resources.insert(map_builder.map); self.resources.insert(map_builder.map);
self.resources.insert(Camera::new(map_builder.player_start)); self.resources.insert(Camera::new(map_builder.player_start));
self.resources.insert(TurnState::AwaitingInput); self.resources.insert(TurnState::AwaitingInput);

View File

@ -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) { fn goblin() -> (i32, String, FontCharType) {
(1, "Goblin".to_string(), to_cp437('g')) (1, "Goblin".to_string(), to_cp437('g'))
} }