add sound effects

This commit is contained in:
Jim 2025-09-02 21:13:21 -04:00
parent 86f2345667
commit 587b902e79
Signed by: jim
GPG key ID: 3D7D94BA53088BF4
39 changed files with 234 additions and 40 deletions

View file

@ -11,7 +11,7 @@ use avian3d::prelude::*;
use bevy::prelude::*;
use building::{BuildingInfo, BuildingPreview, PREVIEW_ALPHA, PopulatePlacedBuilding};
use combat::{
Attacked, Defense, Died, Health, Range, Team,
Attacked, DeathAudio, Defense, Died, Health, Range, Team,
projectiles::{Fire, Projectile, ProjectileLauncher, get_launch_vector},
};
use combat_damagers::ContactDamage;
@ -47,6 +47,9 @@ struct BuildingResources {
projectile_material: Handle<StandardMaterial>,
projectile_collider: Collider,
info_entity: Entity,
death_audio: Handle<AudioSource>,
shoot_audio: Handle<AudioSource>,
explosion_audio: Handle<AudioSource>,
}
const SIZE: UVec3 = UVec3::new(3, 1, 3);
@ -56,6 +59,7 @@ fn register(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
assets: Res<AssetServer>,
) {
let mesh = meshes.add(Cuboid::from_size(SIZE.as_vec3()));
let base_material = StandardMaterial {
@ -178,6 +182,7 @@ fn register(
preview,
size: SIZE,
unlocked: true,
place_sound: assets.load("sounds/thump2.ogg"),
},
Range(20.0),
Health::new(50.0),
@ -196,6 +201,9 @@ fn register(
projectile_mesh: meshes.add(Cuboid::from_size(PROJ_SIZE)),
projectile_collider: Collider::cuboid(PROJ_SIZE.x, PROJ_SIZE.y, PROJ_SIZE.z),
info_entity: info,
death_audio: assets.load("sounds/revthump2.ogg"),
shoot_audio: assets.load("sounds/gust2.ogg"),
explosion_audio: assets.load("sounds/boom1.ogg"),
});
}
@ -218,6 +226,7 @@ fn populate(
pellet_damage: 10.,
pellet_speed: 50.,
},
DeathAudio(res.death_audio.clone()),
ContactDamage::new(2.0),
ProjectileLauncher::new(
Duration::from_secs(3),
@ -225,6 +234,7 @@ fn populate(
Vec3::Y * (SIZE.y as f32 + 0.5),
Duration::from_secs(10),
0.,
res.shoot_audio.clone(),
),
Mesh3d(res.mesh.clone()),
MeshMaterial3d(res.material.clone()),
@ -256,6 +266,7 @@ fn on_fire(
Transform::from_translation(trigger.event().spawn_pos),
Projectile::from(&trigger.event().launcher),
Projectile::collision_layers(trigger.event().team),
DeathAudio(res.explosion_audio.clone()),
SuncannonProjectile(suncannon.clone()),
LinearVelocity(v),
res.projectile_collider.clone(),