mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
80 lines
No EOL
2 KiB
C#
80 lines
No EOL
2 KiB
C#
using System;
|
|
using Cirno.Scripts.Components;
|
|
using Cirno.Scripts.Resources;
|
|
using Godot;
|
|
|
|
namespace Cirno.Scripts.Activables;
|
|
|
|
public partial class BulletEmitter : Node2D, IActivable
|
|
{
|
|
[Export]
|
|
public BulletResource BulletResource { get; set; }
|
|
|
|
[Export]
|
|
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.Open:
|
|
case ActivationType.Enable:
|
|
_isEmitting = true;
|
|
_emitTimer = 0;
|
|
break;
|
|
case ActivationType.Close:
|
|
case ActivationType.Disable:
|
|
_isEmitting = false;
|
|
_emitTimer = 0;
|
|
break;
|
|
case ActivationType.Use:
|
|
case ActivationType.Toggle:
|
|
_isEmitting = !_isEmitting;
|
|
_emitTimer = 0;
|
|
break;
|
|
case ActivationType.Destroy:
|
|
break;
|
|
}
|
|
}
|
|
} |