Add asteroid destruction sound

This commit is contained in:
2025-12-17 16:18:31 -06:00
parent ae093d2c9c
commit d7802bdbed
3 changed files with 14 additions and 2 deletions

Binary file not shown.

View File

@@ -115,6 +115,7 @@ pub fn split_asteroids(
mut respawn_events: MessageWriter<SpawnAsteroid>,
mut commands: Commands,
query: Query<(&Transform, &Asteroid, &Velocity)>,
game_assets: Res<GameAssets>,
) {
for event in destroy_events.read() {
if let Ok((transform, rock, velocity)) = query.get(event.0) {
@@ -137,6 +138,12 @@ pub fn split_asteroids(
// Always despawn the asteroid. New ones (may) be spawned in it's
// place, but this one is gone.
commands.entity(event.0).despawn();
// Play a sound for the asteroid exploding
commands.spawn((
AudioPlayer::new(game_assets.asteroid_crack_sound()),
PlaybackSettings::DESPAWN,
));
}
}
}

View File

@@ -58,7 +58,7 @@ impl Default for WorldSize {
pub struct GameAssets {
meshes: [Handle<Mesh>; 5],
materials: [Handle<ColorMaterial>; 7],
sounds: [Handle<AudioSource>; 2],
sounds: [Handle<AudioSource>; 3],
}
impl GameAssets {
@@ -105,6 +105,10 @@ impl GameAssets {
pub fn laser_sound(&self) -> Handle<AudioSource> {
self.sounds[1].clone()
}
pub fn asteroid_crack_sound(&self) -> Handle<AudioSource> {
self.sounds[2].clone()
}
}
impl FromWorld for GameAssets {
@@ -135,7 +139,8 @@ impl FromWorld for GameAssets {
let loader = world.resource_mut::<AssetServer>();
let sounds = [
loader.load("explosionCrunch_004.ogg"),
loader.load("laserSmall_001.ogg")
loader.load("laserSmall_001.ogg"),
loader.load("explosionCrunch_000.ogg"),
];
GameAssets {
meshes,