Scoring updates in real time so thats nice

main
Elijah Voigt 3 months ago
parent 31a15704ca
commit 6f3b4f7e82

@ -79,7 +79,6 @@ fn main() {
sync_resource_to_ui::<Deaths>.run_if(resource_changed::<Deaths>),
sync_resource_to_ui::<RewindFrames>.run_if(resource_changed::<RewindFrames>),
),
scoring.run_if(on_event::<CollisionEnded>),
update_batch_position.run_if(any_component_changed::<Batch>),
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<CollisionEnded>,
fn manage_score(
trigger: Trigger<OnCollisionEnd>,
state: Res<State<PlayerState>>,
bird: Query<Entity, With<Bird>>,
hitboxes: Query<&Batch, With<Hitbox>>,
mut score: ResMut<Score>,
) {
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());

Loading…
Cancel
Save