Explosions for bullets

This commit is contained in:
Marco 2025-03-06 17:05:45 +01:00
commit 8ab4546579
9 changed files with 58 additions and 11 deletions

View file

@ -24,7 +24,7 @@ public partial class BulletEmitter : Node2D, IActivable
private BulletSpawner _bulletSpawner;
private bool _isEmitting = false;
protected bool IsEmitting = false;
private double _emitTimer = 0f;
@ -33,13 +33,14 @@ public partial class BulletEmitter : Node2D, IActivable
_bulletSpawner = GetNode<BulletSpawner>("BulletSpawner");
if (EmitOnStart)
{
_isEmitting = true;
IsEmitting = true;
CallDeferred(MethodName.Shoot);
}
}
public override void _Process(double delta)
{
if (!_isEmitting) return;
if (!IsEmitting) return;
_emitTimer += delta;
if (_emitTimer >= EmitCoolDown)
@ -60,17 +61,17 @@ public partial class BulletEmitter : Node2D, IActivable
{
case ActivationType.Open:
case ActivationType.Enable:
_isEmitting = true;
IsEmitting = true;
_emitTimer = 0;
break;
case ActivationType.Close:
case ActivationType.Disable:
_isEmitting = false;
IsEmitting = false;
_emitTimer = 0;
break;
case ActivationType.Use:
case ActivationType.Toggle:
_isEmitting = !_isEmitting;
IsEmitting = !IsEmitting;
_emitTimer = 0;
break;
case ActivationType.Destroy:

View file

@ -21,6 +21,8 @@ public partial class WeaponAmmoCounter : Container
public void Init(LootItem item)
{
Item = item;
Icon.Texture = item.InventorySprite;
InventoryManager.Instance.LoadedAmmoChanged += (weaponKey, count) =>
{

View file

@ -0,0 +1,24 @@
using Cirno.Scripts.Activables;
using Godot;
namespace Cirno.Scripts.Weapons;
public partial class AutoclearingBulletEmitter : BulletEmitter
{
[Export]
public float Timeout { get; private set; } = 5f;
private double _timeoutTimer = 0f;
public override void _Process(double delta)
{
base._Process(delta);
if (!IsEmitting) return;
_timeoutTimer += delta;
if (_timeoutTimer >= Timeout)
{
QueueFree();
}
}
}

View file

@ -0,0 +1 @@
uid://df81kn4u8yigu