Crate game_dev_tools

Crate game_dev_tools 

Source
Expand description

ยงGame Dev Tools

Reusable Bevy game development utilities for 2D games

Crates.io Documentation License

A collection of battle-tested game development utilities extracted from real game projects. Built for Bevy 0.17+.

ยงโœจ Features

  • ๐ŸŽฅ Camera Effects: Screen shake, bloom, cinematic controls
  • ๐Ÿ’ฅ Particle System: Explosions, smoke, trails, and custom effects
  • ๐ŸŽต Audio Management: Easy sound effects and music playback
  • ๐ŸŒŒ Parallax Backgrounds: Multi-layer scrolling with automatic wrapping
  • โค๏ธ Health System: Health, lives, and damage tracking
  • ๐ŸŽฎ Input Utilities: Mouse world position tracking, fullscreen toggle
  • ๐Ÿš€ Physics Helpers: Space physics, velocity system, distance-based cleanup

ยง๐Ÿš€ Quick Start

Add to your Cargo.toml:

[dependencies]
game-dev-tools = "0.1"
bevy = "0.17"

Basic setup:

use bevy::prelude::*;
use game_dev_tools::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugins(GameDevToolsPlugin)
        .add_systems(Startup, setup)
        .add_systems(Update, gameplay)
        .run();
}

fn setup(mut commands: Commands) {
    // Setup camera with cinematic effects
    camera::setup_cinematic_camera(&mut commands);
}

fn gameplay(
    mut commands: Commands,
    mut shake: ResMut<ScreenShake>,
    keyboard: Res<ButtonInput<KeyCode>>,
) {
    if keyboard.just_pressed(KeyCode::Space) {
        // Trigger screen shake
        shake.trigger(30.0, 0.5);

        // Spawn explosion particles
        spawn_explosion_particles(&mut commands, Vec2::ZERO, 10, 1.0);
    }
}

ยง๐Ÿ“š Feature Guide

ยง๐ŸŽฅ Screen Shake

Add dramatic impact to your game with configurable screen shake:

fn collision_system(mut shake: ResMut<ScreenShake>) {
    // Light shake
    shake.trigger(15.0, 0.2);

    // Heavy shake
    shake.trigger(50.0, 0.8);

    // Check if shaking
    if shake.is_active() {
        // Do something while shaking
    }
}

ยง๐Ÿ’ฅ Particle System

Create stunning visual effects:

fn spawn_effects(mut commands: Commands) {
    // Explosion particles
    spawn_explosion_particles(&mut commands, position, 20, 1.5);

    // Custom particle
    commands.spawn((
        Sprite { /* ... */ },
        Transform::from_translation(position.extend(0.0)),
        Particle::new(
            1.0,  // lifetime
            Color::srgb(1.0, 0.5, 0.0),  // start color
            Color::srgba(1.0, 0.0, 0.0, 0.0),  // end color
            10.0,  // start size
            2.0,   // end size
        ),
        ParticleBehavior::explosion(),
        Velocity(Vec2::new(100.0, 100.0)),
    ));
}

Preset particles:

  • Particle::explosion_spark() - Bright explosion sparks
  • Particle::smoke() - Expanding smoke clouds
  • ParticleBehavior::explosion() - Gravity + drag
  • ParticleBehavior::floating() - Gentle floating debris

ยง๐ŸŽต Audio System

Simple audio management with volume controls:

fn shoot_system(
    mut commands: Commands,
    asset_server: Res<AssetServer>,
    audio_settings: Res<AudioSettings>,
    audio_state: Res<AudioState>,
) {
    play_sound_effect(
        &mut commands,
        &asset_server,
        &audio_settings,
        "sounds/laser.ogg",
        0.8,  // volume multiplier
        &audio_state,
    );
}

Built-in keyboard controls:

  • M - Toggle mute
  • +/- - Adjust volume

ยง๐ŸŒŒ Parallax Backgrounds

Multi-layer scrolling backgrounds that follow the camera:

fn setup_background(mut commands: Commands) {
    // Far background
    commands.spawn((
        Sprite { /* ... */ },
        Transform::from_xyz(0.0, 0.0, -100.0),
        ParallaxLayer {
            speed_multiplier: 0.1,  // Slow movement (far away)
            layer_depth: -100.0,
            wrap_distance: 2000.0,
            original_position: Vec2::ZERO,
        },
    ));

    // Close foreground
    commands.spawn((
        Sprite { /* ... */ },
        Transform::from_xyz(0.0, 0.0, -10.0),
        ParallaxLayer {
            speed_multiplier: 0.8,  // Fast movement (close)
            layer_depth: -10.0,
            wrap_distance: 1000.0,
            original_position: Vec2::ZERO,
        },
    ));
}

ยงโค๏ธ Health System

Track health and lives for any entity:

fn setup_player(mut commands: Commands) {
    commands.spawn((
        Sprite { /* ... */ },
        Health::new(100.0),
        Lives::new(3),
    ));
}

fn damage_system(mut query: Query<(&mut Health, &mut Lives)>) {
    for (mut health, mut lives) in query.iter_mut() {
        // Take damage
        let is_dead = health.take_damage(25.0);

        if is_dead {
            // Health depleted, lose a life
            let game_over = lives.take_damage();

            if !game_over {
                // Restore health
                health.current = health.max;
            }
        }

        // Check health percentage
        let hp_percent = health.percentage();

        // Heal
        health.heal(10.0);
    }
}

ยง๐Ÿš€ Physics System

Space-like physics with momentum and drag:

fn setup_ship(mut commands: Commands) {
    commands.spawn((
        Sprite { /* ... */ },
        SpacePhysics {
            max_thrust: 500.0,
            drag_coefficient: 0.98,  // 2% drag per frame
            max_speed: 600.0,
            ..default()
        },
        Velocity(Vec2::ZERO),
    ));
}

fn movement_system(
    mut query: Query<&mut SpacePhysics>,
    keyboard: Res<ButtonInput<KeyCode>>,
) {
    for mut physics in query.iter_mut() {
        let mut thrust = Vec2::ZERO;

        if keyboard.pressed(KeyCode::KeyW) {
            thrust.y = 1.0;
        }

        physics.acceleration = thrust * physics.max_thrust;
    }
}

// Velocity is automatically applied by the plugin

ยง๐ŸŽฎ Input Utilities

Get mouse position in world coordinates:

fn aiming_system(
    mouse_pos: Res<MouseWorldPos>,
    player_query: Query<&Transform, With<Player>>,
) {
    if let Ok(player_transform) = player_query.get_single() {
        let direction = mouse_pos.0 - player_transform.translation.truncate();
        let angle = direction.y.atan2(direction.x);
        // Use angle for aiming
    }
}

Built-in keyboard shortcuts:

  • F11 - Toggle fullscreen
  • F12 - Show FPS (requires FrameTimeDiagnosticsPlugin)

ยง๐Ÿ› ๏ธ Configuration

Customize the framework for your game:

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .insert_resource(GameDevConfig {
            window_width: 1920.0,
            window_height: 1080.0,
            max_projectile_distance: 3000.0,
            max_entity_distance: 2000.0,
            max_particle_distance: 1500.0,
        })
        .add_plugins(GameDevToolsPlugin)
        .run();
}

ยง๐Ÿ“ฆ Whatโ€™s Included

ยงComponents

  • Health - Health tracking with damage/heal
  • Lives - Life system
  • Velocity - 2D velocity
  • SpacePhysics - Space-like movement with momentum
  • Projectile - Projectile with damage and optional lifetime
  • Particle - Animated particle with color/size interpolation
  • ParticleB behavior - Gravity, drag, and rotation for particles
  • ParallaxLayer - Parallax scrolling layer
  • CinematicCamera - Camera with effects

ยงResources

  • ScreenShake - Global screen shake controller
  • AudioSettings - Master, SFX, and music volume
  • AudioState - Current audio state
  • MouseWorldPos - Mouse position in world space
  • CameraMovement - Camera velocity tracking
  • GameDevConfig - Framework configuration

ยงSystems

All systems are automatically added by GameDevToolsPlugin:

  • unified_camera_shake_system - Applies screen shake
  • update_particles - Updates particle effects
  • apply_velocity - Applies velocity to transforms
  • update_camera_movement - Tracks camera velocity
  • update_parallax_layers - Updates parallax scrolling
  • update_mouse_world_position - Updates mouse world position
  • toggle_fullscreen - F11 to toggle fullscreen
  • audio_controls - M to mute, +/- for volume

ยง๐ŸŽฏ Examples

Run examples with:

cargo run --example basic_setup

See the examples/ directory for:

  • basic_setup.rs - Minimal setup with screen shake
  • particles.rs - Particle system showcase
  • parallax.rs - Parallax background demo
  • physics.rs - Space physics demo

ยง๐Ÿค Contributing

Contributions welcome! This library is extracted from real game projects and is designed to be practical and reusable.

ยง๐Ÿ“„ License

Licensed under either of:

at your option.

ยง๐ŸŽฎ Built With This

Share your game if you use this library! Open an issue to add yours here.


Note: This library requires Bevy 0.17 or later.

Modulesยง

game_dev_tools