1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use crate::maze::RespawnEvent;
use bevy::prelude::*;

#[derive(Component)]
pub struct ScoreUI;


pub fn spawn(mut commands: Commands, asset_server: Res<AssetServer>) {
	commands
		.spawn(NodeBundle {
			style: Style {
				width: Val::Percent(100.0),
				height: Val::Percent(100.0),
				justify_content: JustifyContent::FlexStart,
				flex_direction: FlexDirection::Column,
				align_items: AlignItems::FlexStart,
				padding: UiRect::all(Val::Px(10.)),

				..default()
			},
			background_color: Color::NONE.into(),
			..default()
		})
		.with_children(|parent| {
			// parent.spawn(NodeBundle::default());
			parent.spawn(TextBundle::from_section(
				"You're on a roll!",
				TextStyle {
					font: asset_server.load("fonts/FiraSans-Bold.ttf"),
					font_size: 50.0,
					color: Color::WHITE,
					..default()
				},
			));
			parent
				.spawn(
					TextBundle::from_section(
						"Score:  0",
						TextStyle {
							font: asset_server.load("fonts/FiraSans-Bold.ttf"),
							font_size: 40.0,
							color: Color::WHITE,
							..default()
						},
					)
					.with_style(Style {
						margin: UiRect::new(
							Val::Px(0.),
							Val::Px(0.),
							Val::Px(10.0),
							Val::Px(10.0),
						),
						..default()
					}),
				)
				.insert(ScoreUI);
			parent.spawn(TextBundle::from_section(
				"\nClick on maze to start\n\nKeys:         I, J, K, L\nReset:       spacebar",
				TextStyle {
					font: asset_server.load("fonts/FiraSans-Bold.ttf"),
					font_size: 20.0,
					color: Color::WHITE,
					..default()
				},
			));
		});
}


pub fn update(
	mut spawn_event: EventReader<RespawnEvent>,
	mut query: Query<&mut Text, With<ScoreUI>>,
) {
	for e in spawn_event.iter() {
		for mut text in query.iter_mut() {
			text.sections[0].value = format!("Score:  {}", e.level - 1);
		}
	}
}