@@ -2,6 +2,7 @@ use bevy::prelude::*;
2
2
3
3
use crate :: {
4
4
audio:: { GameAudio , PlaySound } ,
5
+ player:: speed_timer:: SpeedTimer ,
5
6
GameAssets , GameState ,
6
7
} ;
7
8
@@ -41,19 +42,45 @@ fn spawn_title(commands: &mut Commands, font: Handle<Font>) -> Entity {
41
42
color : Color :: WHITE ,
42
43
} ;
43
44
let text_bundle =
44
- TextBundle :: from_sections ( [ TextSection :: new ( "WIN" . to_string ( ) , text_style. clone ( ) ) ] ) ;
45
+ TextBundle :: from_sections ( [ TextSection :: new ( "YOU WIN" . to_string ( ) , text_style. clone ( ) ) ] ) ;
45
46
commands. spawn ( ( GameOverScreen , text_bundle) ) . id ( )
46
47
}
47
48
48
- fn spawn_text ( commands : & mut Commands , font : Handle < Font > ) {
49
+ fn spawn_thank_you ( commands : & mut Commands , font : Handle < Font > ) -> Entity {
50
+ let text_style = TextStyle {
51
+ font,
52
+ font_size : 40.0 ,
53
+ color : Color :: WHITE ,
54
+ } ;
55
+ let text_bundle = TextBundle :: from_sections ( [ TextSection :: new (
56
+ "THANKS FOR PLAYING" . to_string ( ) ,
57
+ text_style. clone ( ) ,
58
+ ) ] ) ;
59
+ commands. spawn ( ( GameOverScreen , text_bundle) ) . id ( )
60
+ }
61
+
62
+ fn spawn_time ( commands : & mut Commands , font : Handle < Font > , time : f32 ) -> Entity {
63
+ let text = format ! ( "TIME: {:.2} seconds" , time) ;
64
+ let text_style = TextStyle {
65
+ font,
66
+ font_size : 60.0 ,
67
+ color : Color :: WHITE ,
68
+ } ;
69
+ let text_bundle = TextBundle :: from_sections ( [ TextSection :: new ( text, text_style. clone ( ) ) ] ) ;
70
+ commands. spawn ( ( GameOverScreen , text_bundle) ) . id ( )
71
+ }
72
+
73
+ fn spawn_text ( commands : & mut Commands , font : Handle < Font > , time : f32 ) {
49
74
let title_text = spawn_title ( commands, font. clone ( ) ) ;
75
+ let thank_you_text = spawn_thank_you ( commands, font. clone ( ) ) ;
76
+ let time_text = spawn_time ( commands, font. clone ( ) , time) ;
50
77
51
78
commands
52
79
. spawn ( (
53
80
GameOverScreen ,
54
81
NodeBundle {
55
82
style : Style {
56
- top : Val :: Percent ( 35 .0) ,
83
+ top : Val :: Percent ( 20 .0) ,
57
84
width : Val :: Percent ( 100.0 ) ,
58
85
flex_direction : FlexDirection :: Column ,
59
86
row_gap : Val :: Vh ( 10.0 ) ,
@@ -65,16 +92,16 @@ fn spawn_text(commands: &mut Commands, font: Handle<Font>) {
65
92
..default ( )
66
93
} ,
67
94
) )
68
- . push_children ( & [ title_text] ) ;
95
+ . push_children ( & [ title_text, thank_you_text , time_text ] ) ;
69
96
}
70
97
71
98
fn spawn_audio_silence_timer ( commands : & mut Commands ) {
72
99
commands. spawn ( AudioSilenceTimer ( Timer :: from_seconds ( 0.1 , TimerMode :: Once ) ) ) ;
73
100
}
74
101
75
- fn spawn_win_screen ( mut commands : Commands , assets : Res < GameAssets > ) {
102
+ fn spawn_win_screen ( mut commands : Commands , assets : Res < GameAssets > , speed_timer : Res < SpeedTimer > ) {
76
103
spawn_background ( & mut commands, assets. white_pixel . clone ( ) ) ;
77
- spawn_text ( & mut commands, assets. font . clone ( ) ) ;
104
+ spawn_text ( & mut commands, assets. font . clone ( ) , speed_timer . elapsed ) ;
78
105
spawn_audio_silence_timer ( & mut commands) ;
79
106
}
80
107
0 commit comments