Skills

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
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: Harvested is the one-shot yield fact. Inventory applies it in bevy-inventory-system.

Idioms

NeedBevy shape
GrowthElapsed time on a component, stepped on the fixed clock.
ExtractA Harvested message. Inventory consumes it.
SeasonA 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_secs against 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;
        }
    }
}
Read the whole SKILL.md on GitHub

More in Marketing