generated from tipragot/rust
Add a renderer system with temp assets #60
|
@ -11,8 +11,8 @@ pub struct MapGenerationPlugin;
|
|||
|
||||
impl Plugin for MapGenerationPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_event::<MapGenerationEvent>()
|
||||
.add_event::<EndMapGenerationEvent>()
|
||||
app.add_event::<MapGeneration>()
|
||||
.add_event::<EndMapGeneration>()
|
||||
.add_systems(
|
||||
Update,
|
||||
(generate_map.after(delete_map), delete_map)
|
||||
|
@ -23,7 +23,7 @@ impl Plugin for MapGenerationPlugin {
|
|||
|
||||
/// An event to trigger the generation of the map.
|
||||
#[derive(Event)]
|
||||
pub struct MapGenerationEvent {
|
||||
pub struct MapGeneration {
|
||||
/// The seed used to generate the map.
|
||||
pub seed: u32,
|
||||
|
||||
|
@ -33,12 +33,12 @@ pub struct MapGenerationEvent {
|
|||
|
||||
/// An event send when the map is generated.
|
||||
#[derive(Event)]
|
||||
pub struct EndMapGenerationEvent;
|
||||
pub struct EndMapGeneration;
|
||||
|
||||
/// Spawns the tiles if the event is received.
|
||||
fn generate_map(
|
||||
mut event: EventReader<MapGenerationEvent>,
|
||||
mut end_map_event: EventWriter<EndMapGenerationEvent>,
|
||||
mut event: EventReader<MapGeneration>,
|
||||
mut end_map_event: EventWriter<EndMapGeneration>,
|
||||
mut commands: Commands,
|
||||
mut noise: Local<Option<Perlin>>,
|
||||
mut map_iterator: Local<Option<HexSpiral<isize>>>,
|
||||
|
@ -51,10 +51,10 @@ fn generate_map(
|
|||
|
||||
if let (Some(perlin), Some(spiral)) = (noise.as_ref(), map_iterator.as_mut()) {
|
||||
if let Some(position) = spiral.next() {
|
||||
let pixel_position = position.to_pixel_coordinates((0.1, 0.1));
|
||||
let pixel_position = position.to_pixel_coordinates((0.2, 0.2)); // Réduire la taille de la tuile
|
||||
commands.spawn((get_type_tile(pixel_position, perlin), position));
|
||||
} else {
|
||||
end_map_event.send(EndMapGenerationEvent);
|
||||
end_map_event.send(EndMapGeneration);
|
||||
*noise = None;
|
||||
*map_iterator = None;
|
||||
}
|
||||
|
@ -65,17 +65,18 @@ fn generate_map(
|
|||
fn get_type_tile(position: (f32, f32), noise: &Perlin) -> Tile {
|
||||
let value = noise.get([position.0 as f64, position.1 as f64]);
|
||||
match value {
|
||||
v if v <= -0.4 => Tile::Hill,
|
||||
v if v >= 0.4 => Tile::Forest,
|
||||
v if v <= -0.5 => Tile::Hill, // Réduire le seuil pour les collines
|
||||
v if v >= 0.5 => Tile::Forest, // Réduire le seuil pour les forêts
|
||||
_ => Tile::Grass,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Despawns the tiles if the event : [EndMapGenerationEvent] is received.
|
||||
fn delete_map(
|
||||
mut commands: Commands,
|
||||
query: Query<Entity, With<Tile>>,
|
||||
mut event: EventReader<MapGenerationEvent>,
|
||||
mut event: EventReader<MapGeneration>,
|
||||
) {
|
||||
for _ in event.read() {
|
||||
for entity in query.iter() {
|
||||
|
|
Loading…
Reference in a new issue