mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-07 21:25:53 +00:00
Enemy sounds
This commit is contained in:
parent
585befb932
commit
a11e61b2c2
15 changed files with 224 additions and 38 deletions
84
Scripts/Components/Actors/3D/EnemySoundModule3D.cs
Normal file
84
Scripts/Components/Actors/3D/EnemySoundModule3D.cs
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
using Cirno.Scripts.Components.FSM;
|
||||
using Cirno.Scripts.Components.FSM.Enemy._3D;
|
||||
using Cirno.Scripts.Enums;
|
||||
using Cirno.Scripts.Weapons;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.Actors._3D;
|
||||
|
||||
public partial class EnemySoundModule3D : ModuleBase<EnemyState, CharacterBody3D>
|
||||
{
|
||||
|
||||
[ExportCategory("References")]
|
||||
[Export] public DamageReceiver3D DamageReceiver { get; private set; }
|
||||
[Export] public EnemyStorage3D StorageModule { get; private set; }
|
||||
|
||||
|
||||
[ExportCategory("Players")]
|
||||
[Export] public AudioStreamPlayer3D HitPlayer { get; private set; }
|
||||
[Export] public AudioStreamPlayer3D DeathPlayer { get; private set; }
|
||||
[Export] public AudioStreamPlayer3D AlertPlayer { get; private set; }
|
||||
|
||||
private bool _initialized = false;
|
||||
private bool _enabled = false;
|
||||
|
||||
public override void EnterState(EnemyState state)
|
||||
{
|
||||
|
||||
_enabled = true;
|
||||
}
|
||||
|
||||
public override void ExitState(EnemyState state)
|
||||
{
|
||||
_enabled = false;
|
||||
}
|
||||
|
||||
private IStateMachine<EnemyState, CharacterBody3D> _machine;
|
||||
|
||||
public override void Init(IStateMachine<EnemyState, CharacterBody3D> machine)
|
||||
{
|
||||
if (_initialized) return;
|
||||
|
||||
_machine = machine;
|
||||
if (StorageModule.EnemyData.HitSound is not null)
|
||||
{
|
||||
HitPlayer.Stream = StorageModule.EnemyData.HitSound;
|
||||
DamageReceiver.BulletHit += DamageReceiverOnBulletHit;
|
||||
}
|
||||
|
||||
if (StorageModule.EnemyData.DeathSound is not null)
|
||||
{
|
||||
DeathPlayer.Stream = StorageModule.EnemyData.DeathSound;
|
||||
DamageReceiver.HealthProvider.ResourceDepleted += HealthProviderOnResourceDepleted;
|
||||
}
|
||||
|
||||
if (StorageModule.EnemyData.AlertSound is not null)
|
||||
{
|
||||
AlertPlayer.Stream = StorageModule.EnemyData.AlertSound;
|
||||
|
||||
}
|
||||
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
private void HealthProviderOnResourceDepleted()
|
||||
{
|
||||
GD.Print("Played death sound");
|
||||
DeathPlayer.Play();
|
||||
}
|
||||
|
||||
private void DamageReceiverOnBulletHit(Bullet3D bullet, Vector3 position, Vector3 direction)
|
||||
{
|
||||
HitPlayer.Play();
|
||||
}
|
||||
|
||||
public override void Process(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void PhysicsProcess(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue