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();
let mut audio = AudioSystem::new().expect("Failed to create audio system");
audio.load_sound("coin", "assets/sounds/coin.wav").ok();
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));
}
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| {
if input.key_just_pressed(KeyCode::Space) {
println!("π Playing jump sound!");
}
if input.key_just_pressed(KeyCode::KeyC) {
println!("πͺ Playing coin sound!");
audio.play_sound_with_volume("coin", 0.7).ok();
}
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;
}
}
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);
}
});
}