diff --git a/assets/sky.png b/assets/sky.png index 81cc912..4a37c7e 100644 Binary files a/assets/sky.png and b/assets/sky.png differ diff --git a/src/game.rs b/src/game.rs index e6e4e93..c644ec2 100644 --- a/src/game.rs +++ b/src/game.rs @@ -68,7 +68,7 @@ fn setup_tilemap(commands: &mut Commands, asset_server: &Res) { } for x in -15..15 { for y in -15..15 { - let position = Vec3::new(x as f32 * TILE_SIZE, y as f32 * TILE_SIZE, -14.); + let position = Vec3::new(x as f32 * TILE_SIZE, y as f32 * TILE_SIZE, -39.); commands.spawn(TilePrefab::bedrock(position, asset_server)); } } diff --git a/src/main.rs b/src/main.rs index 269b272..bb0fe56 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,7 +11,7 @@ mod tiles; fn main() { App::new() - .insert_resource(game::ZIndex(-5.0)) + .insert_resource(game::ZIndex(0.0)) .add_plugins( DefaultPlugins .set(WindowPlugin { @@ -33,7 +33,14 @@ fn main() { camera::camera_movement, citizen::citizen_movement, tile::tile_item_sprite_update, - // tile::camera_z_movement.chain(tile::tile_sprite_occlusion), + ), + ) + .init_resource::() + .add_systems( + FixedUpdate, + ( + tile::camera_z_movement, + tile::tile_sprite_occlusion.run_if(|camera_moved: Res| camera_moved.0), ), ) .add_systems(FixedUpdate, cursor::move_cursor) diff --git a/src/tile.rs b/src/tile.rs index a793da7..6d2eb44 100644 --- a/src/tile.rs +++ b/src/tile.rs @@ -55,17 +55,27 @@ pub struct DoorTile { pub locked: bool, } -// pub fn camera_z_movement( -// keyboard_input: Res>, -// mut z_index: ResMut, -// ) { -// if keyboard_input.pressed(KeyCode::ShiftLeft) { -// z_index.0 -= 1.0; -// } -// if keyboard_input.pressed(KeyCode::ShiftRight) { -// z_index.0 += 1.0; -// } -// } +#[derive(Resource, Default)] +pub struct CameraMoved(pub bool); + +// Modify camera_z_movement +pub fn camera_z_movement( + keyboard_input: Res>, + mut z_index: ResMut, + mut camera_moved: ResMut, +) { + camera_moved.0 = false; + if keyboard_input.pressed(KeyCode::ShiftLeft) { + z_index.0 -= 1.0; + z_index.0 = z_index.0.clamp(-39.0, 5.0); + camera_moved.0 = true; + } + if keyboard_input.pressed(KeyCode::ShiftRight) { + z_index.0 += 1.0; + z_index.0 = z_index.0.clamp(-39.0, 5.0); + camera_moved.0 = true; + } +} pub fn tile_sprite_occlusion( mut query: Query<(&mut Visibility, &Transform, &Tile), With>,