@@ -60,6 +60,7 @@ impl Plugin for GamePlugin {
6060 . with_system ( move_slit_block)
6161 . with_system ( slits_system)
6262 // effects and juice
63+ . with_system ( game_over_slow_motion)
6364 . with_system ( bounce_audio)
6465 . with_system ( score_audio)
6566 . with_system ( score_effects)
@@ -524,12 +525,17 @@ fn reset_ball(
524525 mut commands : Commands ,
525526 mut player_miss_events : EventReader < PlayerMissEvent > ,
526527 mut player_hit_events : EventReader < PlayerHitEvent > ,
528+ mut time_scale : ResMut < TimeScale > ,
527529 mut query : Query < ( Entity , & mut Transform ) , ( With < Ball > , With < Motion > ) > ,
528530) {
529531 let mut closure = |ball| -> Option < ( ) > {
530532 let ( _, mut transform) = query. get_mut ( ball) . ok ( ) ?;
531533 transform. translation = Vec3 :: new ( 0.0 , 0.0 , -1.0 ) ;
532534 commands. entity ( ball) . remove :: < Motion > ( ) ;
535+
536+ // also reset time scale
537+ time_scale. reset ( ) ;
538+
533539 Some ( ( ) )
534540 } ;
535541
@@ -716,6 +722,42 @@ fn player_miss(
716722 }
717723}
718724
725+ /// Deals with [`GameOverEvent`].
726+ /// The system triggers a slow motion with the duration of [`GAME_OVER_SLOW_MOTION_DURATION`]
727+ fn game_over_slow_motion (
728+ time : Res < Time > ,
729+ mut time_scale : ResMut < TimeScale > ,
730+ mut game_over_events : EventReader < GameOverEvent > ,
731+ mut game_over : Local < GameOver > ,
732+ ) {
733+ if game_over. event . is_some ( ) {
734+ let mut target_time_scale = GAME_OVER_SLOW_MOTION_TIME_SCALE ;
735+ let mut time_scale_damp = TIME_SCALE_DAMP ;
736+
737+ if game_over. slow_motion_timer . tick ( time. delta ( ) ) . finished ( ) {
738+ target_time_scale = 1.0 ;
739+ time_scale_damp = GAME_OVER_TIME_SCALE_DAMP ;
740+ }
741+
742+ time_scale. 0 = time_scale
743+ . 0
744+ . damp ( target_time_scale, time_scale_damp, time. delta_seconds ( ) ) ;
745+
746+ if game_over
747+ . state_change_timer
748+ . tick ( time. delta ( ) )
749+ . just_finished ( )
750+ {
751+ time_scale. reset ( ) ;
752+ * game_over = GameOver :: default ( ) ;
753+ }
754+ } else {
755+ for event in game_over_events. iter ( ) {
756+ game_over. event = Some ( * event) ;
757+ }
758+ }
759+ }
760+
719761/// Emits [`BounceEvent`] when there the ball hits something after debouncing.
720762#[ allow( clippy:: too_many_arguments) ]
721763fn ball_bounce (
0 commit comments