@@ -15,7 +15,7 @@ pub struct GameStats {
1515 pub distance_traveled : u32 ,
1616 pub shots_fired : u32 ,
1717 pub shots_hit : u32 ,
18- // pub time_played: f32,
18+ pub time_played : f32 ,
1919 // pub successful_trip: bool,
2020}
2121
@@ -43,7 +43,7 @@ pub(super) fn plugin(app: &mut App) {
4343 distance_traveled : 0 ,
4444 shots_fired : 0 ,
4545 shots_hit : 0 ,
46- // time_played: 0.0,
46+ time_played : 0.0 ,
4747 // successful_trip: false,
4848 } ) ;
4949 app. insert_resource ( HasEntered ( false ) ) ;
@@ -56,6 +56,11 @@ pub(super) fn plugin(app: &mut App) {
5656 app. configure_sets ( Startup , GameSystems :: Play ) ;
5757 app. configure_sets ( Startup , GameSystems :: Environment ) ;
5858
59+ app. add_systems (
60+ Update ,
61+ stopwatch. run_if ( in_state ( GameState :: Play ) . and ( in_state ( PauseState :: NotPaused ) ) ) ,
62+ ) ;
63+
5964 app. add_systems (
6065 FixedUpdate ,
6166 enter_player. run_if (
@@ -141,6 +146,7 @@ fn enter_player(
141146 game_stats. distance_traveled = 0 ;
142147 game_stats. shots_fired = 0 ;
143148 game_stats. shots_hit = 0 ;
149+ game_stats. time_played = 0.0 ;
144150 let player = player. single_mut ( ) ;
145151 if player. is_err ( ) {
146152 return ;
@@ -185,6 +191,10 @@ struct Asteroid {
185191#[ derive( Resource ) ]
186192struct AsteroidSpawnTimer ( Timer ) ;
187193
194+ fn stopwatch ( time : Res < Time < Virtual > > , mut game_stats : ResMut < GameStats > ) {
195+ game_stats. time_played += time. delta_secs ( ) ;
196+ }
197+
188198fn player_input (
189199 mut commands : Commands ,
190200 input_query : Query < & ActionState < Action > > ,
0 commit comments