PIRWNPUWHOJIQBBYAV5UBILX3ZO4VPOJ3X7SERCX2SYJXOXY2O6AC
SystemSet::on_update(RaceState::Running).with_system(racers_movement_system),
SystemSet::on_update(RaceState::Running)
.with_system(racers_movement_system.label("move"))
.with_system(track_visualisation_system.label("display").after("move"))
.with_system(determine_end_system.after("display")),
fn race_end_system(mut app_exit_events: EventWriter<AppExit>, query: Query<(&Racer, &Position)>) {
println!("The race is over");
for (r, p) in query.iter() {
println!("Racer {} at {:?}", r.0, p.0);
fn determine_end_system(mut state: ResMut<State<RaceState>>, query: Query<&Position>) {
if query.iter().map(|p| p.0).reduce(f32::max).unwrap() >= TRACK_LENGTH {
state.replace(RaceState::Finished).unwrap();
}
fn track_visualisation_system(racers_query: Query<(&Racer, &Position, &Velocity)>) {
for (r, p, v) in racers_query.iter() {
let progression = ((p.0 / TRACK_LENGTH * 100.).round() as usize).min(100);
print!(
"{:-^l$}#{:-^r$}",
"",
"",
l = progression,
r = 100 - progression
);
println!(" Racer {} position {}, velocity {}", r.0, p.0, v.0);
}
println!("");