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