better dorf z
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.8 KiB |
+12
-13
@@ -1,15 +1,16 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
constants::*,
|
constants::*,
|
||||||
|
game,
|
||||||
tilemap::{ChunkMap, CHUNK_SIZE},
|
tilemap::{ChunkMap, CHUNK_SIZE},
|
||||||
};
|
};
|
||||||
use bevy::{math::ivec3, prelude::*};
|
use bevy::{math::ivec3, prelude::*};
|
||||||
use noise::Vector3;
|
|
||||||
|
|
||||||
#[derive(Bundle)]
|
#[derive(Bundle)]
|
||||||
pub struct Citizen {
|
pub struct Citizen {
|
||||||
ambulatory: Ambulatory,
|
ambulatory: Ambulatory,
|
||||||
sprite: Sprite,
|
sprite: Sprite,
|
||||||
transform: Transform,
|
transform: Transform,
|
||||||
|
visibility: Visibility,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Citizen {
|
impl Citizen {
|
||||||
@@ -26,6 +27,7 @@ impl Citizen {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
transform: Transform::from_translation(position).with_scale(Vec3::splat(PIXEL_RATIO)),
|
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(
|
pub fn citizen_movement(
|
||||||
mut query: Query<(&mut Ambulatory, &mut Transform)>,
|
mut query: Query<(&mut Ambulatory, &mut Transform, &mut Visibility)>,
|
||||||
tilemap: Res<TileMap>,
|
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
|
// Check if current position is valid
|
||||||
let current_pos = transform.translation;
|
let current_pos = transform.translation;
|
||||||
let below_pos = Vec3::new(
|
let below_pos = Vec3::new(
|
||||||
@@ -147,19 +150,10 @@ pub fn citizen_movement(
|
|||||||
// println!("transform.translation: {:?}", transform.translation);
|
// println!("transform.translation: {:?}", transform.translation);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let mut rng = rand::thread_rng();
|
|
||||||
if rng.gen_range(0..8) > 0 {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(target) = ambulatory.target {
|
if let Some(target) = ambulatory.target {
|
||||||
// Calculate path if needed
|
// Calculate path if needed
|
||||||
if ambulatory.current_path.is_none() {
|
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(
|
ambulatory.current_path = Some(calculate_path(
|
||||||
&tilemap,
|
&tilemap,
|
||||||
transform.translation.as_ivec3(),
|
transform.translation.as_ivec3(),
|
||||||
@@ -182,6 +176,11 @@ pub fn citizen_movement(
|
|||||||
} else if direction.x < 0.0 {
|
} else if direction.x < 0.0 {
|
||||||
transform.scale.x = -PIXEL_RATIO;
|
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
|
// Check if we've reached the next point
|
||||||
if transform.translation.distance(next_point) < ambulatory.speed {
|
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();
|
let mut rng = rand::thread_rng();
|
||||||
|
|
||||||
// Spawn a handful of citizens
|
// Spawn a handful of citizens
|
||||||
for _ in 0..1 {
|
for _ in 0..5 {
|
||||||
let x: f32 = rng.gen_range(-8.0..8.0);
|
let x: f32 = rng.gen_range(-8.0..8.0);
|
||||||
let y: 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;
|
let mut position = Vec3::new(x.round(), y.round(), 30.0) * TILE_SIZE;
|
||||||
|
|||||||
+5
-6
@@ -150,16 +150,15 @@ pub fn generate_surface_noise(x: i32, y: i32) -> f32 {
|
|||||||
let noise = Perlin::new(0);
|
let noise = Perlin::new(0);
|
||||||
let mut noise_value = 0.0;
|
let mut noise_value = 0.0;
|
||||||
let mut amplitude = 1.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 {
|
for _ in 0..6 {
|
||||||
noise_value += noise.get([x as f64 * frequency, y as f64 * frequency]) * amplitude;
|
noise_value += noise.get([x as f64 * frequency, y as f64 * frequency]) * amplitude;
|
||||||
amplitude *= 0.6; // Gentler amplitude falloff
|
amplitude *= 0.6;
|
||||||
frequency *= 1.8; // Gentler frequency increase
|
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(
|
fn handle_chunk_loading(
|
||||||
@@ -287,7 +286,7 @@ fn handle_chunk_loading(
|
|||||||
|
|
||||||
fn setup_initial_chunks(mut event_writer: EventWriter<LoadChunkEvent>) {
|
fn setup_initial_chunks(mut event_writer: EventWriter<LoadChunkEvent>) {
|
||||||
println!("setup_initial_chunks");
|
println!("setup_initial_chunks");
|
||||||
for x in -3..=3 {
|
for x in -9..=9 {
|
||||||
for y in -2..=2 {
|
for y in -2..=2 {
|
||||||
event_writer.send(LoadChunkEvent {
|
event_writer.send(LoadChunkEvent {
|
||||||
chunk_position: IVec2::new(x, y),
|
chunk_position: IVec2::new(x, y),
|
||||||
|
|||||||
Reference in New Issue
Block a user