diff --git a/src/bin/flappy/main.rs b/src/bin/flappy/main.rs index 3f77b82..6a721be 100644 --- a/src/bin/flappy/main.rs +++ b/src/bin/flappy/main.rs @@ -79,7 +79,6 @@ fn main() { sync_resource_to_ui::.run_if(resource_changed::), sync_resource_to_ui::.run_if(resource_changed::), ), - scoring.run_if(on_event::), update_batch_position.run_if(any_component_changed::), update_tooltip.run_if(in_state(DebuggingState::On)), ( @@ -96,6 +95,7 @@ fn main() { .add_observer(populate_ground) .add_observer(populate_hitbox) .add_observer(manage_batches) + .add_observer(manage_score) .run(); } @@ -687,21 +687,24 @@ impl Display for Deaths { } // TODO: Scoring is bugged, need to make it correct. -fn scoring( - mut events: EventReader, +fn manage_score( + trigger: Trigger, state: Res>, bird: Query>, hitboxes: Query<&Batch, With>, mut score: ResMut, ) { - events - .read() - .filter(|CollisionEnded(a, b)| bird.contains(*a) && hitboxes.contains(*b)) - .for_each(|CollisionEnded(_a, b)| { - debug!("Hit event while {:?}", state.get()); - let Batch(id) = hitboxes.get(*b).unwrap(); - score.0 = *id; - }) + let a = trigger.target(); + let b = trigger.collider; + if bird.contains(a) && hitboxes.contains(b) { + debug!("Hit event while {:?}", state.get()); + let Batch(id) = hitboxes.get(b).unwrap(); + score.0 = match state.get() { + PlayerState::Alive => *id, + PlayerState::Rewind => *id - 1, + _ => *id, // HOW??? + } + } } @@ -746,8 +749,8 @@ fn manage_batches( ); let a = trigger.target(); let b = trigger.collider; - if bird.contains(*a) - && let Ok((e, Batch(idx))) = batches.get(*b) + if bird.contains(a) + && let Ok((_e, Batch(idx))) = batches.get(b) && *idx > 2 { info!("Managing batches in player state {:?}", state.get());