fix fmt
This commit is contained in:
parent
54aab50c3b
commit
fd19c77a6a
33
src/map.rs
33
src/map.rs
|
@ -77,21 +77,26 @@ pub enum Tile {
|
|||
/// Permet de crée des entité representant les cases d'une map, sur une longueur et langueur donné.
|
||||
/// Donner une longueur impaire.
|
||||
pub fn init_map(longueur: u8, largeur: u8, mut commands: Commands) {
|
||||
for y in 0..longueur {
|
||||
for x in 0..largeur {
|
||||
if y % 2 != 0 && x == longueur {
|
||||
} else {
|
||||
let mut curent_type = Tile::Grass;
|
||||
if rand::random() {
|
||||
if rand::random() {
|
||||
curent_type = Tile::Forest
|
||||
} else {
|
||||
curent_type = Tile::Hill
|
||||
}
|
||||
}
|
||||
(0..longueur)
|
||||
.flat_map(|y| {
|
||||
(0..largeur)
|
||||
.filter(move |&x| !(y % 2 == 0 && x == largeur - 1))
|
||||
.map(move |x| (x, y))
|
||||
})
|
||||
.for_each(|(x, y)| {
|
||||
commands.spawn((generate_random_tile_for_map(), Position { x, y }));
|
||||
});
|
||||
}
|
||||
|
||||
commands.spawn((curent_type, Position { x, y }));
|
||||
}
|
||||
/// Cette fonction return un ellement aleatoir entre de la Grass Hill et Forest
|
||||
fn generate_random_tile_for_map() -> Tile {
|
||||
if rand::random() {
|
||||
if rand::random() {
|
||||
Tile::Forest
|
||||
} else {
|
||||
Tile::Hill
|
||||
}
|
||||
} else {
|
||||
Tile::Grass
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue