Skip to content
Bevy Game Engine logo

Bevy Game Engine

Data-driven game engine with ECS architecture.

SKILL.md

Full skill instructions

Bevy Standards

App Setup

use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .add_systems(Update, (movement, collision).chain())
        .run();
}

fn setup(mut commands: Commands) {
    commands.spawn(Camera2dBundle::default());
}

Components

#[derive(Component)]
struct Player {
    speed: f32,
}

#[derive(Component)]
struct Health(u32);

#[derive(Component)]
struct Velocity(Vec2);

// Spawn entity with components
fn spawn_player(mut commands: Commands) {
    commands.spawn((
        Player { speed: 200.0 },
        Health(100),
        Velocity(Vec2::ZERO),
        SpriteBundle {
            transform: Transform::from_xyz(0.0, 0.0, 0.0),
            ..default()
        },
    ));
}

Systems

// Query components
fn movement(
    time: Res<Time>,
    input: Res<Input<KeyCode>>,
    mut query: Query<(&Player, &mut Transform, &mut Velocity)>,
) {
    for (player, mut transform, mut velocity) in &mut query {
        let mut direction = Vec2::ZERO;
        if input.pressed(KeyCode::W) { direction.y += 1.0; }
        if input.pressed(KeyCode::S) { direction.y -= 1.0; }
        if input.pressed(KeyCode::A) { direction.x -= 1.0; }
        if input.pressed(KeyCode::D) { direction.x += 1.0; }

        velocity.0 = direction.normalize_or_zero() * player.speed;
        transform.translation += velocity.0.extend(0.0) * time.delta_seconds();
    }
}

// Filter queries
fn damage_enemies(
    mut query: Query<&mut Health, (With<Enemy>, Without<Player>)>,
) {
    for mut health in &mut query {
        health.0 = health.0.saturating_sub(10);
    }
}

Resources

#[derive(Resource)]
struct GameState {
    score: u32,
    level: u32,
}

#[derive(Resource, Default)]
struct GameAssets {
    player_texture: Handle<Image>,
}

// Insert resource
app.insert_resource(GameState { score: 0, level: 1 });

// Access in system
fn update_score(mut state: ResMut<GameState>) {
    state.score += 10;
}

Events

#[derive(Event)]
struct CollisionEvent {
    entity_a: Entity,
    entity_b: Entity,
}

// Send event
fn detect_collision(mut events: EventWriter<CollisionEvent>) {
    events.send(CollisionEvent { entity_a, entity_b });
}

// Read events
fn handle_collision(mut events: EventReader<CollisionEvent>) {
    for event in events.read() {
        println!("Collision: {:?} <-> {:?}", event.entity_a, event.entity_b);
    }
}

// Register event
app.add_event::<CollisionEvent>();

States

#[derive(States, Debug, Clone, Eq, PartialEq, Hash, Default)]
enum GameState {
    #[default]
    Menu,
    Playing,
    Paused,
    GameOver,
}

app.add_state::<GameState>()
   .add_systems(OnEnter(GameState::Playing), start_game)
   .add_systems(OnExit(GameState::Playing), cleanup_game)
   .add_systems(Update, game_logic.run_if(in_state(GameState::Playing)));

// Change state
fn pause_game(mut next_state: ResMut<NextState<GameState>>) {
    next_state.set(GameState::Paused);
}

Assets

fn load_assets(
    mut commands: Commands,
    asset_server: Res<AssetServer>,
) {
    let texture = asset_server.load("player.png");
    commands.insert_resource(GameAssets { player_texture: texture });
}

// Spawn with texture
fn spawn_sprite(
    mut commands: Commands,
    assets: Res<GameAssets>,
) {
    commands.spawn(SpriteBundle {
        texture: assets.player_texture.clone(),
        ..default()
    });
}

Plugins

pub struct PlayerPlugin;

impl Plugin for PlayerPlugin {
    fn build(&self, app: &mut App) {
        app.add_systems(Startup, spawn_player)
           .add_systems(Update, (movement, animation));
    }
}

// Use plugin
app.add_plugins(PlayerPlugin);

Best Practices

  1. ECS: Prefer composition over inheritance
  2. Systems: Keep small, single responsibility
  3. Queries: Use filters (With, Without) for performance
  4. Resources: For global state, not per-entity data
  5. Events: Decouple systems, avoid direct dependencies

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View