Add sound effects.

加入音效。
This commit is contained in:
Cold-Mint 2024-07-28 17:53:54 +08:00
parent d143cf8dbf
commit c397aff026
Signed by: Cold-Mint
GPG Key ID: C5A9BF8A98E0CE99
9 changed files with 66 additions and 7 deletions

15
default_bus_layout.tres Normal file
View File

@ -0,0 +1,15 @@
[gd_resource type="AudioBusLayout" format=3 uid="uid://cdugntqhtcyd"]
[resource]
bus/1/name = &"BGM"
bus/1/solo = false
bus/1/mute = false
bus/1/bypass_fx = false
bus/1/volume_db = 0.0
bus/1/send = &"Master"
bus/2/name = &"SoundEffect"
bus/2/solo = false
bus/2/mute = false
bus/2/bypass_fx = false
bus/2/volume_db = -0.0127316
bus/2/send = &"Master"

View File

@ -59,3 +59,5 @@ position = Vector2(15, 20)
[node name="DamageNumber" type="Marker2D" parent="."]
position = Vector2(0, -47)
script = ExtResource("3_lrmsw")
[node name="AudioListener2D" type="AudioListener2D" parent="."]

View File

@ -15,10 +15,6 @@ collision_mask = 38
script = ExtResource("1_slakl")
NumberSlots = 30
Id = "packsack"
UniqueName = null
UniqueDescription = null
_minContactInjury = null
_maxContactInjury = null
[node name="DamageArea2D" type="Area2D" parent="."]
collision_layer = 8

View File

@ -30,3 +30,7 @@ collision_mask = 78
[node name="CollisionShape2D" type="CollisionShape2D" parent="CollisionDetectionArea"]
shape = SubResource("CircleShape2D_8117d")
[node name="AudioStreamPlayer2D" type="AudioStreamPlayer2D" parent="."]
bus = &"SoundEffect"
area_mask = 16

View File

@ -1,8 +1,9 @@
[gd_scene load_steps=6 format=3 uid="uid://dnnn2xyayiehk"]
[gd_scene load_steps=7 format=3 uid="uid://dnnn2xyayiehk"]
[ext_resource type="Texture2D" uid="uid://e6670ykyq145" path="res://sprites/weapon/staffOfTheUndead.png" id="1_ms3us"]
[ext_resource type="Script" path="res://scripts/weapon/ProjectileWeapon.cs" id="1_w8hhv"]
[ext_resource type="PackedScene" uid="uid://c01av43yk1q71" path="res://prefab/projectile/curseOfTheUndead.tscn" id="2_34250"]
[ext_resource type="AudioStream" uid="uid://cak6chjjsu7wo" path="res://sounds/fire.wav" id="4_ffr2k"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_obcq2"]
size = Vector2(49, 5)
@ -36,3 +37,7 @@ shape = SubResource("RectangleShape2D_14m1g")
[node name="Marker2D" type="Marker2D" parent="."]
position = Vector2(65, 0)
[node name="AudioStreamPlayer2D" type="AudioStreamPlayer2D" parent="Marker2D"]
stream = ExtResource("4_ffr2k")
bus = &"SoundEffect"

View File

@ -80,7 +80,7 @@ public partial class PickAbleTemplate : RigidBody2D, IItem
//If it leaves the ground or walls.
//如果离开了地面或墙壁。
if (node is TileMap)
if (node is TileMapLayer)
{
_tileMapNumber--;
if (_tileMapNumber == 0)
@ -105,7 +105,7 @@ public partial class PickAbleTemplate : RigidBody2D, IItem
return;
}
if (node is TileMap)
if (node is TileMapLayer)
{
_tileMapNumber++;
EnableContactInjury = false;

View File

@ -13,6 +13,18 @@ public abstract partial class WeaponTemplate : PickAbleTemplate
{
private float _gravity = ProjectSettings.GetSetting("physics/2d/default_gravity").AsSingle();
/// <summary>
/// <para>Fire audio playback component</para>
/// <para>开火音效播放组件</para>
/// </summary>
private AudioStreamPlayer2D? _audioStreamPlayer2D;
public override void _Ready()
{
base._Ready();
_audioStreamPlayer2D = GetNodeOrNull<AudioStreamPlayer2D>("Marker2D/AudioStreamPlayer2D");
}
public override void Use(Node2D? owner, Vector2 targetGlobalPosition)
{
Fire(owner, targetGlobalPosition);
@ -93,6 +105,7 @@ public abstract partial class WeaponTemplate : PickAbleTemplate
}
}
_audioStreamPlayer2D?.Play();
DoFire(owner, enemyGlobalPosition);
_lastFiringTime = nowTime;
}

BIN
sounds/fire.wav Normal file

Binary file not shown.

24
sounds/fire.wav.import Normal file
View File

@ -0,0 +1,24 @@
[remap]
importer="wav"
type="AudioStreamWAV"
uid="uid://cak6chjjsu7wo"
path="res://.godot/imported/fire.wav-bffbfc47d9390c80437953e7f312d8b6.sample"
[deps]
source_file="res://sounds/fire.wav"
dest_files=["res://.godot/imported/fire.wav-bffbfc47d9390c80437953e7f312d8b6.sample"]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0