Fixed README example

This commit is contained in:
klangner 2020-10-17 18:25:16 +02:00
parent 26ff48f5f7
commit a228846d35
2 changed files with 38 additions and 15 deletions

View File

@ -41,31 +41,33 @@ Using single map generator:
```rust
use rand::prelude::*;
use mapgen::dungeon::{
MapGenerator,
cellular_automata::CellularAutomataGen
};
use mapgen::{Map, MapFilter};
use mapgen::filter::CellularAutomata;
let mut rng = StdRng::seed_from_u64(100);
let gen = CellularAutomataGen::new(80, 50);
let map = gen.generate_map(&mut rng)
let gen = CellularAutomata::new();
let map = gen.modify_map(&mut rng, &Map::new(80, 50));
```
Use MapBuilder for chaining map generator and modifiers
```rust
use mapgen::dungeon::{
use mapgen::{
MapBuilder,
map::{Map, Point, TileType},
cellular_automata::CellularAutomataGen,
starting_point::{AreaStartingPosition, XStart, YStart},
cull_unreachable::CullUnreachable,
filter::{
NoiseGenerator,
CellularAutomata,
AreaStartingPosition,
XStart,
YStart,
},
};
let map = MapBuilder::new(CellularAutomataGen::new(80, 50))
let map = MapBuilder::new(80, 50)
.with(NoiseGenerator::uniform())
.with(CellularAutomata::new())
.with(AreaStartingPosition::new(XStart::CENTER, YStart::CENTER))
.with(CullUnreachable::new())
.build_map();
.build();
```
For more information check the [doc](https://docs.rs/mapgen)

21
examples/example1.rs Normal file
View File

@ -0,0 +1,21 @@
use mapgen::{
MapBuilder,
filter::{
NoiseGenerator,
CellularAutomata,
AreaStartingPosition,
XStart,
YStart,
},
};
fn main() {
let map = MapBuilder::new(80, 50)
.with(NoiseGenerator::uniform())
.with(CellularAutomata::new())
.with(AreaStartingPosition::new(XStart::CENTER, YStart::CENTER))
.build();
println!("{:}", &map);
}