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:
fnplayer_movement(keyboard_input:Res<ButtonInput<KeyCode>>,mutquery:Query<(&Speed,&mutTransform),With<Player>>,){// Movement logic here}Resources are global state:
use template_bevy::resources::{Score,GameSettings};fnupdate_score(mutscore: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)]pubstructEnemy{pubdamage:f32,}- Export it in the module.
- Create a new file in
src/systems/:
pubfnenemy_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.