Moving batches works forward but not in reverse

I suspect it has to do with physics sensors not recognizing it in
reverse...

Maybe we can apply the physics backward instead of setting the transform?
main
Elijah Voigt 3 months ago
parent 372240421d
commit 8002c8bae9

@ -81,12 +81,12 @@ fn main() {
), ),
scoring.run_if(on_event::<CollisionEnded>), scoring.run_if(on_event::<CollisionEnded>),
manage_batches.run_if(on_event::<CollisionStarted>).run_if(in_state(PlayerState::Alive).or(in_state(PlayerState::Rewind))), manage_batches.run_if(on_event::<CollisionStarted>).run_if(in_state(PlayerState::Alive).or(in_state(PlayerState::Rewind))),
update_batch_position.run_if(any_component_changed::<Batch>),
update_tooltip.run_if(in_state(DebuggingState::On)), update_tooltip.run_if(in_state(DebuggingState::On)),
), ),
) )
.add_observer(flap) .add_observer(flap)
.add_observer(populate_batch) .add_observer(populate_batch)
.add_observer(update_batch)
.add_observer(populate_pipe) .add_observer(populate_pipe)
.add_observer(populate_ground) .add_observer(populate_ground)
.add_observer(populate_hitbox) .add_observer(populate_hitbox)
@ -213,22 +213,21 @@ fn populate_batch(
parent.spawn(Ground(1)); parent.spawn(Ground(1));
parent.spawn(Ground(2)); parent.spawn(Ground(2));
if *batch_id > 0 { if *batch_id > 0 {
parent.spawn(Pipe::Top); parent.spawn((Pipe::Top, Batch(*batch_id)));
parent.spawn(Pipe::Bottom); parent.spawn((Pipe::Bottom, Batch(*batch_id)));
parent.spawn((Hitbox, Batch(*batch_id))); parent.spawn((Hitbox, Batch(*batch_id)));
} }
}); });
} }
} }
fn update_batch( fn update_batch_position(
trigger: Trigger<OnReplace, Batch>, mut root_changes: Query<(&mut Transform, &Batch), (Changed<Batch>, Without<ChildOf>)>,
mut root: Query<(&mut Transform, &Batch), With<Children>>,
) { ) {
if let Ok((mut t, Batch(idx))) = root.get_mut(trigger.target()) { root_changes.iter_mut().for_each(|(mut t, Batch(idx))|{
debug!("Updating batch {:?}", idx); info!("Updating batch {:?}", idx);
t.translation.x = 500.0 * (*idx) as f32; t.translation.x = 500.0 * (*idx) as f32;
} });
// todo!("Adjust pipe positions"); // todo!("Adjust pipe positions");
} }
@ -652,19 +651,16 @@ fn scoring(
mut events: EventReader<CollisionEnded>, mut events: EventReader<CollisionEnded>,
state: Res<State<PlayerState>>, state: Res<State<PlayerState>>,
bird: Query<Entity, With<Bird>>, bird: Query<Entity, With<Bird>>,
hitboxes: Query<Entity, With<Hitbox>>, hitboxes: Query<&Batch, With<Hitbox>>,
mut score: ResMut<Score>, mut score: ResMut<Score>,
) { ) {
events events
.read() .read()
.filter(|CollisionEnded(a, b)| bird.contains(*a) && hitboxes.contains(*b)) .filter(|CollisionEnded(a, b)| bird.contains(*a) && hitboxes.contains(*b))
.for_each(|_| { .for_each(|CollisionEnded(_a, b)| {
debug!("Hit event while {:?}", state.get()); debug!("Hit event while {:?}", state.get());
match state.get() { let Batch(id) = hitboxes.get(*b).unwrap();
PlayerState::Alive => score.0 = score.0.saturating_add(1), score.0 = *id;
PlayerState::Rewind => score.0 = score.0.saturating_sub(1),
PlayerState::Pause | PlayerState::Stasis => (),
}
}) })
} }
@ -702,9 +698,16 @@ fn manage_batches(
} }
fn update_tooltip( fn update_tooltip(
mut query: Query<(&mut ToolTip, &LinearVelocity, Entity), With<Bird>>, mut query: Query<(&mut ToolTip, Option<&LinearVelocity>, Option<&Batch>, Entity)>,
) { ) {
query.iter_mut().for_each(|(mut tt, lv, _)| { query.iter_mut().for_each(|(mut tt, lv, b, _e)| {
tt.insert("Velocity", format!("{}", lv.0)); // Add Linear Velocity if present on entity
lv.iter().for_each(|it| {
tt.insert("Velocity", format!("{}", it.0));
});
// Add Batch ID to if present
b.iter().for_each(|it| {
tt.insert("Batch", format!("{}", it.0));
});
}); });
} }

Loading…
Cancel
Save