shadow_engine_2d 2.0.1

A modern, high-performance 2D game engine built in Rust with ECS, physics, particles, audio, and more
Documentation
use shadow_engine_2d::prelude::*;
use winit::keyboard::KeyCode;

fn main() {
    env_logger::init();

    let mut engine = Engine::builder()
        .title("Audio Demo - Shadow Engine 2D")
        .size(1280, 720)
        .build();

    // Create audio system
    let mut audio = AudioSystem::new().expect("Failed to create audio system");

    // Note: You'll need to add your own audio files to test this!
    // Uncomment these lines when you have audio files:
    // audio.load_sound("jump", "assets/sounds/jump.wav").ok();
    audio.load_sound("coin", "assets/sounds/coin.wav").ok();
    // audio.play_music_with_volume("assets/music/background.mp3", 0.5).ok();

    // Create visual feedback sprites
    let speaker = engine.world_mut().spawn();
    if let Some(entity) = engine.world_mut().entity_mut(speaker) {
        entity.add(Transform::new(0.0, -100.0));
        entity.add(Sprite::new(100.0, 100.0).with_color(Color::CYAN));
    }

    // Instructions
    let instructions = vec![
        "Audio Demo Controls:",
        "Space - Play Jump Sound",
        "C - Play Coin Sound",
        "M - Toggle Music",
        "Up/Down - Adjust Music Volume",
        "",
        "Note: Add audio files to test!",
    ];

    println!("\n{}", instructions.join("\n"));

    let mut music_volume = 0.5f32;
    let mut music_playing = false;

    engine.run(move |_world, input, _time| {
        // Play jump sound
        if input.key_just_pressed(KeyCode::Space) {
            println!("πŸ”Š Playing jump sound!");
            // audio.play_sound("jump").ok();
        }

        // Play coin sound
        if input.key_just_pressed(KeyCode::KeyC) {
            println!("πŸͺ™ Playing coin sound!");
            audio.play_sound_with_volume("coin", 0.7).ok();
        }

        // Toggle music
        if input.key_just_pressed(KeyCode::KeyM) {
            if music_playing {
                println!("⏸️ Pausing music");
                audio.pause_music();
                music_playing = false;
            } else {
                println!("▢️ Playing music");
                audio.resume_music();
                music_playing = true;
            }
        }

        // Adjust volume
        if input.key_pressed(KeyCode::ArrowUp) {
            music_volume = (music_volume + 0.01).min(1.0);
            audio.set_music_volume(music_volume);
            println!("πŸ”Š Volume: {:.0}%", music_volume * 100.0);
        }
        if input.key_pressed(KeyCode::ArrowDown) {
            music_volume = (music_volume - 0.01).max(0.0);
            audio.set_music_volume(music_volume);
            println!("πŸ”‰ Volume: {:.0}%", music_volume * 100.0);
        }
    });
}