Bullet emitter

This commit is contained in:
Marco 2025-02-23 20:00:01 +01:00
commit 54c8199e8a
7 changed files with 75 additions and 32 deletions

View file

@ -7,44 +7,74 @@ namespace Cirno.Scripts.Activables;
public partial class BulletEmitter : Node2D, IActivable
{
[Export]
public BulletResource BulletResource { get; set; }
[Export]
private bool _isEmitting { get; set; } = false;
public bool EmitOnStart { get; set; } = false;
[Export]
public float EmitCoolDown { get; private set; } = 1f;
[Export] public float Spread { get; set; } = 0f;
[Export] public int Count { get; set; } = 1;
[Export] public float EmissionRotation { get; set; } = 0f;
private BulletSpawner _bulletSpawner;
private bool _isEmitting = false;
private double _emitTimer = 0f;
public override void _Ready()
{
_bulletSpawner = GetNode<BulletSpawner>("BulletSpawner");
if (EmitOnStart)
{
_isEmitting = true;
}
}
public override void _Process(double delta)
{
if (!_isEmitting) return;
_emitTimer += delta;
if (_emitTimer >= EmitCoolDown)
{
Shoot();
_emitTimer = 0f;
}
}
public void Shoot()
{
_bulletSpawner.SpawnBullet(BulletResource.MakeBullet(this.GlobalPosition, Count, Spread, EmissionRotation));
}
public void Activate(ActivationType activationType = ActivationType.Toggle)
{
switch (activationType)
{
case ActivationType.Toggle:
break;
case ActivationType.Open:
case ActivationType.Enable:
_bulletSpawner.SpawnBullet(BulletResource.MakeBullet(this.GlobalPosition, 1, Spread, EmissionRotation));
_isEmitting = true;
_emitTimer = 0;
break;
case ActivationType.Close:
case ActivationType.Disable:
_isEmitting = false;
_emitTimer = 0;
break;
case ActivationType.Use:
_bulletSpawner.SpawnBullet(BulletResource.MakeBullet(this.GlobalPosition, 1, Spread, EmissionRotation));
case ActivationType.Toggle:
_isEmitting = !_isEmitting;
_emitTimer = 0;
break;
case ActivationType.Destroy:
break;
default:
throw new ArgumentOutOfRangeException(nameof(activationType), activationType, null);
}
}
}

View file

@ -5,7 +5,6 @@ using Godot;
public partial class Actor : CharacterBody2D
{
[Export]
public float MovementSpeed { get; private set; }