shadow_engine_2d 2.0.1

A modern, high-performance 2D game engine built in Rust with ECS, physics, particles, audio, and more
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
# 🦎 Shadow Engine 2D

<div align="center">

![Shadow the Axolotl](website/shadow-mascot.svg)

**A modern, high-performance 2D game engine built in Rust**

[![Crates.io](https://img.shields.io/crates/v/shadow_engine_2d.svg)](https://crates.io/crates/shadow_engine_2d)
[![Documentation](https://docs.rs/shadow_engine_2d/badge.svg)](https://docs.rs/shadow_engine_2d)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Rust](https://img.shields.io/badge/rust-1.70%2B-orange.svg)](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>