|
|
|
@ -83,6 +83,8 @@ fn main() {
|
|
|
|
),
|
|
|
|
),
|
|
|
|
update_batch_position.run_if(any_component_changed::<Batch>),
|
|
|
|
update_batch_position.run_if(any_component_changed::<Batch>),
|
|
|
|
update_tooltip.run_if(in_state(DebuggingState::On)),
|
|
|
|
update_tooltip.run_if(in_state(DebuggingState::On)),
|
|
|
|
|
|
|
|
// TODO: Add run_if to this system
|
|
|
|
|
|
|
|
manage_batches,
|
|
|
|
(
|
|
|
|
(
|
|
|
|
// Temp debugging systems
|
|
|
|
// Temp debugging systems
|
|
|
|
debug_collision_events.run_if(on_event::<CollisionEnded>),
|
|
|
|
debug_collision_events.run_if(on_event::<CollisionEnded>),
|
|
|
|
@ -96,7 +98,6 @@ fn main() {
|
|
|
|
.add_observer(populate_pipe)
|
|
|
|
.add_observer(populate_pipe)
|
|
|
|
.add_observer(populate_ground)
|
|
|
|
.add_observer(populate_ground)
|
|
|
|
.add_observer(populate_hitbox)
|
|
|
|
.add_observer(populate_hitbox)
|
|
|
|
.add_observer(manage_batches)
|
|
|
|
|
|
|
|
.add_observer(manage_score)
|
|
|
|
.add_observer(manage_score)
|
|
|
|
.run();
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -143,8 +144,7 @@ fn init_bird(
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
let material = MeshMaterial2d(materials.add(ColorMaterial {
|
|
|
|
let material = MeshMaterial2d(materials.add(ColorMaterial {
|
|
|
|
texture: Some(server.load("flappy/bird.png")),
|
|
|
|
texture: Some(server.load("flappy/bird.png")),
|
|
|
|
// color: ORANGE.into(),
|
|
|
|
color: ORANGE.into(),
|
|
|
|
color: BLACK.into(),
|
|
|
|
|
|
|
|
alpha_mode: AlphaMode2d::Blend,
|
|
|
|
alpha_mode: AlphaMode2d::Blend,
|
|
|
|
..default()
|
|
|
|
..default()
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
@ -469,7 +469,6 @@ fn init_ui(mut commands: Commands) {
|
|
|
|
..default()
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Button,
|
|
|
|
Button,
|
|
|
|
// TODO: Add Pause (basically Stasis) state
|
|
|
|
|
|
|
|
PlayerState::Pause,
|
|
|
|
PlayerState::Pause,
|
|
|
|
children![Text::new("Go!"),],
|
|
|
|
children![Text::new("Go!"),],
|
|
|
|
))
|
|
|
|
))
|
|
|
|
@ -775,7 +774,6 @@ impl Display for Deaths {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Scoring is bugged, need to make it correct.
|
|
|
|
|
|
|
|
fn manage_score(
|
|
|
|
fn manage_score(
|
|
|
|
trigger: Trigger<OnCollisionEnd>,
|
|
|
|
trigger: Trigger<OnCollisionEnd>,
|
|
|
|
state: Res<State<PlayerState>>,
|
|
|
|
state: Res<State<PlayerState>>,
|
|
|
|
@ -836,38 +834,30 @@ fn debug_collision_end_observations(
|
|
|
|
/// When the player moves forward while alive
|
|
|
|
/// When the player moves forward while alive
|
|
|
|
/// spawn more batches and despawn old batches
|
|
|
|
/// spawn more batches and despawn old batches
|
|
|
|
fn manage_batches(
|
|
|
|
fn manage_batches(
|
|
|
|
// TODO: Trigger on both start and end??
|
|
|
|
bird: Query<&ColliderAabb, With<Bird>>,
|
|
|
|
trigger: Trigger<OnCollisionEnd>,
|
|
|
|
hitboxes: Query<(Entity, &ColliderAabb), With<Hitbox>>,
|
|
|
|
state: Res<State<PlayerState>>,
|
|
|
|
|
|
|
|
bird: Query<Entity, With<Bird>>,
|
|
|
|
|
|
|
|
batches: Query<(Entity, &Batch)>,
|
|
|
|
batches: Query<(Entity, &Batch)>,
|
|
|
|
|
|
|
|
state: Res<State<PlayerState>>,
|
|
|
|
mut commands: Commands,
|
|
|
|
mut commands: Commands,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
debug_assert!(
|
|
|
|
bird.iter().for_each(|bird_aabb| {
|
|
|
|
matches!(state.get(), PlayerState::Alive) || matches!(state.get(), PlayerState::Rewind)
|
|
|
|
if let Some(e) = hitboxes.iter().find_map(|(e, hitbox_aabb)| {
|
|
|
|
);
|
|
|
|
bird_aabb.intersects(hitbox_aabb).then_some(e)
|
|
|
|
let a = trigger.target();
|
|
|
|
}) {
|
|
|
|
let b = trigger.collider;
|
|
|
|
let (_, Batch(curr)) = batches.get(e).unwrap();
|
|
|
|
if bird.contains(a)
|
|
|
|
let (target_batch_id, new_batch_id) = match state.get() {
|
|
|
|
&& let Ok((_e, Batch(idx))) = batches.get(b)
|
|
|
|
PlayerState::Alive => (curr.saturating_sub(2), curr.saturating_add(2)),
|
|
|
|
&& *idx > 2
|
|
|
|
PlayerState::Rewind => (curr.saturating_add(2), curr.saturating_sub(2)),
|
|
|
|
{
|
|
|
|
_ => (*curr, *curr),
|
|
|
|
info!("Managing batches in player state {:?}", state.get());
|
|
|
|
|
|
|
|
let (old_batch_idx, new_batch_idx) = match state.get() {
|
|
|
|
|
|
|
|
PlayerState::Alive => (idx - 2, idx + 2),
|
|
|
|
|
|
|
|
PlayerState::Rewind => (idx + 2, idx - 2),
|
|
|
|
|
|
|
|
_ => panic!("Should not happen!"),
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
// Find all entities with the old batch and adjust them
|
|
|
|
if target_batch_id != new_batch_id {
|
|
|
|
batches
|
|
|
|
if let Some(e_old) = batches.iter().find_map(|(e, b)| (b.0 == target_batch_id).then_some(e)) {
|
|
|
|
.iter()
|
|
|
|
commands.entity(e_old).insert(Batch(new_batch_id));
|
|
|
|
.filter_map(|(e, batch)| (batch.0 == old_batch_idx).then_some(e))
|
|
|
|
|
|
|
|
.for_each(|e| {
|
|
|
|
|
|
|
|
info!("Moving batch {} -> {}", old_batch_idx, new_batch_idx);
|
|
|
|
|
|
|
|
commands.entity(e).insert(Batch(new_batch_idx));
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn update_tooltip(
|
|
|
|
fn update_tooltip(
|
|
|
|
mut query: Query<(
|
|
|
|
mut query: Query<(
|
|
|
|
|