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, LinearVelocity, RigidBody};
use bevy::prelude::*;
use building::{BuildingInfo, BuildingPreview, PREVIEW_ALPHA, PopulatePlacedBuilding};
use combat::{
Defense, Health, Range,
DeathAudio, Defense, Health, Range,
projectiles::{Fire, Projectile, ProjectileLauncher, get_shotgun_launch_vectors},
};
use combat_damagers::ContactDamage;
@ -36,6 +36,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::splat(2);
@ -45,6 +47,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_length(2.0));
let base_material = StandardMaterial {
@ -149,6 +152,7 @@ fn register(
preview,
size: SIZE,
unlocked: true,
place_sound: assets.load("sounds/thump1.ogg"),
},
Range(10.0),
Health::new(20.0),
@ -167,6 +171,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/thump1.ogg"),
shoot_audio: assets.load("sounds/pop1.ogg"),
});
}
@ -185,12 +191,14 @@ fn populate(
projectile_count: 5,
},
ContactDamage::new(2.0),
DeathAudio(res.death_audio.clone()),
ProjectileLauncher::new(
Duration::from_secs(1),
5.0,
Vec3::Y * (SIZE.y as f32 + 0.5),
Duration::from_secs(10),
10.0_f32.to_radians(),
res.shoot_audio.clone(),
),
Mesh3d(res.mesh.clone()),
MeshMaterial3d(res.material.clone()),