# Game Dev Tools
> Reusable Bevy game development utilities for 2D games
[](https://crates.io/crates/game-dev-tools)
[](https://docs.rs/game-dev-tools)
[](LICENSE-MIT)
A collection of battle-tested game development utilities extracted from real game projects. Built for [Bevy](https://bevyengine.org/) 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`:
```toml
[dependencies]
game-dev-tools = "0.1"
bevy = "0.17"
```
Basic setup:
```rust
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:
```rust
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:
```rust
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:
```rust
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:
```rust
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:
```rust
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:
```rust
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:
```rust
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:
```rust
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:
```bash
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:
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE))
- MIT license ([LICENSE-MIT](LICENSE-MIT))
at your option.
## 🎮 Built With This
Share your game if you use this library! Open an issue to add yours here.
## 🔗 Links
- [Documentation](https://docs.rs/game-dev-tools)
- [Crates.io](https://crates.io/crates/game-dev-tools)
- [Repository](https://github.com/nitesh545/game-dev-tools)
- [Bevy](https://bevyengine.org/)
---
**Note**: This library requires Bevy 0.17 or later.