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