Expand description
ยงGame Dev Tools
Reusable Bevy game development utilities for 2D games
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 sparksParticle::smoke()- Expanding smoke cloudsParticleBehavior::explosion()- Gravity + dragParticleBehavior::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 fullscreenF12- Show FPS (requiresFrameTimeDiagnosticsPlugin)
ยง๐ ๏ธ 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/healLives- Life systemVelocity- 2D velocitySpacePhysics- Space-like movement with momentumProjectile- Projectile with damage and optional lifetimeParticle- Animated particle with color/size interpolationParticleB behavior- Gravity, drag, and rotation for particlesParallaxLayer- Parallax scrolling layerCinematicCamera- Camera with effects
ยงResources
ScreenShake- Global screen shake controllerAudioSettings- Master, SFX, and music volumeAudioState- Current audio stateMouseWorldPos- Mouse position in world spaceCameraMovement- Camera velocity trackingGameDevConfig- Framework configuration
ยงSystems
All systems are automatically added by GameDevToolsPlugin:
unified_camera_shake_system- Applies screen shakeupdate_particles- Updates particle effectsapply_velocity- Applies velocity to transformsupdate_camera_movement- Tracks camera velocityupdate_parallax_layers- Updates parallax scrollingupdate_mouse_world_position- Updates mouse world positiontoggle_fullscreen- F11 to toggle fullscreenaudio_controls- M to mute, +/- for volume
ยง๐ฏ Examples
Run examples with:
cargo run --example basic_setupSee the examples/ directory for:
basic_setup.rs- Minimal setup with screen shakeparticles.rs- Particle system showcaseparallax.rs- Parallax background demophysics.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:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.
ยง๐ฎ Built With This
Share your game if you use this library! Open an issue to add yours here.
ยง๐ Links
Note: This library requires Bevy 0.17 or later.