From 6f92162d5a271ba17f16b221736278cf098be1fb Mon Sep 17 00:00:00 2001 From: Marco Date: Tue, 1 Apr 2025 16:13:54 +0200 Subject: [PATCH] Grazing sounds --- Scenes/Misc/graze_particles.tscn | 14 ++++++++++++++ Scenes/Misc/graze_sound.tscn | 6 ++++++ Scenes/enemyBullet.tscn | 8 +++++++- Scripts/Bullet.cs | 19 +++++++++++++++++++ .../FSM/Player/PlayerGrazingModule.cs | 3 ++- 5 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 Scenes/Misc/graze_particles.tscn create mode 100644 Scenes/Misc/graze_sound.tscn diff --git a/Scenes/Misc/graze_particles.tscn b/Scenes/Misc/graze_particles.tscn new file mode 100644 index 00000000..d8ffdad1 --- /dev/null +++ b/Scenes/Misc/graze_particles.tscn @@ -0,0 +1,14 @@ +[gd_scene load_steps=2 format=3 uid="uid://ce83htrsiu7qa"] + +[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_cjf14"] +particle_flag_disable_z = true +spread = 180.0 +initial_velocity_max = 73.59 +gravity = Vector3(0, 0, 0) + +[node name="GrazeParticles" type="GPUParticles2D"] +emitting = false +amount = 4 +lifetime = 0.33 +one_shot = true +process_material = SubResource("ParticleProcessMaterial_cjf14") diff --git a/Scenes/Misc/graze_sound.tscn b/Scenes/Misc/graze_sound.tscn new file mode 100644 index 00000000..1f4a6146 --- /dev/null +++ b/Scenes/Misc/graze_sound.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://m88tchaflpln"] + +[ext_resource type="AudioStream" uid="uid://b0ficxrbhf8om" path="res://SFX/615532__crash_358__sci-fi-ui-button-sound-005.wav" id="1_q5ph6"] + +[node name="AudioStreamPlayer2D" type="AudioStreamPlayer2D"] +stream = ExtResource("1_q5ph6") diff --git a/Scenes/enemyBullet.tscn b/Scenes/enemyBullet.tscn index fad30e1c..884fcdf9 100644 --- a/Scenes/enemyBullet.tscn +++ b/Scenes/enemyBullet.tscn @@ -1,7 +1,9 @@ -[gd_scene load_steps=4 format=3 uid="uid://cuixq5ex0j40h"] +[gd_scene load_steps=6 format=3 uid="uid://cuixq5ex0j40h"] [ext_resource type="Script" uid="uid://dsa4b75hdig8p" path="res://Scripts/Bullet.cs" id="1_s0j1e"] [ext_resource type="Texture2D" uid="uid://bdyd0bht18n47" path="res://Sprites/EnemyProjectile.png" id="2_iw5k0"] +[ext_resource type="PackedScene" uid="uid://m88tchaflpln" path="res://Scenes/Misc/graze_sound.tscn" id="3_fx7gj"] +[ext_resource type="PackedScene" uid="uid://ce83htrsiu7qa" path="res://Scenes/Misc/graze_particles.tscn" id="4_mbs6d"] [sub_resource type="CircleShape2D" id="CircleShape2D_jxptd"] radius = 2.23607 @@ -24,6 +26,10 @@ editor_description = "Player Bullet" [node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="."] +[node name="AudioStreamPlayer2D" parent="." instance=ExtResource("3_fx7gj")] + +[node name="GrazeParticles" parent="." instance=ExtResource("4_mbs6d")] + [connection signal="area_entered" from="." to="." method="_on_area_entered"] [connection signal="body_entered" from="." to="." method="_on_body_entered"] [connection signal="screen_exited" from="VisibleOnScreenNotifier2D" to="." method="_on_visible_on_screen_notifier_2d_screen_exited"] diff --git a/Scripts/Bullet.cs b/Scripts/Bullet.cs index 5e5c5ab2..f1a3a898 100644 --- a/Scripts/Bullet.cs +++ b/Scripts/Bullet.cs @@ -32,6 +32,15 @@ public partial class Bullet : Area2D [Signal] public delegate void OnDestroyEventHandler(); + private AudioStreamPlayer2D _grazeSound; + private GpuParticles2D _grazeParticles; + + public override void _Ready() + { + _grazeSound = GetNodeOrNull("AudioStreamPlayer2D"); + _grazeParticles = GetNodeOrNull("GrazeParticles"); + } + public void Initialize(BulletInfo bulletInfo, GameManager gameManager) { _bulletInfo = bulletInfo; @@ -51,6 +60,16 @@ public partial class Bullet : Area2D _modifiers = _bulletInfo.TimeModifiers.Select(x => x.Wrap()).ToList(); } + public void Graze() + { + _grazeSound?.Play(); + if (_grazeParticles is not null) + { + _grazeParticles.Emitting = true; + } + IsGrazed = true; + } + private void ApplyTimeModifiers(double delta) { foreach (var modifier in _modifiers) diff --git a/Scripts/Components/FSM/Player/PlayerGrazingModule.cs b/Scripts/Components/FSM/Player/PlayerGrazingModule.cs index f02fb011..88f21fbc 100644 --- a/Scripts/Components/FSM/Player/PlayerGrazingModule.cs +++ b/Scripts/Components/FSM/Player/PlayerGrazingModule.cs @@ -39,7 +39,8 @@ public partial class PlayerGrazingModule : PlayerArea2DModule GD.Print("Grazed"); - bullet.IsGrazed = true; + bullet.Graze(); + //bullet.IsGrazed = true; Shield.CurrentResource += bullet.BulletInfo.GrazeValue; // check if it's grazed // check if it's grazeable