
Bevy Game Loop Harvest
Bevy ECS harvest loop: Crop stage on Time<Fixed>, season scale, catch-up from a...
Install
npx skills add thedivergentai/Game-Dev-Agentic-Skills --skill bevy-game-loop-harvest -g -a claude-code -y- Repository
- thedivergentai/Game-Dev-Agentic-Skills917
- Category
- Marketing
- Updated
- 19d ago
- License
- LGPL-3.0
- Context cost
- Mediumabout 2,064 tokens
- Runs scripts
- No, instructions only
What it does
Bevy ECS harvest loop: Crop stage on Time<Fixed>, season scale, catch-up from a LastVisit resource, Harvested messages. Use when growth must finish before the yield message. Keywords: Bevy, harvest, crop, FixedUpdate, season, catch-up.
Bevy harvest loop
When to use
Load this when crops advance on a timer and a harvest message records the yield.
ECS shape
- Components: growth elapsed and a stage index you define.
- Resources: the last visit and the season scale live in resources (bevy-data-resources).
- Systems: step growth on
FixedUpdate. Use.chain()so harvest reads the stage growth just wrote. - Messages:
Harvestedis the one-shot yield fact. Inventory applies it in bevy-inventory-system.
Idioms
| Need | Bevy shape |
|---|---|
| Growth | Elapsed time on a component, stepped on the fixed clock. |
| Extract | A Harvested message. Inventory consumes it. |
| Season | A resource scale. No calendar type was opened. |
Scope
- A crop component stores stage and elapsed time. Growth steps on
Time<Fixed>. - Offline catch-up reads
Time::elapsed_secsagainst a resource that remembers the last visit.
Examples
[package]
name = "harvest"
version = "0.1.0"
edition = "2021"
[dependencies]
bevy = "0.20"
Growth advances one stage per interval. Harvest only fires when the last stage is ready.
#[derive(Component)]
struct Crop {
stage: u8,
elapsed: f32,
stage_seconds: f32,
stages: u8,
}
#[derive(Message)]
struct Harvested {
plot: Entity,
yield_item: u32,
}
fn grow(time: Res<Time<Fixed>>, mut crops: Query<&mut Crop>) {
let dt = time.delta_secs();
for mut crop in &mut crops {
if crop.stage + 1 >= crop.stages {
continue;
}
crop.elapsed += dt;
if crop.elapsed >= crop.stage_seconds {
crop.elapsed = 0.0;
crop.stage += 1;
}
}
}
