Added trail to physics bird

main
Elijah Voigt 3 months ago
parent c48be4d41b
commit cacfa0098a

@ -1,6 +1,7 @@
// Bevy basically forces "complex types" with Querys // Bevy basically forces "complex types" with Querys
#![allow(clippy::type_complexity)] #![allow(clippy::type_complexity)]
use bevy::color::palettes::tailwind::FUCHSIA_950;
use bevy::render::view::{ColorGrading, ColorGradingGlobal}; use bevy::render::view::{ColorGrading, ColorGradingGlobal};
use games::physics2d::*; use games::physics2d::*;
use games::*; use games::*;
@ -83,7 +84,10 @@ fn main() {
sync_resource_to_ui::<Deaths>.run_if(resource_changed::<Deaths>), sync_resource_to_ui::<Deaths>.run_if(resource_changed::<Deaths>),
sync_resource_to_ui::<RewindFrames>.run_if(resource_changed::<RewindFrames>), sync_resource_to_ui::<RewindFrames>.run_if(resource_changed::<RewindFrames>),
), ),
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 // TODO: Add run_if to this system
update_batch_position.run_if(any_component_changed::<Batch>), update_batch_position.run_if(any_component_changed::<Batch>),
move_batches.run_if(on_event::<CollisionStarted>), move_batches.run_if(on_event::<CollisionStarted>),
@ -135,10 +139,7 @@ struct Tape {
fn init_bird( fn init_bird(
mut commands: Commands, mut commands: Commands,
server: Res<AssetServer>,
bird_assets: Res<BirdAssets>, bird_assets: Res<BirdAssets>,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
) { ) {
let name = Name::new("bird"); let name = Name::new("bird");
@ -893,3 +894,26 @@ fn update_tooltip(
}) })
}); });
} }
fn debug_trail(
mut physics_objects: Query<(Entity ,&Transform), With<Mass>>,
mut gizmos: Gizmos,
mut positions: Local<HashMap<Entity, VecDeque<Vec3>>>,
) {
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);
});
});
})
}

@ -13,6 +13,7 @@ mod version;
// Rust stdlib // Rust stdlib
pub use std::f32::consts::PI; pub use std::f32::consts::PI;
pub use std::fmt::Display; pub use std::fmt::Display;
pub use std::collections::VecDeque;
// Community libraries // Community libraries
pub use bevy::{ pub use bevy::{

Loading…
Cancel
Save