Complete Chapter 1.12
This commit is contained in:
parent
7079a7eedd
commit
f4f1800770
@ -313,9 +313,10 @@ impl State {
|
||||
|
||||
// Build a new map and place the player
|
||||
let worldmap;
|
||||
let current_depth;
|
||||
{
|
||||
let mut worldmap_resource = self.ecs.write_resource::<Map>();
|
||||
let current_depth = worldmap_resource.depth;
|
||||
current_depth = worldmap_resource.depth;
|
||||
|
||||
*worldmap_resource = Map::new_map_rooms_and_corridors(current_depth + 1);
|
||||
worldmap = worldmap_resource.clone();
|
||||
@ -323,7 +324,7 @@ impl State {
|
||||
|
||||
// Spawn bad guys
|
||||
for room in worldmap.rooms.iter().skip(1) {
|
||||
spawner::spawn_room(&mut self.ecs, room);
|
||||
spawner::spawn_room(&mut self.ecs, room, current_depth + 1);
|
||||
}
|
||||
|
||||
// Place the player and update resources
|
||||
@ -403,7 +404,7 @@ fn main() -> rltk::BError {
|
||||
|
||||
gs.ecs.insert(rltk::RandomNumberGenerator::new());
|
||||
for room in map.rooms.iter().skip(1) {
|
||||
spawner::spawn_room(&mut gs.ecs, room);
|
||||
spawner::spawn_room(&mut gs.ecs, room, 1);
|
||||
}
|
||||
|
||||
gs.ecs.insert(map);
|
||||
|
@ -36,26 +36,26 @@ pub fn player(ecs: &mut World, player_x: i32, player_y: i32) -> Entity {
|
||||
|
||||
const MAX_MONSTERS: i32 = 4;
|
||||
|
||||
fn room_table() -> RandomTable {
|
||||
fn room_table(map_depth: i32) -> RandomTable {
|
||||
RandomTable::new()
|
||||
.add("Goblin", 10)
|
||||
.add("Orc", 1)
|
||||
.add("Orc", 1 + map_depth)
|
||||
.add("Health Potion", 7)
|
||||
.add("Fireball Scroll", 2)
|
||||
.add("Confusion Scroll", 2)
|
||||
.add("Fireball Scroll", 2 + map_depth)
|
||||
.add("Confusion Scroll", 2 + map_depth)
|
||||
.add("Magic Missile Scroll", 4)
|
||||
}
|
||||
|
||||
/// fills a room with stuff!
|
||||
#[allow(clippy::map_entry)]
|
||||
pub fn spawn_room(ecs: &mut World, room: &Rect) {
|
||||
let spawn_table = room_table();
|
||||
pub fn spawn_room(ecs: &mut World, room: &Rect, map_depth: i32) {
|
||||
let spawn_table = room_table(map_depth);
|
||||
let mut spawn_points: HashMap<usize, String> = HashMap::new();
|
||||
|
||||
// Scope to keep the borrow checker happy
|
||||
{
|
||||
let mut rng = ecs.write_resource::<RandomNumberGenerator>();
|
||||
let num_spawns = rng.roll_dice(1, MAX_MONSTERS + 3) - 3;
|
||||
let num_spawns = rng.roll_dice(1, MAX_MONSTERS + 3) + (map_depth - 1) - 3;
|
||||
|
||||
for _i in 0..num_spawns {
|
||||
let mut added = false;
|
||||
|
Loading…
Reference in New Issue
Block a user