A Bevy game engine template designed for indie game developers. This template provides a solid foundation with organized modules for components, systems, resources, states, and plugins.
- ๐ฎ Bevy game engine with ECS architecture
- ๐ Organized folder structure for game development
- ๐งฉ Modular plugin system
- ๐ฏ Game state management (Loading, Menu, Playing, Paused, GameOver)
- ๐ Movement and physics components
- ๐ค Auto-movement system for obstacles and NPCs
- ๐ฅ AABB collision detection system
- ๐ฏ Dynamic obstacle spawning with randomization
- ๐ท Smooth camera follow system
- ๐จ User interface with score display and health bar
- โค๏ธ Health and combat systems
- ๐ต Audio and settings resources
- ๐งช Comprehensive test suite
- ๐ CI/CD with GitHub Actions
- ๐ฆ Cross-platform builds
- ๐ณ Docker support
- โ๏ธ Nix flakes for reproducible environments
git clone https://github.com/pnstack/template-bevy.git
cd template-bevy
cargo build --releaseFor faster compile times during development, use the dev feature:
cargo run --features devDownload the latest binary from the Releases page.
# Development build (faster compilation)
cargo run --features dev
# Release build (optimized)
cargo run --release- A/D or Arrow Left/Right - Move player horizontally
- Spacebar - Jump (only when on ground)
- ESC - Quit game
template-bevy/
โโโ .github/workflows/ # CI/CD workflows
โโโ src/
โ โโโ components/ # ECS components (Player, Health, Speed, etc.)
โ โโโ systems/ # ECS systems (movement, setup, etc.)
โ โโโ resources/ # Global resources (Score, Settings, Timer)
โ โโโ states/ # Game states (Loading, Menu, Playing, etc.)
โ โโโ plugins/ # Custom Bevy plugins
โ โโโ game/ # Core game logic and constants
โ โโโ lib.rs # Library root
โ โโโ main.rs # Application entry point
โโโ assets/
โ โโโ textures/ # Sprites and images
โ โโโ audio/ # Music and sound effects
โ โโโ fonts/ # Custom fonts
โโโ tests/ # Integration tests
โโโ examples/ # Usage examples
โโโ docs/ # Documentation
Components are data containers attached to entities:
use template_bevy::components::{Player, Health, Speed};
// Spawn a player entity
commands.spawn((
Player,
Health::new(100.0),
Speed(200.0),
Transform::default(),
));Systems process entities with specific components:
fn player_movement(
keyboard_input: Res<ButtonInput<KeyCode>>,
mut query: Query<(&Speed, &mut Transform), With<Player>>,
) {
// Movement logic here
}Resources are global state:
use template_bevy::resources::{Score, GameSettings};
fn update_score(mut score: ResMut<Score>) {
score.add(100);
}States control game flow:
use template_bevy::states::GameState;
app.add_systems(Update, gameplay_system.run_if(in_state(GameState::Playing)));The template includes several ready-to-use systems:
Entities with the AutoMove component will automatically move in the specified direction:
use template_bevy::components::{AutoMove, Obstacle};
// Create an obstacle that moves left
commands.spawn((
Obstacle,
AutoMove::left(150.0), // Speed of 150 pixels/second
// ... other components
));The spawn_obstacles system automatically spawns obstacles at regular intervals with random properties (position, size, speed).
The camera automatically follows the player with smooth interpolation:
use template_bevy::components::{CameraFollow, MainCamera};
// Camera will smoothly follow the target
commands.spawn((
MainCamera,
CameraFollow::new(player_entity)
.with_offset(Vec3::new(0.0, 50.0, 0.0))
.with_smoothing(0.05),
Camera2dBundle::default(),
));AABB collision detection between player and obstacles:
- Platform collisions for landing and ground detection
- Obstacle collisions that apply damage to the player
Built-in UI components for displaying game information:
- Score Display: Shows current score in the top-left corner
- Health Bar: Visual health indicator with color changes based on health level
- Rust 1.70 or later
- For Linux:
libasound2-dev,libudev-dev(audio and input support)
# Ubuntu/Debian
sudo apt-get install libasound2-dev libudev-dev
# Fedora
sudo dnf install alsa-lib-devel systemd-devel# Debug build
cargo build
# Release build (optimized)
cargo build --release
# Development build with dynamic linking (faster iteration)
cargo build --features devcargo testcargo clippy -- -D warningscargo fmt- Create the component in
src/components/mod.rs:
#[derive(Component, Debug)]
pub struct Enemy {
pub damage: f32,
}- Export it in the module.
- Create a new file in
src/systems/:
pub fn enemy_ai(query: Query<&Transform, With<Enemy>>) {
// AI logic
}- Export it in
src/systems/mod.rs - Register it in
src/plugins/mod.rs
- Add the state variant in
src/states/mod.rs - Add state-specific systems in your plugin
- Use
--features devduring development for faster compile times - Use
--releasefor testing actual game performance - The template includes optimized dependency builds by default
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.