SkyRace: add score display

This commit is contained in:
yuni 2024-11-25 01:00:25 +01:00
parent 33a572eba2
commit a9c7aafece
3 changed files with 74 additions and 1 deletions

View file

@ -747,9 +747,15 @@ fn handle_race(
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
mut ew_achievement: EventWriter<game::AchievementEvent>,
q_player: Query<(&Position, &LinearVelocity, &Transform), With<PlayerCamera>>,
mut q_scoredisplay: Query<&mut Text, With<hud::SkyRaceScoreDisplay>>,
mut q_scorewrapper: Query<&mut Visibility, With<hud::SkyRaceScoreWrapper>>,
mut q_racetarget: Query<
(Entity, &mut Position, &mut LinearVelocity, &mut Visibility),
(With<RaceTarget>, Without<PlayerCamera>),
(
With<RaceTarget>,
Without<PlayerCamera>,
Without<hud::SkyRaceScoreWrapper>,
),
>,
) {
let mut deinitialize = false;
@ -785,10 +791,19 @@ fn handle_race(
race.score = 0.0;
race.initialized = true;
spawn_target = true;
if let Ok(mut text) = q_scoredisplay.get_single_mut() {
text.sections[0].value = race.score.to_string();
}
if let Ok(mut vis) = q_scorewrapper.get_single_mut() {
*vis = Visibility::Inherited;
}
}
if player_pos.distance(target_pos.0) < RACE_TARGET_RADIUS {
race.score += 1.0;
if let Ok(mut text) = q_scoredisplay.get_single_mut() {
text.sections[0].value = race.score.to_string();
}
spawn_target = true;
}
@ -823,5 +838,8 @@ fn handle_race(
settings.race_active = false;
*target_vis = Visibility::Hidden;
commands.entity(target_entity).remove::<RigidBody>();
if let Ok(mut vis) = q_scorewrapper.get_single_mut() {
*vis = Visibility::Hidden;
}
}
}

View file

@ -147,6 +147,10 @@ struct Speedometer2;
#[derive(Component)]
struct GaugeLength(f32);
#[derive(Component)]
pub struct SkyRaceScoreWrapper;
#[derive(Component)]
pub struct SkyRaceScoreDisplay;
#[derive(Component)]
pub struct ToggleableHudElement;
#[derive(Component)]
pub struct ToggleableHudMapElement;
@ -389,6 +393,12 @@ pub fn setup(
color: settings.hud_color_speedometer,
..default()
};
let style_skyrace = TextStyle {
font: font_handle.clone(),
font_size: settings.font_size_skyrace_score,
color: settings.hud_color_skyrace_score,
..default()
};
let style = TextStyle {
font: font_handle,
font_size: settings.font_size_hud,
@ -742,6 +752,47 @@ pub fn setup(
));
});
// SkyRace score display
commands
.spawn((
NodeBundle {
style: Style {
width: Val::Vw(100.0),
align_items: AlignItems::Center,
flex_direction: FlexDirection::Column,
position_type: PositionType::Absolute,
top: Val::Vh(10.0),
left: Val::Px(0.0),
..default()
},
visibility: Visibility::Hidden,
..default()
},
SkyRaceScoreWrapper,
))
.with_children(|builder| {
builder.spawn((
TextBundle {
text: Text {
sections: vec![TextSection::new("skyrace-score", style_skyrace)],
justify: JustifyText::Center,
..default()
},
style: Style {
max_width: Val::Percent(50.0),
margin: UiRect {
top: Val::Vh(1.0),
..default()
},
..default()
},
..default()
},
SkyRaceScoreDisplay,
ToggleableHudElement,
));
});
// Selectagon
let mut entitycmd = commands.spawn((
Selectagon,

View file

@ -58,6 +58,7 @@ pub struct Settings {
pub font_size_choices: f32,
pub font_size_console: f32,
pub font_size_speedometer: f32,
pub font_size_skyrace_score: f32,
pub font_size_deathtext: f32,
pub font_size_deathsubtext: f32,
pub font_size_deathpoem: f32,
@ -77,6 +78,7 @@ pub struct Settings {
pub hud_color_subtitles: Color,
pub hud_color_choices: Color,
pub hud_color_speedometer: Color,
pub hud_color_skyrace_score: Color,
pub hud_color_deathpoem: Color,
pub hud_color_achievement: Color,
pub hud_color_achievement_header: Color,
@ -206,6 +208,7 @@ impl Default for Settings {
font_size_choices: 28.0,
font_size_console: 20.0,
font_size_speedometer: 34.0,
font_size_skyrace_score: 64.0,
font_size_deathtext: 64.0,
font_size_deathsubtext: 32.0,
font_size_deathpoem: 18.0,
@ -225,6 +228,7 @@ impl Default for Settings {
hud_color_subtitles: Srgba::hex(COLOR_SECONDARY).unwrap().into(),
hud_color_choices: Srgba::hex(COLOR_BODY).unwrap().into(),
hud_color_speedometer: Srgba::hex(COLOR_PRIMARY).unwrap().into(),
hud_color_skyrace_score: Srgba::hex(COLOR_PRIMARY).unwrap().into(),
hud_color_deathpoem: Srgba::hex("#CC2200").unwrap().into(),
hud_color_achievement: Srgba::hex(COLOR_DIM).unwrap().into(),
hud_color_achievement_accomplished: Srgba::hex(COLOR_SUCCESS).unwrap().into(),