Skills

Bevy Game Loop Time Trial

Run a Bevy 0.20 time trial as ECS data.

Install

npx skills add thedivergentai/Game-Dev-Agentic-Skills --skill bevy-game-loop-time-trial -g -a claude-code -y
Category
Engineering
Updated
19d ago
License
LGPL-3.0
Context cost
Mediumabout 2,034 tokens
Runs scripts
No, instructions only

What it does

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.
[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.

#[derive(Resource)]
struct RaceClock {
    elapsed: f32,
    splits: Vec<f32>,
    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<Time>, mut clock: ResMut<RaceClock>) {
    if !clock.finished {
        clock.elapsed += time.delta_secs();
    }
}

#[derive(Component)]
struct SplitGate {
    at_x: f32,
    taken: bool,
}
Read the whole SKILL.md on GitHub

More in Engineering