| Crates.io | game-dev-tools |
| lib.rs | game-dev-tools |
| version | 0.1.1 |
| created_at | 2025-10-10 18:58:44.356276+00 |
| updated_at | 2025-10-10 19:05:06.315323+00 |
| description | Reusable Bevy game development utilities for 2D games |
| homepage | |
| repository | https://github.com/yourusername/game-dev-tools |
| max_upload_size | |
| id | 1877386 |
| size | 167,682 |
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+.
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);
}
}
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
}
}
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 debrisSimple 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 volumeMulti-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,
},
));
}
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);
}
}
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
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 (requires FrameTimeDiagnosticsPlugin)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();
}
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 effectsScreenShake - Global screen shake controllerAudioSettings - Master, SFX, and music volumeAudioState - Current audio stateMouseWorldPos - Mouse position in world spaceCameraMovement - Camera velocity trackingGameDevConfig - Framework configurationAll 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 volumeRun examples with:
cargo run --example basic_setup
See the examples/ directory for:
basic_setup.rs - Minimal setup with screen shakeparticles.rs - Particle system showcaseparallax.rs - Parallax background demophysics.rs - Space physics demoContributions welcome! This library is extracted from real game projects and is designed to be practical and reusable.
Licensed under either of:
at your option.
Share your game if you use this library! Open an issue to add yours here.
Note: This library requires Bevy 0.17 or later.