attempt noise gen
This commit is contained in:
+29
-53
@@ -4,77 +4,53 @@ use crate::tiles::TilePrefab;
|
||||
use crate::constants::*;
|
||||
use bevy::prelude::*;
|
||||
use rand::prelude::*;
|
||||
use noise::{NoiseFn, Perlin};
|
||||
|
||||
|
||||
pub fn setup_level(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||
setup_tilemap(&mut commands, &asset_server);
|
||||
|
||||
for x in -50..50 {
|
||||
for y in -25..25 {
|
||||
if random::<f32>() < 0.1 {
|
||||
commands.spawn(Citizen::new(
|
||||
&asset_server,
|
||||
Vec3::new(x as f32 * 64., y as f32 * 64., 1.),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
// for x in -50..50 {
|
||||
// for y in -25..25 {
|
||||
// if random::<f32>() < 0.1 {
|
||||
// commands.spawn(Citizen::new(
|
||||
// &asset_server,
|
||||
// Vec3::new(x as f32 * 64., y as f32 * 64., 1.),
|
||||
// ));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
fn setup_tilemap(commands: &mut Commands, asset_server: &Res<AssetServer>) {
|
||||
for x in -50..50 {
|
||||
for y in -25..25 {
|
||||
for z in 0..4 {
|
||||
let perlin = Perlin::new(0);
|
||||
|
||||
for x in -150..150 {
|
||||
for y in -150..150 {
|
||||
for z in -10..10 {
|
||||
let position = Vec3::new(
|
||||
x as f32 * TILE_SIZE,
|
||||
y as f32 * TILE_SIZE,
|
||||
-z as f32,
|
||||
);
|
||||
|
||||
// Generate Perlin noise value
|
||||
let noise_value = perlin.get([
|
||||
x as f64 * 0.1,
|
||||
y as f64 * 0.1,
|
||||
z as f64 * 0.1,
|
||||
]);
|
||||
|
||||
let mut items: Vec<ItemBundle> = vec![];
|
||||
|
||||
if random::<f32>() < 0.1 {
|
||||
items.push(ItemBundle {
|
||||
transform: Transform::from_translation(Vec3::new(0., 0., 0.1)),
|
||||
sprite: Sprite {
|
||||
image: asset_server.load("beer.png"),
|
||||
..Default::default()
|
||||
},
|
||||
item: Item::new(),
|
||||
visibility: Visibility::Visible,
|
||||
});
|
||||
}
|
||||
if random::<f32>() < 0.1 {
|
||||
items.push(ItemBundle {
|
||||
transform: Transform::from_translation(Vec3::new(0., 0., 0.1)),
|
||||
sprite: Sprite {
|
||||
image: asset_server.load("chalice.png"),
|
||||
..Default::default()
|
||||
},
|
||||
item: Item::new(),
|
||||
visibility: Visibility::Visible,
|
||||
});
|
||||
}
|
||||
if random::<f32>() < 0.1 {
|
||||
items.push(ItemBundle {
|
||||
transform: Transform::from_translation(Vec3::new(0., 0., 0.1)),
|
||||
sprite: Sprite {
|
||||
image: asset_server.load("fish.png"),
|
||||
..Default::default()
|
||||
},
|
||||
item: Item::new(),
|
||||
visibility: Visibility::Visible,
|
||||
});
|
||||
}
|
||||
|
||||
if random::<f32>() < 0.7 {
|
||||
if noise_value < -0.3 {
|
||||
commands
|
||||
.spawn(TilePrefab::grass(position, asset_server))
|
||||
.spawn(TilePrefab::rock(position, asset_server))
|
||||
.with_children(|parent| {
|
||||
for item in items {
|
||||
parent.spawn(item);
|
||||
}
|
||||
});
|
||||
} else if random::<f32>() < 0.2 {
|
||||
} else if noise_value < 0. {
|
||||
commands
|
||||
.spawn(TilePrefab::dirt(position, asset_server))
|
||||
.with_children(|parent| {
|
||||
@@ -82,9 +58,9 @@ fn setup_tilemap(commands: &mut Commands, asset_server: &Res<AssetServer>) {
|
||||
parent.spawn(item);
|
||||
}
|
||||
});
|
||||
} else if random::<f32>() < 0.1 {
|
||||
} else if noise_value < 0.3 {
|
||||
commands
|
||||
.spawn(TilePrefab::rock(position, asset_server))
|
||||
.spawn(TilePrefab::grass(position, asset_server))
|
||||
.with_children(|parent| {
|
||||
for item in items {
|
||||
parent.spawn(item);
|
||||
|
||||
Reference in New Issue
Block a user