mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-09 10:25:54 +00:00
Bullet emitter
This commit is contained in:
parent
d49f5e2a45
commit
54c8199e8a
7 changed files with 75 additions and 32 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,6 @@ using Godot;
|
|||
|
||||
public partial class Actor : CharacterBody2D
|
||||
{
|
||||
|
||||
[Export]
|
||||
public float MovementSpeed { get; private set; }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue