From d24bf8defcc12d1434a4a39fb14c81951970d024 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Wed, 31 Jul 2024 15:55:17 -0500 Subject: [PATCH] Crosshair drawing over statues without going invisible past -1000 on the Y axis --- src/camera.rs | 7 +++++++ src/main.rs | 1 + src/movement.rs | 7 +++++-- src/player.rs | 23 ++++++++--------------- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/camera.rs b/src/camera.rs index fb4ed46..37dc8f6 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -3,6 +3,13 @@ use bevy::render::camera::Camera; pub fn startup(mut commands: Commands) { let mut bundle = (Camera2dBundle::default(), IsDefaultUiCamera); + bundle.0.projection = OrthographicProjection { + near: f32::MIN, + far: f32::MAX, + scale: 1., + ..default() + }; + // bundle.0.transform.translation.z = f32::MAX; bundle.0.projection.scale = 1.; commands.spawn(bundle); } diff --git a/src/main.rs b/src/main.rs index 7916255..e88b52d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -96,6 +96,7 @@ fn main() -> AppExit { (update,).after(input::process_input), ( player::control, + player::player_debug_info, statue::spawn_statue, movement::update_velocity_by_heading, movement::resolve_velocity.after(movement::update_velocity_by_heading), diff --git a/src/movement.rs b/src/movement.rs index a067af3..9f3bc00 100644 --- a/src/movement.rs +++ b/src/movement.rs @@ -9,6 +9,9 @@ pub struct Heading(pub Vec2); #[derive(Component, Deref, DerefMut, Debug, Default)] pub struct Speed(pub f32); +#[derive(Component, Deref, DerefMut, Debug, Default)] +pub struct Height(pub f32); + #[derive(Component, Debug, Default)] pub struct YSortable; @@ -24,9 +27,9 @@ pub fn update_velocity_by_heading(mut query: Query<(&mut Velocity, &Speed, &Head } } -pub fn ysort(mut q: Query<&mut Transform, With>) { +pub fn ysort(mut q: Query<(&mut Transform, Option<&Height>), With>) { q.iter_mut() - .for_each(|mut tf| tf.translation.z = -tf.translation.y) + .for_each(|(mut tf, z)| tf.translation.z = -tf.translation.y - z.map(|z| z.0).unwrap_or(0.)) } #[derive(Bundle, Debug, Default)] diff --git a/src/player.rs b/src/player.rs index 299c47f..4a88cc8 100644 --- a/src/player.rs +++ b/src/player.rs @@ -55,28 +55,15 @@ pub fn startup( .with_children(|player| { let mesh = meshes.add(Capsule2d::new(3.0, 25.0)); let material = materials.add(Color::hsl(360. * 1 as f32 / 3 as f32, 0.95, 0.7)); - // let global_transform = GlobalTransform::from_xyz( - // 0.0, 20.0, - // // TODO: need some way to ensure this draws above everything else? - // // a UI layer or something? - // 1000., - // ); - - let transform = Transform::from_xyz( - 0.0, 0.0, - // TODO: need some way to ensure this draws above everything else? - // a UI layer or something? - 1000., - ); + let transform = Transform::from_xyz(0.0, 0.0, 500.); player.spawn(( Crosshair, // TODO: crosshair transform? MaterialMesh2dBundle { - // global_transform, mesh: mesh.into(), - material, transform, + material, ..default() }, )); @@ -102,6 +89,12 @@ pub fn control(input: Res, mut player: Query<&mut Heading, With>) } } +pub fn player_debug_info(mut player: Query<(&Heading, &Transform), With>) { + if let Ok((heading, transform)) = player.get_single_mut() { + info!("{heading:#?} {transform:#?}"); + } +} + pub fn exit(mut commands: Commands, q: Query>) { for id in q.iter() { commands.entity(id).despawn_recursive();