https://github.com/pnstack/template-bevy
https://github.com/pnstack/template-bevy
bevy game rust template
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/pnstack/template-bevy
- Owner: pnstack
- Created: 2025-12-04T05:14:52.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-12-06T04:46:01.000Z (7 months ago)
- Last Synced: 2025-12-08T12:23:29.257Z (7 months ago)
- Topics: bevy, game, rust, template
- Language: Rust
- Homepage:
- Size: 84 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Template Bevy
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.
## Features
- ๐ฎ 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
## Installation
### From Source
```bash
git clone https://github.com/pnstack/template-bevy.git
cd template-bevy
cargo build --release
```
### Quick Development Build
For faster compile times during development, use the `dev` feature:
```bash
cargo run --features dev
```
### From Releases
Download the latest binary from the [Releases](https://github.com/pnstack/template-bevy/releases) page.
## Usage
### Running the Game
```bash
# Development build (faster compilation)
cargo run --features dev
# Release build (optimized)
cargo run --release
```
### Controls
- **A/D** or **Arrow Left/Right** - Move player horizontally
- **Spacebar** - Jump (only when on ground)
- **ESC** - Quit game
## Project Structure
```
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
```
## Architecture
### Components
Components are data containers attached to entities:
```rust
use template_bevy::components::{Player, Health, Speed};
// Spawn a player entity
commands.spawn((
Player,
Health::new(100.0),
Speed(200.0),
Transform::default(),
));
```
### Systems
Systems process entities with specific components:
```rust
fn player_movement(
keyboard_input: Res>,
mut query: Query<(&Speed, &mut Transform), With>,
) {
// Movement logic here
}
```
### Resources
Resources are global state:
```rust
use template_bevy::resources::{Score, GameSettings};
fn update_score(mut score: ResMut) {
score.add(100);
}
```
### States
States control game flow:
```rust
use template_bevy::states::GameState;
app.add_systems(Update, gameplay_system.run_if(in_state(GameState::Playing)));
```
## Core Systems
The template includes several ready-to-use systems:
### Auto-Movement
Entities with the `AutoMove` component will automatically move in the specified direction:
```rust
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
));
```
### Obstacle Spawning
The `spawn_obstacles` system automatically spawns obstacles at regular intervals with random properties (position, size, speed).
### Camera Follow
The camera automatically follows the player with smooth interpolation:
```rust
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(),
));
```
### Collision Detection
AABB collision detection between player and obstacles:
- Platform collisions for landing and ground detection
- Obstacle collisions that apply damage to the player
### User Interface
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
## Development
### Prerequisites
- Rust 1.70 or later
- For Linux: `libasound2-dev`, `libudev-dev` (audio and input support)
```bash
# Ubuntu/Debian
sudo apt-get install libasound2-dev libudev-dev
# Fedora
sudo dnf install alsa-lib-devel systemd-devel
```
### Building
```bash
# Debug build
cargo build
# Release build (optimized)
cargo build --release
# Development build with dynamic linking (faster iteration)
cargo build --features dev
```
### Running Tests
```bash
cargo test
```
### Running Clippy (Linter)
```bash
cargo clippy -- -D warnings
```
### Formatting Code
```bash
cargo fmt
```
## Adding Game Content
### Adding a New Component
1. Create the component in `src/components/mod.rs`:
```rust
#[derive(Component, Debug)]
pub struct Enemy {
pub damage: f32,
}
```
2. Export it in the module.
### Adding a New System
1. Create a new file in `src/systems/`:
```rust
pub fn enemy_ai(query: Query<&Transform, With>) {
// AI logic
}
```
2. Export it in `src/systems/mod.rs`
3. Register it in `src/plugins/mod.rs`
### Adding a New State
1. Add the state variant in `src/states/mod.rs`
2. Add state-specific systems in your plugin
## Performance Tips
1. Use `--features dev` during development for faster compile times
2. Use `--release` for testing actual game performance
3. The template includes optimized dependency builds by default
## Contributing
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests for new functionality
5. Ensure all tests pass
6. Submit a pull request
## License
This project is licensed under either of
- Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
at your option.