From 9d5caadbf495ee5dda5eeaab138094fca6fb9e4a Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Sun, 27 Jul 2025 14:06:42 -0700 Subject: [PATCH] camera following bird works --- src/bin/flappy/main.rs | 11 ++++++++++- src/debug.rs | 2 +- src/scheduling.rs | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/bin/flappy/main.rs b/src/bin/flappy/main.rs index 7b787eb..36b662a 100644 --- a/src/bin/flappy/main.rs +++ b/src/bin/flappy/main.rs @@ -1,4 +1,4 @@ -use bevy::{input::common_conditions::input_just_released, render::view::VisibleEntities}; +use bevy::input::common_conditions::input_just_released; use games::*; fn main() { @@ -37,6 +37,8 @@ fn main() { .run_if(in_state(PlayerState::Alive)), // Rewinding systems rewind.run_if(in_state(PlayerState::Rewind)), + // Camera follows when bird moves regardless of player state + camera_follow_bird.run_if(any_component_changed::), ), ) .run(); @@ -248,3 +250,10 @@ fn kill_bird( debug!("Killing bird"); **bird = RigidBody::Static; } + +fn camera_follow_bird( + bird: Single<&Transform, (With, Changed)>, + mut camera: Single<&mut Transform, (With, Without)> +) { + camera.translation.x = bird.translation.x; +} diff --git a/src/debug.rs b/src/debug.rs index 54f3497..351397c 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -19,7 +19,7 @@ impl Plugin for DebuggingPlugin { ( (toggle_state_visibility::,) .run_if(state_changed::), - toggle_debug_state.run_if(on_keyboard_press(KeyCode::F12)), + toggle_debug_state.run_if(input_just_pressed(KeyCode::F12)), (toggle_light_gizmo, toggle_aabb_gizmo).run_if(state_changed::), ( (hover_mesh, hover_ui) diff --git a/src/scheduling.rs b/src/scheduling.rs index c16ebbe..42d2a23 100644 --- a/src/scheduling.rs +++ b/src/scheduling.rs @@ -14,3 +14,37 @@ pub fn any_component_changed(q: Query>) -> bool pub fn on_keyboard_press(key: KeyCode) -> impl FnMut(Res>) -> bool { move |keys: Res>| keys.just_pressed(key) } + +/* +/// TODO: Make these work: + +use bevy::ecs::query::{ArchetypeFilter, QueryData, QueryFilter}; + +pub fn filter_contains_exactly(n: usize) -> impl FnMut(Query) -> bool +where + F: QueryFilter + ArchetypeFilter +{ + move |q: Query| q.iter().len() == n +} + +pub fn filter_contains_at_least(n: usize) -> impl FnMut(Query) -> bool +where + F: QueryFilter + ArchetypeFilter +{ + move |q: Query| q.iter().len() >= n +} + +pub fn filter_contains_at_most(n: usize) -> impl FnMut(Query) -> bool +where + F: QueryFilter + ArchetypeFilter +{ + move |q: Query| q.iter().len() <= n +} + +pub fn filter_is_empty() -> impl FnMut(Query) -> bool +where + F: QueryFilter + ArchetypeFilter +{ + move |q: Query| q.iter().len() == 0 +} +*/