generated from tipragot/rust
Adding a map creation plugin #57
|
@ -52,7 +52,7 @@ fn generate_map(
|
||||||
if let (Some(perlin), Some(spiral)) = (noise.as_ref(), map_iterator.as_mut()) {
|
if let (Some(perlin), Some(spiral)) = (noise.as_ref(), map_iterator.as_mut()) {
|
||||||
CoCo_Sol marked this conversation as resolved
Outdated
|
|||||||
if let Some(position) = spiral.next() {
|
if let Some(position) = spiral.next() {
|
||||||
let pixel_position = position.to_pixel_coordinates((0.2, 0.2));
|
let pixel_position = position.to_pixel_coordinates((0.2, 0.2));
|
||||||
commands.spawn((get_type_tile(pixel_position, perlin), position));
|
commands.spawn((get_type(pixel_position, perlin), position));
|
||||||
} else {
|
} else {
|
||||||
end_map_event.send(EndMapGeneration);
|
end_map_event.send(EndMapGeneration);
|
||||||
*noise = None;
|
*noise = None;
|
||||||
|
@ -61,8 +61,8 @@ fn generate_map(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the type of the tile at the given position with the given noise.
|
/// Returns the type of the position with the given noise.
|
||||||
fn get_type_tile(position: (f32, f32), noise: &Perlin) -> Tile {
|
fn get_type(position: (f32, f32), noise: &Perlin) -> Tile {
|
||||||
CoCo_Sol marked this conversation as resolved
Outdated
tipragot
commented
Why don't you use HexPosition here? Why don't you use HexPosition here?
CoCo_Sol
commented
because is not a hex position in a hex grid but a position in orthogonal grid because is not a hex position in a hex grid but a position in orthogonal grid
tipragot
commented
You need to change the name of the function or take an HexPosition and convert it in the function, because it can be confusing that you use "tile" to describe the orthogonal position of an HexPosition You need to change the name of the function or take an HexPosition and convert it in the function, because it can be confusing that you use "tile" to describe the orthogonal position of an HexPosition
CoCo_Sol
commented
you are right you are right
CoCo_Sol marked this conversation as resolved
tipragot
commented
This should be in the get_type function and the value shouldn't be hard coded This should be in the get_type function and the value shouldn't be hard coded
|
|||||||
let value = noise.get([position.0 as f64, position.1 as f64]);
|
let value = noise.get([position.0 as f64, position.1 as f64]);
|
||||||
match value {
|
match value {
|
||||||
v if v <= -0.4 => Tile::Hill,
|
v if v <= -0.4 => Tile::Hill,
|
||||||
|
|
Loading…
Reference in a new issue
You can use the let else syntax to remove one level of nesting.
if I use the "else let" keyword, the nesting level is the same
No because you do an early return
I have to write an unwrap so ?
No, an let else