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

@ -8,7 +8,7 @@ use avian3d::prelude::{Collider, GravityScale, LinearVelocity, RigidBody};
use bevy::prelude::*;
use building::{BuildingInfo, BuildingPreview, PREVIEW_ALPHA, PopulatePlacedBuilding};
use combat::{
Defense, Health, Range, Team,
DeathAudio, Defense, Health, Range, Team,
projectiles::{Fire, Projectile, ProjectileLauncher},
};
use combat_damagers::ContactDamage;
@ -38,6 +38,8 @@ struct BuildingResources {
projectile_material: Handle<StandardMaterial>,
projectile_collider: Collider,
info_entity: Entity,
death_audio: Handle<AudioSource>,
shoot_audio: Handle<AudioSource>,
}
const SIZE: UVec3 = UVec3::new(1, 4, 1);
@ -47,6 +49,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 {
@ -157,6 +160,7 @@ fn register(
preview,
size: SIZE,
unlocked: true,
place_sound: assets.load("sounds/thump1.ogg"),
},
Range(10.0),
Health::new(10.0),
@ -175,6 +179,8 @@ 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/revthump1.ogg"),
shoot_audio: assets.load("sounds/pop2.ogg"),
});
}
@ -194,6 +200,7 @@ fn populate(
shot_velocity: 20.,
},
ContactDamage::new(2.0),
DeathAudio(res.death_audio.clone()),
ProjectileLauncher {
custom_targeting: true,
..ProjectileLauncher::new(
@ -202,6 +209,7 @@ fn populate(
Vec3::Y * (SIZE.y as f32 + 0.5),
Duration::from_secs(10),
0.,
res.shoot_audio.clone(),
)
},
Mesh3d(res.mesh.clone()),