cirnogodot/Scripts/AttackPatterns/SpiralPattern.cs

87 lines
2.9 KiB
C#
Raw Normal View History

2025-02-09 11:48:30 +01:00
using System.Collections.Generic;
using System.Linq;
using Cirno.Scripts.Actors;
2025-02-05 19:41:49 +01:00
using Cirno.Scripts.Components;
using Cirno.Scripts.Resources;
using Godot;
2025-02-09 11:48:30 +01:00
using Godot.Collections;
2025-02-13 18:25:55 +01:00
using Array = System.Array;
2025-02-05 19:41:49 +01:00
namespace Cirno.Scripts.AttackPatterns;
[GlobalClass]
public partial class SpiralPattern : AttackPattern
{
[Export] public PackedScene BulletScene;
[Export] private float bulletSpeed = 5f;
[Export] private int bulletCount = 16;
2025-02-09 09:37:43 +01:00
[Export] private float rotationSpeed = 0f;
[Export] private float _rotationOffset = 0f;
2025-02-05 19:41:49 +01:00
[Export] private float duration = 5f;
[Export] private float burstInterval = 0.5f;
[Export] private float spread = 360f;
[Export] private BulletOwner owner = BulletOwner.Enemy;
2025-02-11 19:00:01 +01:00
[Export] private DamageType _damageType = DamageType.Neutral;
[Export] private float _bulletDamage = 1f;
2025-02-13 14:32:24 +01:00
[Export] private BulletCreationModifier _modifier;
2025-02-13 18:25:55 +01:00
[Export] private Array<TimeModifier> _timeModifiers;
2025-02-05 19:41:49 +01:00
2025-02-12 16:51:00 +01:00
[Export] private bool _targetPlayer = false;
2025-02-05 19:41:49 +01:00
private double timer;
private double burstTimer;
private BulletSpawner spawner;
2025-02-12 16:51:00 +01:00
2025-02-05 19:41:49 +01:00
public override void Start(Boss boss)
{
Boss = boss;
timer = 0;
burstTimer = burstInterval; // start immediately
spawner = boss.GetNode<BulletSpawner>("BulletSpawner");
}
public override void UpdatePattern(double delta)
{
timer += delta;
burstTimer += delta;
if (timer < duration && burstTimer >= burstInterval)
{
2025-02-12 16:51:00 +01:00
float angleOffset = _rotationOffset + (float)(rotationSpeed * timer);
Vector2 direction = Vector2.Right;
if (_targetPlayer && Boss.GameManager.PlayerPosition.HasValue)
{
direction = (Boss.GameManager.PlayerPosition.Value - Boss.GlobalPosition).Normalized();
}
2025-02-09 09:37:43 +01:00
spawner.SpawnBullet(new BulletInfo()
{
Position = Boss.GlobalPosition,
2025-02-12 16:51:00 +01:00
Direction = direction,
2025-02-09 09:37:43 +01:00
Speed = bulletSpeed,
Owner = owner,
2025-02-11 19:00:01 +01:00
DamageType = _damageType,
Damage = _bulletDamage,
2025-02-09 09:37:43 +01:00
BulletCount = bulletCount,
Spread = spread,
BulletScene = BulletScene,
2025-02-12 16:51:00 +01:00
RotationOffset = angleOffset,
2025-02-13 14:32:24 +01:00
Modifier = _modifier,
2025-02-13 18:25:55 +01:00
TimeModifiers = ((_timeModifiers?.Where(mod => mod != null)) ?? Array.Empty<TimeModifier>()).Select(m => new ModifierWrapper()
{
TimeModifier = m,
Applied = false
}).ToList()
2025-02-09 09:37:43 +01:00
});
// spawner.SpawnSpiralPattern(Boss.GlobalPosition, bulletSpeed, owner, bulletCount, rotationSpeed, timer, spread, BulletScene);
2025-02-05 19:41:49 +01:00
burstTimer = 0;
}
}
public override bool IsComplete()
{
return timer >= duration;
}
}