From c11a797d38f8655cdf3432c48f576dcef511af50 Mon Sep 17 00:00:00 2001 From: CoCoSol007 Date: Wed, 21 Feb 2024 18:37:47 +0100 Subject: [PATCH] save --- crates/border-wars/src/map/generation.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/border-wars/src/map/generation.rs b/crates/border-wars/src/map/generation.rs index dd263b3..9587d74 100644 --- a/crates/border-wars/src/map/generation.rs +++ b/crates/border-wars/src/map/generation.rs @@ -9,13 +9,15 @@ use super::{Tile, TilePosition}; /// A plugin to handle the map generation. pub struct MapGenerationPlugin; +const MAP_GENERATION_ZOOM: f32 = 0.2; + impl Plugin for MapGenerationPlugin { fn build(&self, app: &mut App) { app.add_event::() .add_event::() .add_systems( Update, - (generate_map.after(delete_map), delete_map) + (delete_map, generate_map.after(delete_map)) .run_if(in_state(crate::CurrentScene::Game)), ); } @@ -62,8 +64,7 @@ fn generate_map( // If the map is generated, we send [EndMapGeneration] and set the local // variables to None. if let Some(position) = spiral.next() { - let pixel_position = position.to_pixel_coordinates() * 0.2; - commands.spawn((get_type(pixel_position, noise), position as TilePosition)); + commands.spawn((get_type_tile(position, noise), position as TilePosition)); } else { end_generation_writer.send(EndMapGeneration); *local_noise = None; @@ -72,8 +73,9 @@ fn generate_map( } /// Returns the type of the position with the given noise. -fn get_type(position: Vec2, noise: &Perlin) -> Tile { - let value = noise.get([position.x as f64, position.y as f64]); +fn get_type_tile(position: HexPosition, noise: &Perlin) -> Tile { + let pixel_position = position.to_pixel_coordinates() * MAP_GENERATION_ZOOM; + let value = noise.get([pixel_position.x as f64, pixel_position.y as f64]); match value { v if v <= -0.4 => Tile::Hill, v if v >= 0.4 => Tile::Forest, @@ -81,7 +83,7 @@ fn get_type(position: Vec2, noise: &Perlin) -> Tile { } } -/// Despawns the tiles if the event : [StartMapGeneration] is received. +/// Despawns the tiles if the event [StartMapGeneration] is received. fn delete_map( mut commands: Commands, query: Query>,