Noise surface
This commit is contained in:
+69
-21
@@ -1,3 +1,5 @@
|
||||
use std::process::exit;
|
||||
|
||||
use crate::citizen::Citizen;
|
||||
use crate::constants::*;
|
||||
use crate::item::{Item, ItemBundle};
|
||||
@@ -17,7 +19,7 @@ pub fn setup_level(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||
if random::<f32>() < 0.1 {
|
||||
commands.spawn(Citizen::new(
|
||||
&asset_server,
|
||||
Vec3::new(x as f32 * 64., y as f32 * 64., 0.9),
|
||||
Vec3::new(x as f32 * TILE_SIZE, y as f32 * TILE_SIZE, 0.9),
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -25,18 +27,73 @@ pub fn setup_level(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||
}
|
||||
|
||||
fn setup_tilemap(commands: &mut Commands, asset_server: &Res<AssetServer>) {
|
||||
let perlin = Perlin::new(0);
|
||||
let noise = Perlin::new(0);
|
||||
|
||||
for x in -50..50 {
|
||||
for y in -50..50 {
|
||||
for z in -50..150 {
|
||||
let position = Vec3::new(x as f32 * TILE_SIZE, y as f32 * TILE_SIZE, -z as f32);
|
||||
for y in -50..50 {
|
||||
for x in -50..50 {
|
||||
// Base noise for terrain height
|
||||
let noise_value_a = noise.get([x as f64 * 0.01, y as f64 * 0.01]) * 1.25;
|
||||
// Additional noise for bumpiness
|
||||
let noise_value_b = noise.get([x as f64 * 0.05, y as f64 * 0.05]) * 0.25;
|
||||
|
||||
// Generate Perlin noise value
|
||||
let noise_value = perlin.get([x as f64 * 0.1, y as f64 * 0.1, z as f64 * 0.1]);
|
||||
// Combine the two noise values
|
||||
let combined_noise_value = noise_value_a + noise_value_b;
|
||||
// print!("({}, {}, {}), ", noise_value_a, noise_value_b, combined_noise_value);
|
||||
|
||||
let mut items: Vec<ItemBundle> = vec![];
|
||||
if noise_value < -0.4 {
|
||||
let noise_position = Vec3::new(
|
||||
(x as f32 * TILE_SIZE).round(),
|
||||
(y as f32 * TILE_SIZE).round(),
|
||||
(combined_noise_value * 4.).round() as f32 * TILE_SIZE,
|
||||
);
|
||||
|
||||
for z in -150..50 {
|
||||
let position = Vec3::new(
|
||||
(x as f32 * TILE_SIZE).round(),
|
||||
(y as f32 * TILE_SIZE).round(),
|
||||
(z as f32 * TILE_SIZE).round(),
|
||||
);
|
||||
|
||||
let items: Vec<ItemBundle> = vec![];
|
||||
|
||||
if noise_position.z > position.z {
|
||||
if z < -15 {
|
||||
let noise_value =
|
||||
noise.get([x as f64 * 0.1, y as f64 * 0.1, z as f64 * 0.1]);
|
||||
if noise_value < -0.5 {
|
||||
commands
|
||||
.spawn(TilePrefab::air(position, asset_server))
|
||||
.with_children(|parent| {
|
||||
for item in items {
|
||||
parent.spawn(item);
|
||||
}
|
||||
});
|
||||
} else if noise_value < 0.8 {
|
||||
commands
|
||||
.spawn(TilePrefab::rock(position, asset_server))
|
||||
.with_children(|parent| {
|
||||
for item in items {
|
||||
parent.spawn(item);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
commands
|
||||
.spawn(TilePrefab::dirt(position, asset_server))
|
||||
.with_children(|parent| {
|
||||
for item in items {
|
||||
parent.spawn(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
commands
|
||||
.spawn(TilePrefab::dirt(position, asset_server))
|
||||
.with_children(|parent| {
|
||||
for item in items {
|
||||
parent.spawn(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if noise_position.z < position.z {
|
||||
commands
|
||||
.spawn(TilePrefab::air(position, asset_server))
|
||||
.with_children(|parent| {
|
||||
@@ -44,7 +101,7 @@ fn setup_tilemap(commands: &mut Commands, asset_server: &Res<AssetServer>) {
|
||||
parent.spawn(item);
|
||||
}
|
||||
});
|
||||
} else if noise_value < -0.2 {
|
||||
} else {
|
||||
commands
|
||||
.spawn(TilePrefab::grass(position, asset_server))
|
||||
.with_children(|parent| {
|
||||
@@ -52,20 +109,11 @@ fn setup_tilemap(commands: &mut Commands, asset_server: &Res<AssetServer>) {
|
||||
parent.spawn(item);
|
||||
}
|
||||
});
|
||||
} else if noise_value < 0.2 {
|
||||
commands
|
||||
.spawn(TilePrefab::dirt(position, asset_server))
|
||||
.with_children(|parent| {
|
||||
for item in items {
|
||||
parent.spawn(item);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
commands.spawn(TilePrefab::rock(position, asset_server));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for x in -50..50 {
|
||||
for y in -50..50 {
|
||||
let position = Vec3::new(x as f32 * TILE_SIZE, y as f32 * TILE_SIZE, -150.);
|
||||
|
||||
Reference in New Issue
Block a user