|
|
|
|
@ -1,8 +1,6 @@
|
|
|
|
|
// Bevy basically forces "complex types" with Querys
|
|
|
|
|
#![allow(clippy::type_complexity)]
|
|
|
|
|
|
|
|
|
|
use bevy::platform::hash::RandomState;
|
|
|
|
|
use std::hash::BuildHasher;
|
|
|
|
|
use games::physics2d::*;
|
|
|
|
|
use games::*;
|
|
|
|
|
|
|
|
|
|
@ -82,6 +80,7 @@ fn main() {
|
|
|
|
|
sync_resource_to_ui::<RewindFrames>.run_if(resource_changed::<RewindFrames>),
|
|
|
|
|
),
|
|
|
|
|
scoring.run_if(on_event::<CollisionEnded>),
|
|
|
|
|
create_forward_batches.run_if(on_event::<CollisionStarted>).run_if(in_state(PlayerState::Alive)),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.add_observer(flap)
|
|
|
|
|
@ -194,8 +193,12 @@ fn init_first_batches(
|
|
|
|
|
fn populate_batch(
|
|
|
|
|
trigger: Trigger<OnAdd, Batch>,
|
|
|
|
|
batches: Query<&Batch>,
|
|
|
|
|
children: Query<&ChildOf>,
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
) {
|
|
|
|
|
// Only run this for top level batch entities,
|
|
|
|
|
// not children containing a reference to their batch, like hitboxes
|
|
|
|
|
if !children.contains(trigger.target()) {
|
|
|
|
|
let Batch(batch_id) = batches.get(trigger.target()).unwrap();
|
|
|
|
|
commands
|
|
|
|
|
.entity(trigger.target())
|
|
|
|
|
@ -209,9 +212,10 @@ fn populate_batch(
|
|
|
|
|
if *batch_id > 0 {
|
|
|
|
|
parent.spawn(Pipe::Top);
|
|
|
|
|
parent.spawn(Pipe::Bottom);
|
|
|
|
|
parent.spawn(Hitbox);
|
|
|
|
|
parent.spawn((Hitbox, Batch(*batch_id)));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The ground population spawns a center peace and two pieces of ground
|
|
|
|
|
@ -648,3 +652,32 @@ fn scoring(
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// When the player moves forward while alive
|
|
|
|
|
/// spawn more batches and despawn old batches
|
|
|
|
|
fn create_forward_batches(
|
|
|
|
|
mut events: EventReader<CollisionStarted>,
|
|
|
|
|
state: Res<State<PlayerState>>,
|
|
|
|
|
bird: Query<Entity, With<Bird>>,
|
|
|
|
|
hitboxes: Query<&Batch, With<Hitbox>>,
|
|
|
|
|
batches: Query<(Entity, &Batch), (With<Children>, Without<Hitbox>)>,
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
) {
|
|
|
|
|
debug_assert!(*state.get() == PlayerState::Alive);
|
|
|
|
|
events
|
|
|
|
|
.read()
|
|
|
|
|
.filter(|CollisionStarted(a, b)| bird.contains(*a) && hitboxes.contains(*b))
|
|
|
|
|
.for_each(|CollisionStarted(_, b)| {
|
|
|
|
|
let Batch(idx) = hitboxes.get(*b).unwrap();
|
|
|
|
|
info!("Batch {:?}", idx);
|
|
|
|
|
if *idx > 2 {
|
|
|
|
|
// Spawn future batch
|
|
|
|
|
commands.spawn(Batch(idx + 2));
|
|
|
|
|
|
|
|
|
|
// Despawn old batch
|
|
|
|
|
if let Some((despawn_batch, _)) = batches.iter().find(|(_, Batch(n))| *n == idx - 2) {
|
|
|
|
|
commands.entity(despawn_batch).despawn();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|