|
|
|
|
@ -39,9 +39,11 @@ fn main() {
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.add_systems(OnEnter(PlayerState::Alive), alive_bird)
|
|
|
|
|
.add_systems(OnEnter(PlayerState::Alive), reset_button::<FlapButton>)
|
|
|
|
|
.add_systems(OnEnter(PlayerState::Rewind), (start_rewinding, alive_bird))
|
|
|
|
|
.add_systems(OnEnter(PlayerState::Pause), pause_bird)
|
|
|
|
|
.add_systems(OnEnter(PlayerState::Stasis), pause_bird)
|
|
|
|
|
.add_systems(OnExit(PlayerState::Stasis), reset_button::<RewindButton>)
|
|
|
|
|
.add_systems(
|
|
|
|
|
Update,
|
|
|
|
|
(
|
|
|
|
|
@ -93,6 +95,8 @@ fn main() {
|
|
|
|
|
update_batch_position.run_if(any_component_changed::<Batch>),
|
|
|
|
|
move_batches.run_if(on_event::<CollisionStarted>),
|
|
|
|
|
manage_score.run_if(on_event::<CollisionStarted>.or(on_event::<CollisionEnded>)),
|
|
|
|
|
shimmer_button::<RewindButton>.run_if(in_state(PlayerState::Stasis)),
|
|
|
|
|
shimmer_button::<FlapButton>.run_if(in_state(PlayerState::Pause)),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.add_observer(flap)
|
|
|
|
|
@ -407,12 +411,18 @@ fn init_assets(
|
|
|
|
|
#[derive(Component)]
|
|
|
|
|
struct FlapSfx;
|
|
|
|
|
|
|
|
|
|
#[derive(Component)]
|
|
|
|
|
struct FlapButton;
|
|
|
|
|
|
|
|
|
|
#[derive(Component)]
|
|
|
|
|
struct BonkSfx;
|
|
|
|
|
|
|
|
|
|
#[derive(Component)]
|
|
|
|
|
struct RewindSfx;
|
|
|
|
|
|
|
|
|
|
#[derive(Component)]
|
|
|
|
|
struct RewindButton;
|
|
|
|
|
|
|
|
|
|
fn init_ui(mut commands: Commands) {
|
|
|
|
|
commands
|
|
|
|
|
.spawn((
|
|
|
|
|
@ -532,11 +542,9 @@ fn init_ui(mut commands: Commands) {
|
|
|
|
|
flex_direction: FlexDirection::Column,
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
Button,
|
|
|
|
|
PlayerState::Pause,
|
|
|
|
|
children![Text::new("Go!"),],
|
|
|
|
|
))
|
|
|
|
|
.observe(start_game);
|
|
|
|
|
children![Text::new("Go!")],
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
commands
|
|
|
|
|
.spawn(Node {
|
|
|
|
|
@ -550,13 +558,15 @@ fn init_ui(mut commands: Commands) {
|
|
|
|
|
.spawn((
|
|
|
|
|
Node { ..default() },
|
|
|
|
|
Button,
|
|
|
|
|
BackgroundColor::default(),
|
|
|
|
|
RewindButton,
|
|
|
|
|
children![Text::new("Rewind!"),],
|
|
|
|
|
))
|
|
|
|
|
.observe(start_rewind)
|
|
|
|
|
.observe(end_rewind);
|
|
|
|
|
|
|
|
|
|
parent
|
|
|
|
|
.spawn((Node { ..default() }, Button, children![Text::new("Flap!"),]))
|
|
|
|
|
.spawn((Node { ..default() }, Button, FlapButton, children![Text::new("Flap!"),]))
|
|
|
|
|
.observe(flap_button);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@ -585,7 +595,12 @@ fn flap_button(
|
|
|
|
|
_trigger: Trigger<Pointer<Pressed>>,
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
bird: Single<Entity, With<Bird>>,
|
|
|
|
|
curr: Res<State<PlayerState>>,
|
|
|
|
|
mut next: ResMut<NextState<PlayerState>>,
|
|
|
|
|
) {
|
|
|
|
|
if !matches!(curr.get(), PlayerState::Alive) {
|
|
|
|
|
next.set(PlayerState::Alive);
|
|
|
|
|
}
|
|
|
|
|
let e = *bird;
|
|
|
|
|
debug!("Flapping {:?}", e);
|
|
|
|
|
commands.trigger_targets(Flap, e);
|
|
|
|
|
@ -994,3 +1009,21 @@ fn start_rewinding(
|
|
|
|
|
RewindSfx,
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn shimmer_button<T: Component>(
|
|
|
|
|
mut bg: Single<&mut BackgroundColor, With<T>>,
|
|
|
|
|
time: Res<Time>,
|
|
|
|
|
) {
|
|
|
|
|
let t = time.elapsed_secs();
|
|
|
|
|
let period = 3.0;
|
|
|
|
|
let r = (((t / period) % 1.0) * std::f32::consts::PI).cos();
|
|
|
|
|
let g = ((((t / period) + 0.3) % 1.0) * std::f32::consts::PI).cos();
|
|
|
|
|
let b = ((((t / period) + 0.6) % 1.0) * std::f32::consts::PI).cos();
|
|
|
|
|
bg.0 = Srgba::rgb(r, g, b).into();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn reset_button<T: Component>(
|
|
|
|
|
mut bg: Single<&mut BackgroundColor, With<T>>,
|
|
|
|
|
) {
|
|
|
|
|
bg.0 = WHITE.into();
|
|
|
|
|
}
|
|
|
|
|
|