BSP Rooms as an example
This commit is contained in:
parent
fc1bebb4c3
commit
f231a5f4d6
|
@ -57,7 +57,19 @@ impl World {
|
|||
let map = MapBuilder::new(width as usize, height as usize)
|
||||
.with(SimpleRooms::new())
|
||||
.with(NearestCorridors::new())
|
||||
.with(AreaStartingPosition::new(XStart::CENTER, YStart::CENTER))
|
||||
.with(AreaStartingPosition::new(XStart::LEFT, YStart::TOP))
|
||||
.with(DistantExit::new())
|
||||
.build_with_rng(&mut rng);
|
||||
World::new(width, height, map)
|
||||
}
|
||||
|
||||
pub fn new_bsp_rooms(width: u32, height: u32, seed: u32) -> World {
|
||||
World::print_map_info(format!("BSP Rooms with the seed: {}", seed));
|
||||
let mut rng = StdRng::seed_from_u64(seed as u64);
|
||||
let map = MapBuilder::new(width as usize, height as usize)
|
||||
.with(BspRooms::new())
|
||||
.with(NearestCorridors::new())
|
||||
.with(AreaStartingPosition::new(XStart::LEFT, YStart::BOTTOM))
|
||||
.with(DistantExit::new())
|
||||
.build_with_rng(&mut rng);
|
||||
World::new(width, height, map)
|
||||
|
@ -80,7 +92,7 @@ impl World {
|
|||
let mut rng = StdRng::seed_from_u64(seed as u64);
|
||||
let map = MapBuilder::new(width as usize, height as usize)
|
||||
.with(DrunkardsWalk::open_halls())
|
||||
.with(AreaStartingPosition::new(XStart::CENTER, YStart::CENTER))
|
||||
.with(AreaStartingPosition::new(XStart::RIGHT, YStart::BOTTOM))
|
||||
.with(CullUnreachable::new())
|
||||
.with(DistantExit::new())
|
||||
.build_with_rng(&mut rng);
|
||||
|
@ -90,12 +102,14 @@ impl World {
|
|||
pub fn new_random(width: u32, height: u32, seed: u32) -> World {
|
||||
let mut rng = rand::thread_rng();
|
||||
let px = rng.gen::<f32>();
|
||||
if px < 0.25 {
|
||||
if px < 0.2 {
|
||||
World::new_cellular_automata(width, height, seed)
|
||||
} else if px < 0.5 {
|
||||
} else if px < 0.4 {
|
||||
World::new_simple_rooms(width, height, seed)
|
||||
} else if px < 0.75 {
|
||||
} else if px < 0.6 {
|
||||
World::new_drunkard(width, height, seed)
|
||||
} else if px < 0.8 {
|
||||
World::new_bsp_rooms(width, height, seed)
|
||||
} else {
|
||||
World::new_bsp_interior(width, height, seed)
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
|
||||
<a class="dropdown-item" id="cellular-automata-option">Cellular Automata</a>
|
||||
<a class="dropdown-item" id="simple-rooms-option">Simple Rooms</a>
|
||||
<a class="dropdown-item" id="bsp-rooms-option">BSP Rooms</a>
|
||||
<a class="dropdown-item" id="bsp-interior-option">BSP Interior</a>
|
||||
<a class="dropdown-item" id="drunkard-option">Drunkard Walk</a>
|
||||
<a class="dropdown-item" id="random-option">Random Generator</a>
|
||||
|
|
|
@ -54,6 +54,12 @@ function newDrunkard() {
|
|||
requestAnimationFrame(renderLoop);
|
||||
}
|
||||
|
||||
function newBspRooms() {
|
||||
var seed = Date.now();
|
||||
world = World.new_bsp_rooms(GRID_COLS, GRID_ROWS, get_seed());
|
||||
requestAnimationFrame(renderLoop);
|
||||
}
|
||||
|
||||
function newRandomGen() {
|
||||
var seed = Date.now();
|
||||
world = World.new_random(GRID_COLS, GRID_ROWS, get_seed());
|
||||
|
@ -147,6 +153,7 @@ newRandomGen();
|
|||
// Connect UI element
|
||||
document.getElementById('cellular-automata-option').addEventListener('click', newCellularAutomata);
|
||||
document.getElementById('simple-rooms-option').addEventListener('click', newSimpleRooms);
|
||||
document.getElementById('bsp-interior-option').addEventListener('click', newBspInterior);
|
||||
document.getElementById('bsp-rooms-option').addEventListener('click', newBspRooms);
|
||||
document.getElementById('drunkard-option').addEventListener('click', newDrunkard);
|
||||
document.getElementById('bsp-interior-option').addEventListener('click', newBspInterior);
|
||||
document.getElementById('random-option').addEventListener('click', newRandomGen);
|
||||
|
|
Loading…
Reference in New Issue
Block a user