better dorf z

This commit is contained in:
StephenAdamson
2025-01-25 16:54:27 +00:00
parent 7143a9dded
commit 501c66a1b0
3 changed files with 17 additions and 19 deletions
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

+12 -13
View File
@@ -1,15 +1,16 @@
use crate::{
constants::*,
game,
tilemap::{ChunkMap, CHUNK_SIZE},
};
use bevy::{math::ivec3, prelude::*};
use noise::Vector3;
#[derive(Bundle)]
pub struct Citizen {
ambulatory: Ambulatory,
sprite: Sprite,
transform: Transform,
visibility: Visibility,
}
impl Citizen {
@@ -26,6 +27,7 @@ impl Citizen {
..Default::default()
},
transform: Transform::from_translation(position).with_scale(Vec3::splat(PIXEL_RATIO)),
visibility: Visibility::Hidden,
}
}
}
@@ -129,10 +131,11 @@ pub fn update_citizen_wandering_targets(
}
pub fn citizen_movement(
mut query: Query<(&mut Ambulatory, &mut Transform)>,
mut query: Query<(&mut Ambulatory, &mut Transform, &mut Visibility)>,
tilemap: Res<TileMap>,
z_index: Res<game::ZIndex>,
) {
for (mut ambulatory, mut transform) in query.iter_mut() {
for (mut ambulatory, mut transform, mut visibility) in query.iter_mut() {
// Check if current position is valid
let current_pos = transform.translation;
let below_pos = Vec3::new(
@@ -147,19 +150,10 @@ pub fn citizen_movement(
// println!("transform.translation: {:?}", transform.translation);
continue;
}
let mut rng = rand::thread_rng();
if rng.gen_range(0..8) > 0 {
continue;
}
if let Some(target) = ambulatory.target {
// Calculate path if needed
if ambulatory.current_path.is_none() {
// println!(
// "from {:?} to {:?}",
// transform.translation.as_ivec3(),
// target.as_ivec3() - ivec3(0, 0, 1)
// );
ambulatory.current_path = Some(calculate_path(
&tilemap,
transform.translation.as_ivec3(),
@@ -182,6 +176,11 @@ pub fn citizen_movement(
} else if direction.x < 0.0 {
transform.scale.x = -PIXEL_RATIO;
}
if transform.translation.z.round() / TILE_SIZE <= z_index.0 + 1.0 {
*visibility = Visibility::Visible;
} else {
*visibility = Visibility::Hidden;
}
// Check if we've reached the next point
if transform.translation.distance(next_point) < ambulatory.speed {
@@ -342,7 +341,7 @@ pub fn spawn_citizens(mut commands: Commands, asset_server: Res<AssetServer>) {
let mut rng = rand::thread_rng();
// Spawn a handful of citizens
for _ in 0..1 {
for _ in 0..5 {
let x: f32 = rng.gen_range(-8.0..8.0);
let y: f32 = rng.gen_range(-8.0..8.0);
let mut position = Vec3::new(x.round(), y.round(), 30.0) * TILE_SIZE;
+5 -6
View File
@@ -150,16 +150,15 @@ pub fn generate_surface_noise(x: i32, y: i32) -> f32 {
let noise = Perlin::new(0);
let mut noise_value = 0.0;
let mut amplitude = 1.0;
let mut frequency = 0.008; // Reduced initial frequency for smoother base terrain
let mut frequency = 0.008;
// Reduced number of octaves for less rough detail
for _ in 0..6 {
noise_value += noise.get([x as f64 * frequency, y as f64 * frequency]) * amplitude;
amplitude *= 0.6; // Gentler amplitude falloff
frequency *= 1.8; // Gentler frequency increase
amplitude *= 0.6;
frequency *= 1.8;
}
(noise_value * 2.5) as f32 // Reduced height multiplier for less extreme elevation
(noise_value * 2.5) as f32
}
fn handle_chunk_loading(
@@ -287,7 +286,7 @@ fn handle_chunk_loading(
fn setup_initial_chunks(mut event_writer: EventWriter<LoadChunkEvent>) {
println!("setup_initial_chunks");
for x in -3..=3 {
for x in -9..=9 {
for y in -2..=2 {
event_writer.send(LoadChunkEvent {
chunk_position: IVec2::new(x, y),