cirnogodot/Scripts/AttackPatterns/PatternTest.cs

45 lines
1.2 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;
[Export] private float bulletSpeed = 5f;
[Export] private int bulletCount = 12;
[Export] private float duration = 3f;
[Export] private float burstInterval = 0.5f;
[Export] private BulletOwner owner = BulletOwner.Enemy;
private double timer;
private double burstTimer;
private BulletSpawner spawner;
2025-03-15 11:44:30 +01:00
public override void Start(Node2D parent)
2025-02-05 19:41:49 +01:00
{
2025-03-15 11:44:30 +01:00
Parent = parent;
2025-02-05 19:41:49 +01:00
timer = 0;
burstTimer = 0;
2025-03-15 11:44:30 +01:00
spawner = Parent.GetNode<BulletSpawner>("BulletSpawner");
2025-02-05 19:41:49 +01:00
}
public override void UpdatePattern(double delta)
{
timer += delta;
burstTimer += delta;
if (timer < duration && burstTimer >= burstInterval)
{
2025-03-15 11:44:30 +01:00
spawner.SpawnBullet(Parent.GlobalPosition, Vector2.Right, bulletSpeed, owner, bulletCount, bulletScene: BulletScene);
2025-02-05 19:41:49 +01:00
burstTimer = 0;
}
}
public override bool IsComplete()
{
return timer >= duration;
}
}