From cacfa0098a98db057f48fa34fadb7e31fcd08c65 Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Tue, 12 Aug 2025 20:45:30 -0700 Subject: [PATCH] Added trail to physics bird --- src/bin/flappy/main.rs | 32 ++++++++++++++++++++++++++++---- src/lib.rs | 1 + 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/bin/flappy/main.rs b/src/bin/flappy/main.rs index 43fa7ad..0e92933 100644 --- a/src/bin/flappy/main.rs +++ b/src/bin/flappy/main.rs @@ -1,6 +1,7 @@ // Bevy basically forces "complex types" with Querys #![allow(clippy::type_complexity)] +use bevy::color::palettes::tailwind::FUCHSIA_950; use bevy::render::view::{ColorGrading, ColorGradingGlobal}; use games::physics2d::*; use games::*; @@ -83,7 +84,10 @@ fn main() { sync_resource_to_ui::.run_if(resource_changed::), sync_resource_to_ui::.run_if(resource_changed::), ), - update_tooltip.run_if(in_state(DebuggingState::On)), + ( + update_tooltip, + debug_trail, + ).run_if(in_state(DebuggingState::On)), // TODO: Add run_if to this system update_batch_position.run_if(any_component_changed::), move_batches.run_if(on_event::), @@ -135,10 +139,7 @@ struct Tape { fn init_bird( mut commands: Commands, - server: Res, bird_assets: Res, - mut meshes: ResMut>, - mut materials: ResMut>, ) { let name = Name::new("bird"); @@ -893,3 +894,26 @@ fn update_tooltip( }) }); } + +fn debug_trail( + mut physics_objects: Query<(Entity ,&Transform), With>, + mut gizmos: Gizmos, + mut positions: Local>>, +) { + physics_objects.iter_mut().for_each(|(e, obj)| { + if let Some(mut list) = positions.get_mut(&e) { + list.push_front(obj.translation); + if list.len() > 60 { + list.pop_back(); + } + } else { + positions.insert(e, vec![obj.translation].into()); + } + + positions.iter().for_each(|(_e, list)| { + list.iter().for_each(|v| { + gizmos.cross_2d(Vec2::new(v.x, v.y), 12., FUCHSIA); + }); + }); + }) +} diff --git a/src/lib.rs b/src/lib.rs index c26b2d2..82127f0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,6 +13,7 @@ mod version; // Rust stdlib pub use std::f32::consts::PI; pub use std::fmt::Display; +pub use std::collections::VecDeque; // Community libraries pub use bevy::{