Sometimes we get a bug, but not consistently...

main
Elijah Voigt 3 months ago
parent 72ad17d27c
commit 34e2c5a08b

@ -84,7 +84,7 @@ fn main() {
update_tooltip.run_if(in_state(DebuggingState::On)),
// TODO: Add run_if to this system
update_batch_position.run_if(any_component_changed::<Batch>),
hitbox_collision_handler,
move_batches.run_if(on_event::<CollisionStarted>),
manage_score.run_if(on_event::<CollisionStarted>.or(on_event::<CollisionEnded>)),
),
)
@ -810,14 +810,20 @@ fn manage_score(
}
}
/// When the player moves forward while alive
/// spawn more batches and despawn old batches
fn hitbox_collision_handler(
/// WARNING: This method is somewhat janky
///
/// We first figure out which collided entity was a hitbox
/// and bial out early if neither is a hitbox
/// Then we find the batch ID for the hitbox that was hit
/// Next we figure out the old -> new batch IDs based on offsets from the current batch
/// skipping the 0th batch intentionally as that is a special case
/// Finally we iterate over all entities with the old batch ID and upsert the new batch ID
/// This includes root batch entities as well as pipes and hitboxes
fn move_batches(
mut start: EventReader<CollisionStarted>,
bird: Query<Entity, With<Bird>>,
hitboxes: Query<Entity, With<Hitbox>>,
batches: Query<(Entity, &Batch)>,
parents: Query<Entity, Without<ChildOf>>,
state: Res<State<PlayerState>>,
mut commands: Commands,
) {
@ -836,8 +842,7 @@ fn hitbox_collision_handler(
let (_, Batch(curr)) = batches.get(target).unwrap();
debug!("[batches] Current: {curr}");
if *curr > 0 {
info!("[batches] Current: {curr}");
let (old_batch, new_batch) = match state.get() {
PlayerState::Alive => (curr.saturating_sub(2), curr.saturating_add(2)),
PlayerState::Rewind => (curr.saturating_add(2), curr.saturating_sub(2)),
@ -854,7 +859,6 @@ fn hitbox_collision_handler(
commands.entity(old).insert(Batch(new_batch));
})
}
}
});
}

Loading…
Cancel
Save