diff --git a/src/bullet.rs b/src/bullet.rs index 7b6ad84..087c533 100644 --- a/src/bullet.rs +++ b/src/bullet.rs @@ -8,6 +8,11 @@ impl Plugin for BulletPlugin { .add_system_set( SystemSet::on_exit(AppState::InGame).with_system(cleanup::), ) + .add_system_set( + SystemSet::on_update(AppState::MechaPicker) + .with_system(handle_bullet_events) + .with_system(handle_bullets), + ) .add_system_set( SystemSet::on_update(AppState::InGame) .with_system(handle_bullet_events) diff --git a/src/follow_text.rs b/src/follow_text.rs new file mode 100644 index 0000000..de2fb51 --- /dev/null +++ b/src/follow_text.rs @@ -0,0 +1,41 @@ +use crate::game_camera::PanOrbitCamera; +use bevy::prelude::*; +use bevy::render::camera::*; + +pub struct FollowTextPlugin; +impl Plugin for FollowTextPlugin { + fn build(&self, app: &mut App) { + app.add_system(update_text_position); + } +} + +#[derive(Component)] +pub struct FollowText { + pub following: Entity, +} + +fn update_text_position( + windows: Res, + mut text_query: Query<(&mut Style, &CalculatedSize, &FollowText)>, + mesh_query: Query<&Transform>, + camera_query: Query<(&Camera, &GlobalTransform), With>, +) { + for (mut style, calculated, follow) in text_query.iter_mut() { + if let Ok(mesh_position) = mesh_query.get(follow.following) { + for (camera, camera_transform) in camera_query.iter() { + match camera.world_to_screen(&windows, camera_transform, mesh_position.translation) + { + Some(coords) => { + style.position.left = Val::Px(coords.x - calculated.size.width / 2.0); + style.position.bottom = + Val::Px((coords.y * 1.4) - calculated.size.height / 2.0); + } + None => { + // A hack to hide the text when the it's behind the camera + style.position.bottom = Val::Px(-1000.0); + } + } + } + } + } +} diff --git a/src/game_camera.rs b/src/game_camera.rs index f626b43..5ab4667 100644 --- a/src/game_camera.rs +++ b/src/game_camera.rs @@ -8,8 +8,11 @@ pub struct GameCameraPlugin; impl Plugin for GameCameraPlugin { fn build(&self, app: &mut App) { app.insert_resource(Perlin::new()) - .add_system(handle_camera_shake) - .add_system(pan_orbit_camera); + .insert_resource(CameraSettings::default()) + //.add_system(handle_camera_shake) + .add_system(update_camera) + //.add_system(pan_orbit_camera); +; } } @@ -30,6 +33,88 @@ impl Default for PanOrbitCamera { } } +#[derive(Default)] +pub struct CameraSettings { + look_at: Vec3, + height: f32, + orbit: bool, + speed: f32, + distance: f32, + target_distance: f32, +} + +impl CameraSettings { + pub fn set_camera( + &mut self, + height: f32, + look_at: Vec3, + speed: f32, + orbit: bool, + distance: f32, + target_distance: f32, + ) { + self.height = height; + self.look_at = look_at; + self.speed = speed; + self.orbit = orbit; + self.distance = distance; + self.target_distance = target_distance; + } +} + +fn update_camera( + mut cameras: Query<&mut Transform, With>, + mut camera_settings: ResMut, + time: Res