This commit is contained in:
Daniel Flanagan 2023-12-25 15:35:10 -06:00
parent 6781105af3
commit 623a06284b
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4
2 changed files with 12 additions and 11 deletions

View file

@ -22,7 +22,7 @@ the heavy-lifting for me _plus_ it's a fun excuse to write more Rust.
- https://github.com/bevyengine/bevy/blob/main/examples/audio/audio.rs
- https://github.com/bevyengine/bevy/blob/main/examples/audio/audio_control.rs
- https://github.com/bevyengine/bevy/blob/main/examples/audio/spatial_audio_2d.rs
- [ ] Y-sort
- [X] Y-sort
- [ ] Tile system
- [ ] Basic map
- [ ] Enemies

View file

@ -1,13 +1,15 @@
use bevy::prelude::*;
use crate::player;
use crate::player::Player;
use bevy::render::camera::Camera as BevyCamera;
pub struct Camera;
impl Plugin for Camera {
fn build(&self, app: &mut App) {
app.add_systems(Startup, spawn)
.add_systems(PostUpdate, focus);
.add_systems(PostUpdate, focus)
.add_systems(Update, y_sort);
}
}
@ -18,13 +20,12 @@ fn spawn(mut commands: Commands) {
}
fn focus(
player: Query<&Transform, With<player::Player>>,
mut camera: Query<
&mut Transform,
(With<bevy::render::camera::Camera>, Without<player::Player>),
>,
player: Query<&Transform, With<Player>>,
mut camera: Query<&mut Transform, (With<BevyCamera>, Without<Player>)>,
) {
let ply = player.single();
let mut camt = camera.single_mut();
camt.translation = ply.translation
camera.single_mut().translation = player.single().translation
}
fn y_sort(mut q: Query<&mut Transform>) {
q.for_each_mut(|mut tf| tf.translation.z = -tf.translation.y)
}