|
|
|
|
@ -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,24 +842,22 @@ fn hitbox_collision_handler(
|
|
|
|
|
|
|
|
|
|
let (_, Batch(curr)) = batches.get(target).unwrap();
|
|
|
|
|
|
|
|
|
|
debug!("[batches] Current: {curr}");
|
|
|
|
|
if *curr > 0 {
|
|
|
|
|
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)),
|
|
|
|
|
_ => (*curr, *curr),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if old_batch > 0 && new_batch != 0 {
|
|
|
|
|
batches
|
|
|
|
|
.iter()
|
|
|
|
|
// Filter to just entities with this batch ID
|
|
|
|
|
.filter_map(|(e, Batch(id))| (*id == old_batch).then_some(e))
|
|
|
|
|
.for_each(|old| {
|
|
|
|
|
info!("Moving batch {old_batch}({old}) -> {new_batch}");
|
|
|
|
|
commands.entity(old).insert(Batch(new_batch));
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
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)),
|
|
|
|
|
_ => (*curr, *curr),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if old_batch > 0 && new_batch != 0 {
|
|
|
|
|
batches
|
|
|
|
|
.iter()
|
|
|
|
|
// Filter to just entities with this batch ID
|
|
|
|
|
.filter_map(|(e, Batch(id))| (*id == old_batch).then_some(e))
|
|
|
|
|
.for_each(|old| {
|
|
|
|
|
info!("Moving batch {old_batch}({old}) -> {new_batch}");
|
|
|
|
|
commands.entity(old).insert(Batch(new_batch));
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|