# 🦎 Shadow Engine 2D
<div align="center">

**A modern, high-performance 2D game engine built in Rust**
[](https://crates.io/crates/shadow_engine_2d)
[](https://docs.rs/shadow_engine_2d)
[](https://opensource.org/licenses/MIT)
[](https://www.rust-lang.org/)
[Website](https://shadowteamengine-design.github.io/shadowengine2dwebsite/) • [Documentation](https://docs.rs/shadow_engine_2d) • [Examples](examples/) • [Discord](#)
*Powered by Shadow the Axolotl* 🖤
</div>
---
## ✨ Features
Shadow Engine 2D is a complete 2D game engine with everything you need to build amazing games:
### 🎮 Core Systems
- **Entity Component System (ECS)** - Clean, intuitive architecture for game objects
- **GPU Rendering** - Hardware-accelerated graphics with WGPU (Vulkan, DirectX 12, Metal)
- **Input Handling** - Keyboard and mouse support with easy-to-use API
- **Time Management** - Delta time and frame-independent movement
### ⚡ Physics
- **ShadowPhysics2D** - Custom-built physics engine
- Gravity and force simulation
- Box and circle colliders
- Collision detection and response
- Dynamic and kinematic rigid bodies
- Realistic physics behavior
### 🎨 Graphics & Effects
- **Sprite Rendering** - Fast, batched sprite rendering with colors
- **Texture System** - Load PNG, JPG, and other image formats
- **Particle System** - Stunning visual effects
- Continuous and burst emission modes
- Built-in presets (explosion, fire, smoke)
- Customizable emitters with gravity and velocity
- **Camera System** - Professional camera controls
- Smooth following with configurable speed
- Zoom in/out functionality
- Camera shake effects
- Bounded camera movement
### 🖼️ UI System
- **Flexible UI Components**
- Panels with customizable borders
- Interactive buttons with hover states
- Progress bars
- Anchor-based positioning (Center, TopLeft, TopRight, etc.)
### 🔊 Audio System
- **Sound Effects** - Play multiple sounds simultaneously
- **Background Music** - Looping music with volume control
- **Supported Formats** - WAV, OGG, MP3, FLAC
- **Volume Control** - Per-sound and global volume adjustment
---
## 🚀 Quick Start
### Installation
Add Shadow Engine 2D to your `Cargo.toml`:
```toml
[dependencies]
shadow_engine_2d = "2.0.1"
```
### Your First Game
```rust
use shadow_engine_2d::prelude::*;
use winit::keyboard::KeyCode;
fn main() {
let mut engine = Engine::builder()
.title("My Game")
.size(1280, 720)
.build();
// Spawn player with physics
let player = engine.world_mut().spawn();
if let Some(entity) = engine.world_mut().entity_mut(player) {
entity.add(Transform::new(0.0, 0.0));
entity.add(Sprite::new(50.0, 50.0).with_color(Color::CYAN));
entity.add(RigidBody::dynamic());
entity.add(Collider::box_collider(50.0, 50.0));
}
// Game loop
engine.run(|world, input, time| {
let speed = 300.0;
let dt = time.delta();
for entity in world.entities_mut() {
if let Some(transform) = entity.get_mut::<Transform>() {
if input.key_pressed(KeyCode::KeyW) {
transform.position.y -= speed * dt;
}
if input.key_pressed(KeyCode::KeyS) {
transform.position.y += speed * dt;
}
if input.key_pressed(KeyCode::KeyA) {
transform.position.x -= speed * dt;
}
if input.key_pressed(KeyCode::KeyD) {
transform.position.x += speed * dt;
}
}
}
});
}
```
---
## 📚 Examples
Shadow Engine 2D comes with comprehensive examples:
### Basic Game
```bash
cargo run --example basic_game
```
Simple player movement with WASD controls.
### Physics Demo
```bash
cargo run --example physics_demo
```
Platformer with gravity, jumping, and collisions.
### Particles & Camera
```bash
cargo run --example particles_camera_demo
```
Particle effects with camera following and zoom.
### UI Demo
```bash
cargo run --example ui_demo
```
Health bars, buttons, and UI panels.
### Audio Demo
```bash
cargo run --example audio_demo
```
Sound effects and background music.
---
## 🎯 Core Concepts
### Entity Component System
Shadow Engine 2D uses an intuitive ECS architecture:
```rust
// Spawn an entity
let entity_id = world.spawn();
// Add components
if let Some(entity) = world.entity_mut(entity_id) {
entity.add(Transform::new(100.0, 200.0));
entity.add(Sprite::new(32.0, 32.0).with_color(Color::RED));
entity.add(RigidBody::dynamic());
}
// Query entities
for entity in world.entities() {
if let Some(transform) = entity.get::<Transform>() {
println!("Position: {:?}", transform.position);
}
}
```
### Physics System
```rust
let physics = PhysicsSystem::new();
// Create a dynamic body
entity.add(RigidBody::dynamic()
.with_velocity(Vec2::new(100.0, 0.0))
.with_mass(2.0)
.with_drag(0.1));
entity.add(Collider::box_collider(50.0, 50.0));
// Update physics in game loop
physics.update(world, dt);
let collisions = physics.detect_collisions(world);
physics.resolve_collisions(world, &collisions);
// Apply forces
if let Some(body) = entity.get_mut::<RigidBody>() {
body.apply_force(Vec2::new(1000.0, 0.0));
body.apply_impulse(Vec2::new(0.0, -500.0)); // Jump!
}
```
### Particle System
```rust
let mut particle_system = ParticleSystem::new();
// Create particle emitter
let emitter_id = world.spawn();
if let Some(entity) = world.entity_mut(emitter_id) {
entity.add(Transform::new(0.0, 0.0));
entity.add(ParticleEmitter::explosion());
// or ParticleEmitter::fire()
// or ParticleEmitter::smoke()
}
// Update particles
particle_system.update(world, dt);
```
### Camera System
```rust
let mut camera = Camera::new();
// Follow an entity
camera.follow(player_id);
camera.follow_speed = 5.0;
// Zoom
camera.zoom(1.5);
// Camera shake
camera.shake(10.0, 0.5); // intensity, duration
// Update camera
camera.update(world, dt);
```
### Audio System
```rust
let mut audio = AudioSystem::new().unwrap();
// Load sounds
audio.load_sound("jump", "assets/sounds/jump.wav").unwrap();
audio.load_sound("coin", "assets/sounds/coin.wav").unwrap();
// Play sound effects
audio.play_sound("jump").unwrap();
audio.play_sound_with_volume("coin", 0.7).unwrap();
// Background music
audio.play_music("assets/music/background.mp3").unwrap();
audio.set_music_volume(0.5);
audio.pause_music();
audio.resume_music();
```
### UI System
```rust
// Create a health bar
let health_bar = world.spawn();
if let Some(entity) = world.entity_mut(health_bar) {
entity.add(UITransform::new(Anchor::TopLeft)
.with_offset(Vec2::new(20.0, 20.0)));
entity.add(UIProgressBar::new(200.0, 30.0)
.with_value(0.75)
.with_color(Color::GREEN));
}
// Create a button
let button = world.spawn();
if let Some(entity) = world.entity_mut(button) {
entity.add(UITransform::new(Anchor::Center));
entity.add(UIButton::new());
entity.add(UIPanel::new()
.with_size(Vec2::new(200.0, 60.0))
.with_color(Color::BLUE));
}
```
---
## 🎨 Asset Loading
### Textures
```rust
// Load from file
let texture = Texture::load(&device, &queue, "assets/player.png").unwrap();
// Load from bytes (embedded)
let bytes = include_bytes!("../assets/enemy.png");
let texture = Texture::from_bytes(&device, &queue, bytes, "enemy").unwrap();
// Sprite sheets
let spritesheet = SpriteSheet::new("characters", 32, 32);
let (u1, v1, u2, v2) = spritesheet.get_uv_coords(0);
```
### Audio
Supported formats: **WAV**, **OGG**, **MP3**, **FLAC**
```rust
audio.load_sound("explosion", "assets/sounds/explosion.wav").unwrap();
audio.play_sound("explosion").unwrap();
```
---
## 🛠️ Building from Source
```bash
# Clone the repository
git clone https://github.com/yourusername/shadow_engine_2d.git
cd shadow_engine_2d
# Build the library
cargo build --release
# Run examples
cargo run --example basic_game
cargo run --example physics_demo
cargo run --example particles_camera_demo
cargo run --example ui_demo
cargo run --example audio_demo
# Run tests
cargo test
```
---
## 📦 Dependencies
Shadow Engine 2D is built on top of excellent Rust crates:
- **winit** - Cross-platform window creation
- **wgpu** - Modern graphics API (Vulkan, DirectX 12, Metal)
- **glam** - Fast math library
- **rodio** - Audio playback
- **image** - Image loading and processing
- **glyphon** - Text rendering
---
## 🎯 Roadmap
- [x] Entity Component System
- [x] GPU Rendering
- [x] Physics System
- [x] Particle System
- [x] Camera System
- [x] UI System
- [x] Audio System
- [x] Texture Loading
- [ ] Animation System
- [ ] Tilemap/Level Editor
- [ ] Networking (Multiplayer)
- [ ] Save/Load System
- [ ] Scene Management
- [ ] Asset Hot Reloading
- [ ] Mobile Support (iOS/Android)
- [ ] WebAssembly Support
---
## 📄 License
Shadow Engine 2D is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
---
## 👨💻 About the Creator
**Darian Jones** - Age 14, Rust Developer
Shadow Engine 2D was created as a passion project to make 2D game development in Rust accessible, powerful, and fun. Inspired by Shadow the Axolotl, this engine aims to provide a clean API without sacrificing performance or features.
- 🦀 Rust enthusiast
- 🦎 Exotic animal lover (especially axolotls!)
- 🍕 Food adventurer
- 🎮 Game engine developer
> *"Building games should be fun, fast, and safe. That's why Shadow Engine 2D exists!"*
---
## 🙏 Acknowledgments
- Shadow the Axolotl 🦎 - Official mascot and inspiration
- The Rust community for amazing libraries and support
- All contributors and users of Shadow Engine 2D
---
## 📞 Contact & Community
- **Website**: [shadowengine2d.dev](https://shadowteamengine-design.github.io/shadowengine2dwebsite/)
- **Documentation**: [docs.rs/shadow_engine_2d](https://docs.rs/shadow_engine_2d)
- **GitHub**: [github.com/shadowteamengine-design](https://github.com/shadowteamengine-design)
---
<div align="center">
**Made with 🖤 by Darian Jones**
*Powered by Shadow the Axolotl* 🦎
⭐ Star us on GitHub if you like Shadow Engine 2D!
</div>