cirnogodot/Scripts/AttackPatterns/PatternTest.cs

55 lines
1.6 KiB
C#
Raw Normal View History

2025-02-05 19:41:49 +01:00
using Cirno.Scripts.Actors;
using Cirno.Scripts.Components;
using Cirno.Scripts.Resources;
using Godot;
namespace Cirno.Scripts.AttackPatterns;
[GlobalClass]
public partial class PatternTest : AttackPattern
{
[Export] public PackedScene BulletScene;
2025-03-15 17:17:30 +01:00
[Export] public float bulletSpeed = 5f;
[Export] public int bulletCount = 12;
[Export] public float duration = 3f;
[Export] public float burstInterval = 0.5f;
[Export] public BulletOwner owner = BulletOwner.Enemy;
public override IPatternMachine MakeMachine(Node2D parent)
2025-02-05 19:41:49 +01:00
{
2025-03-15 17:17:30 +01:00
return new PatternTestMachine(this, parent);
2025-02-05 19:41:49 +01:00
}
2025-03-15 17:17:30 +01:00
public class PatternTestMachine(PatternTest pattern, Node2D parent) : IPatternMachine
2025-02-05 19:41:49 +01:00
{
2025-03-15 17:17:30 +01:00
public Node2D Parent => parent;
private double timer;
private double burstTimer;
private BulletSpawner spawner;
public void Start()
2025-02-05 19:41:49 +01:00
{
2025-03-15 17:17:30 +01:00
timer = 0;
2025-02-05 19:41:49 +01:00
burstTimer = 0;
2025-03-15 17:17:30 +01:00
spawner = Parent.GetNode<BulletSpawner>("BulletSpawner");
2025-02-05 19:41:49 +01:00
}
2025-03-15 17:17:30 +01:00
public void UpdatePattern(double delta)
{
timer += delta;
burstTimer += delta;
if (timer < pattern.duration && burstTimer >= pattern.burstInterval)
{
spawner.SpawnBullet(Parent.GlobalPosition, Vector2.Right, pattern.bulletSpeed, pattern.owner, pattern.bulletCount, bulletScene: pattern.BulletScene);
burstTimer = 0;
}
}
public bool IsComplete()
{
return timer >= pattern.duration;
}
2025-02-05 19:41:49 +01:00
}
2025-03-15 17:17:30 +01:00
2025-02-05 19:41:49 +01:00
}