mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:35:34 +00:00
Weapon sounds
This commit is contained in:
parent
22a1ec5ba2
commit
3c531bbe04
14 changed files with 174 additions and 52 deletions
|
|
@ -95,8 +95,7 @@ public partial class PlayerWeaponProvider : Node2D
|
|||
public void Shoot(Vector2 direction)
|
||||
{
|
||||
if (EquippedWeapon == null) return;
|
||||
|
||||
|
||||
|
||||
EquippedWeapon.ShootDirection = direction;
|
||||
EquippedWeapon.Shoot();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -170,8 +170,6 @@ public partial class Active : PlayerStateBase
|
|||
//CallDeferred(MethodName.PauseDeferred);
|
||||
PauseDeferred();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void PauseDeferred()
|
||||
|
|
|
|||
|
|
@ -29,16 +29,15 @@ public partial class WeaponResource : Resource
|
|||
|
||||
[Export] public bool InfiniteAmmo = true;
|
||||
|
||||
|
||||
[Export] public StringName ItemKey;
|
||||
[Export] public StringName AmmoKey;
|
||||
#region Bullet spawn data
|
||||
[ExportCategory("Bullet Spawn Data")]
|
||||
[Export] public int BulletsPerShot = 1;
|
||||
|
||||
[Export] public float SpreadAngle = 0f;
|
||||
[Export] public float RandomSpread = 0f;
|
||||
|
||||
[Export] public StringName ItemKey;
|
||||
|
||||
#region Bullet spawn data
|
||||
|
||||
[Export] public StringName AmmoKey;
|
||||
[Export] public float RandomSpread = 0f;
|
||||
//[Export] public float BulletSpeed = 100f;
|
||||
//[Export] public float BulletDamage = 1;
|
||||
//[Export] public float LifeTime = 10f;
|
||||
|
|
@ -49,6 +48,11 @@ public partial class WeaponResource : Resource
|
|||
//[Export] private Array<Resource> _timeModifiers;
|
||||
|
||||
#endregion
|
||||
|
||||
[ExportCategory("Sounds")]
|
||||
[Export] public AudioStream ReloadSound { get; set; }
|
||||
[Export] public AudioStream ShootSound { get; set; }
|
||||
[Export] public AudioStream EmptySound { get; set; }
|
||||
|
||||
public BulletInfo MakeBullet(Vector2 position)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -17,6 +17,14 @@ public partial class Weapon : Node2D
|
|||
[Export]
|
||||
public Marker2D Muzzle { get; set; }
|
||||
|
||||
[Signal]
|
||||
public delegate void ShootingEventHandler();
|
||||
|
||||
[Signal]
|
||||
public delegate void ReloadingEventHandler();
|
||||
|
||||
[Signal] public delegate void EmptyEventHandler();
|
||||
|
||||
public int Ammo { get; set; } = 0;
|
||||
|
||||
private int _loadedAmmo;
|
||||
|
|
@ -60,6 +68,8 @@ public partial class Weapon : Node2D
|
|||
|
||||
public void Reload()
|
||||
{
|
||||
EmitSignalReloading();
|
||||
|
||||
_cooldownTimer.Start(WeaponData.ReloadTime);
|
||||
|
||||
if (WeaponData.InfiniteAmmo || string.IsNullOrWhiteSpace(WeaponData.AmmoKey))
|
||||
|
|
@ -77,7 +87,8 @@ public partial class Weapon : Node2D
|
|||
}
|
||||
else
|
||||
{
|
||||
GD.Print("Out of ammo");
|
||||
EmitSignalEmpty();
|
||||
//GD.Print("Out of ammo");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -100,11 +111,12 @@ public partial class Weapon : Node2D
|
|||
return;
|
||||
}
|
||||
|
||||
EmitSignalShooting();
|
||||
|
||||
// TODO: Shoot at muzzle position, need to provide a way to turn it, on a radius?
|
||||
|
||||
float halfSpread = WeaponData.SpreadAngle / 2f;
|
||||
float spreadStep = WeaponData.BulletsPerShot > 1 ? WeaponData.SpreadAngle / (WeaponData.BulletsPerShot - 1) : 0;
|
||||
|
||||
|
||||
for (int i = 0; i < WeaponData.BulletsPerShot; i++)
|
||||
{
|
||||
|
|
|
|||
40
Scripts/Weapons/WeaponSoundModule.cs
Normal file
40
Scripts/Weapons/WeaponSoundModule.cs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Weapons;
|
||||
|
||||
public partial class WeaponSoundModule : Node2D
|
||||
{
|
||||
[Export]
|
||||
public Weapon Weapon { get; private set; }
|
||||
|
||||
[Export]
|
||||
public AudioStreamPlayer2D ShootSound { get; private set; }
|
||||
[Export]
|
||||
public AudioStreamPlayer2D ReloadSound { get; private set; }
|
||||
[Export]
|
||||
public AudioStreamPlayer2D EmptySound { get; private set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
if (Weapon?.WeaponData is null) return;
|
||||
|
||||
ShootSound.Stream = Weapon.WeaponData.ShootSound;
|
||||
ReloadSound.Stream = Weapon.WeaponData.ReloadSound;
|
||||
EmptySound.Stream = Weapon.WeaponData.EmptySound;
|
||||
}
|
||||
|
||||
public void PlayReloadSound()
|
||||
{
|
||||
ReloadSound?.Play();
|
||||
}
|
||||
|
||||
public void PlayShootSound()
|
||||
{
|
||||
ShootSound?.Play();
|
||||
}
|
||||
|
||||
public void PlayEmptySound()
|
||||
{
|
||||
EmptySound?.Play();
|
||||
}
|
||||
}
|
||||
1
Scripts/Weapons/WeaponSoundModule.cs.uid
Normal file
1
Scripts/Weapons/WeaponSoundModule.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dw7nwfbws3op4
|
||||
Loading…
Add table
Add a link
Reference in a new issue