diff --git a/src/bin/flappy/main.rs b/src/bin/flappy/main.rs index b9ebe2b..ab30558 100644 --- a/src/bin/flappy/main.rs +++ b/src/bin/flappy/main.rs @@ -39,9 +39,11 @@ fn main() { ), ) .add_systems(OnEnter(PlayerState::Alive), alive_bird) + .add_systems(OnEnter(PlayerState::Alive), reset_button::) .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::) .add_systems( Update, ( @@ -93,6 +95,8 @@ fn main() { update_batch_position.run_if(any_component_changed::), move_batches.run_if(on_event::), manage_score.run_if(on_event::.or(on_event::)), + shimmer_button::.run_if(in_state(PlayerState::Stasis)), + shimmer_button::.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>, mut commands: Commands, bird: Single>, + curr: Res>, + mut next: ResMut>, ) { + 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( + mut bg: Single<&mut BackgroundColor, With>, + time: Res