2023-12-20 13:24:16 -06:00
|
|
|
use bevy::prelude::*;
|
|
|
|
|
2023-12-23 16:50:08 -06:00
|
|
|
use crate::player;
|
|
|
|
|
2023-12-20 13:24:16 -06:00
|
|
|
pub struct Camera;
|
|
|
|
|
|
|
|
impl Plugin for Camera {
|
|
|
|
fn build(&self, app: &mut App) {
|
2023-12-23 16:50:08 -06:00
|
|
|
app.add_systems(Startup, spawn)
|
|
|
|
.add_systems(PostUpdate, focus);
|
2023-12-20 13:24:16 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-23 16:50:08 -06:00
|
|
|
fn spawn(mut commands: Commands) {
|
2023-12-20 13:24:16 -06:00
|
|
|
let mut bundle = Camera2dBundle::default();
|
2023-12-25 15:22:15 -06:00
|
|
|
bundle.projection.scale = 1. / 2.;
|
2023-12-20 13:24:16 -06:00
|
|
|
commands.spawn(bundle);
|
|
|
|
}
|
2023-12-23 16:50:08 -06:00
|
|
|
|
|
|
|
fn focus(
|
|
|
|
player: Query<&Transform, With<player::Player>>,
|
|
|
|
mut camera: Query<
|
|
|
|
&mut Transform,
|
|
|
|
(With<bevy::render::camera::Camera>, Without<player::Player>),
|
|
|
|
>,
|
|
|
|
) {
|
|
|
|
let ply = player.single();
|
|
|
|
let mut camt = camera.single_mut();
|
|
|
|
camt.translation = ply.translation
|
|
|
|
}
|