--- name: bevy-game-loop-time-trial description: "Run a Bevy 0.20 time trial as ECS data. Use when a race clock, split gates, and a finish line share one resource and must be chained, while movement steps on FixedUpdate. Keywords: Bevy, time trial, RaceClock, SplitGate, FixedUpdate, chain." --- # Bevy time-trial loop ## When to use Load this when a run records elapsed time, splits, or a finish line. ## ECS shape - **Components:** a racer marker and a finish volume. - **Resources:** the race clock, split list, and best time live on one resource. - **Systems:** tick the clock, record a split, then test the finish line, in that order with `.chain()`. - **Messages:** one-shot facts (hit, pickup, quest advance) go through bevy-events-messaging. This file does not add a new event type name. ```toml [package] name = "time-trial" version = "0.1.0" edition = "2021" [dependencies] bevy = "0.20" ``` The race clock is one resource. Three systems write it, so they share one chain. ```rust #[derive(Resource)] struct RaceClock { elapsed: f32, splits: Vec, finished: bool, best: f32, } #[derive(Component)] struct Racer; #[derive(Component)] struct FinishLine; fn spawn_course(mut commands: Commands) { commands.insert_resource(RaceClock { elapsed: 0.0, splits: Vec::new(), finished: false, best: f32::MAX, }); commands.spawn((Racer, Transform::from_xyz(0.0, 0.0, 0.0))); commands.spawn((FinishLine, Transform::from_xyz(10.0, 0.0, 0.0))); commands.spawn(SplitGate { at_x: 5.0, taken: false, }); } fn tick_race(time: Res