diff --git a/assets/sky.png b/assets/sky.png index e618637..5d4304b 100644 Binary files a/assets/sky.png and b/assets/sky.png differ diff --git a/src/game.rs b/src/game.rs index c5ed295..bc37ca5 100644 --- a/src/game.rs +++ b/src/game.rs @@ -6,28 +6,29 @@ use bevy::prelude::*; use rand::prelude::*; use noise::{NoiseFn, Perlin}; +pub const Z_INDEX:f32 = 0.; pub fn setup_level(mut commands: Commands, asset_server: Res) { setup_tilemap(&mut commands, &asset_server); - // for x in -50..50 { - // for y in -25..25 { - // if random::() < 0.1 { - // commands.spawn(Citizen::new( - // &asset_server, - // Vec3::new(x as f32 * 64., y as f32 * 64., 1.), - // )); - // } - // } - // } + for x in -10..10 { + for y in -10..10 { + if random::() < 0.1 { + commands.spawn(Citizen::new( + &asset_server, + Vec3::new(x as f32 * 64., y as f32 * 64., 0.9), + )); + } + } + } } fn setup_tilemap(commands: &mut Commands, asset_server: &Res) { let perlin = Perlin::new(0); - for x in -150..150 { - for y in -150..150 { - for z in -10..10 { + for x in -20..20 { + for y in -20..20 { + for z in -2..10 { let position = Vec3::new( x as f32 * TILE_SIZE, y as f32 * TILE_SIZE, @@ -42,23 +43,15 @@ fn setup_tilemap(commands: &mut Commands, asset_server: &Res) { ]); let mut items: Vec = vec![]; - if noise_value < -0.3 { + if noise_value < -0.4 { commands - .spawn(TilePrefab::rock(position, asset_server)) + .spawn(TilePrefab::air(position, asset_server)) .with_children(|parent| { for item in items { parent.spawn(item); } }); - } else if noise_value < 0. { - commands - .spawn(TilePrefab::dirt(position, asset_server)) - .with_children(|parent| { - for item in items { - parent.spawn(item); - } - }); - } else if noise_value < 0.3 { + } else if noise_value < -0.2 { commands .spawn(TilePrefab::grass(position, asset_server)) .with_children(|parent| { @@ -66,8 +59,16 @@ fn setup_tilemap(commands: &mut Commands, asset_server: &Res) { 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::air(position, asset_server)); + commands.spawn(TilePrefab::rock(position, asset_server)); } } } diff --git a/src/main.rs b/src/main.rs index 1c473f5..1aba68d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,9 +22,9 @@ fn main() { }) .set(ImagePlugin::default_nearest()), ) - .insert_resource(ClearColor(Color::srgb(0.1, 0.1, 0.15))) + .insert_resource(ClearColor(Color::srgb(0.0, 0.0, 0.0))) .add_systems(Startup, (game::setup_level, camera::spawn_panning_camera)) - .add_systems(Startup, tile::tile_sprite_visibility_update) + .add_systems(PostStartup, tile::tile_sprite_visibility_update) .add_systems(Startup, cursor::setup_curor) .add_systems( FixedUpdate, diff --git a/src/tile.rs b/src/tile.rs index 081117b..110df9f 100644 --- a/src/tile.rs +++ b/src/tile.rs @@ -1,16 +1,16 @@ use crate::item::Item; -use crate::constants::*; +use crate::{constants::*, game}; use bevy::prelude::*; #[derive(Component)] #[require(Sprite)] pub struct Tile { - pub id: u32 + pub id: u32, } impl Default for Tile { fn default() -> Self { - Self {id:1} + Self { id: 1 } } } @@ -51,33 +51,39 @@ pub struct DoorTile { pub locked: bool, } - - pub fn tile_sprite_visibility_update( - mut query: Query<(&mut Visibility, &Transform, Entity), With>, + mut query: Query<(&mut Visibility, &Transform), With>, tile_query: Query<(&Transform, &Tile)>, ) { - for (mut visibility, transform, entity) in query.iter_mut() { + for (mut visibility, transform) in query.iter_mut() { *visibility = Visibility::Hidden; + if transform.translation.z > game::Z_INDEX { + continue; + } + for x_offset in -1..=1 { for y_offset in -1..=1 { - if x_offset == 0 && y_offset == 0 { - continue; // Skip the current tile - } + for z_offset in -1..=0 { + if x_offset == 0 && y_offset == 0 && z_offset == 0 { + continue; // Skip the current tile + } + let neighbor_position = transform.translation + + Vec3::new( + x_offset as f32 * TILE_SIZE, + y_offset as f32 * TILE_SIZE, + z_offset as f32 * TILE_SIZE, + ); - let neighbor_position = transform.translation + Vec3::new( - x_offset as f32 * TILE_SIZE, - y_offset as f32 * TILE_SIZE, - 0.0, - ); - - if let Some((neighbor_transform, neighbor_tile)) = tile_query.iter().find(|(neighbor_transform, _)| { - neighbor_transform.translation == neighbor_position - }) { - if neighbor_tile.id == 0 { - *visibility = Visibility::Visible; - break; + if let Some((neighbor_transform, neighbor_tile)) = + tile_query.iter().find(|(neighbor_transform, _)| { + neighbor_transform.translation == neighbor_position + }) + { + if neighbor_tile.id == 0 { + *visibility = Visibility::Visible; + break; + } } } } @@ -85,8 +91,6 @@ pub fn tile_sprite_visibility_update( } } - - pub fn tile_item_sprite_update( time: Res