Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions MoreInterestingDungeons/cellular/src/map_builder/automata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ impl MapArchitect for CellularAutomataArchitect {
for _ in 0..10 {
self.iteration(&mut mb.map);
}
self.add_boundaries(&mut mb.map);
let start = self.find_start(&mb.map);
mb.monster_spawns = mb.spawn_monsters(&start, rng);
mb.player_start = start;
Expand Down Expand Up @@ -71,6 +72,19 @@ impl CellularAutomataArchitect {
map.tiles = new_tiles;
}

fn add_boundaries(&mut self, map: &mut Map) {
for x in 1 .. SCREEN_WIDTH {
map.tiles[map_idx(x, 1)] = TileType::Wall;
map.tiles[map_idx(x, SCREEN_HEIGHT-1)] = TileType::Wall;
map.tiles[map_idx(x, 0)] = TileType::Wall;
}
for y in 1 .. SCREEN_HEIGHT {
map.tiles[map_idx(1, y)] = TileType::Wall;
map.tiles[map_idx(SCREEN_WIDTH-1, y)] = TileType::Wall;
map.tiles[map_idx(0, y)] = TileType::Wall;
}
}

fn find_start(&self, map: &Map) -> Point {
let center = Point::new(SCREEN_WIDTH/2, SCREEN_HEIGHT/2);// (10)
let closest_point = map.tiles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ impl CellularAutomataArchitect {
for x in 1 .. SCREEN_WIDTH {
self.map.tiles[map_idx(x, 1)] = TileType::Wall;
self.map.tiles[map_idx(x, SCREEN_HEIGHT-1)] = TileType::Wall;
self.map.tiles[map_idx(x, 0)] = TileType::Wall;
}
for y in 1 .. SCREEN_HEIGHT {
self.map.tiles[map_idx(1, y)] = TileType::Wall;
self.map.tiles[map_idx(SCREEN_WIDTH-1, y)] = TileType::Wall;
self.map.tiles[map_idx(0, y)] = TileType::Wall;
}
}

Expand Down