mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-10 07:05:54 +00:00
Made bullet creation modifier generics
This commit is contained in:
parent
9ae07e5b38
commit
797e24d766
7 changed files with 46 additions and 10 deletions
|
|
@ -22,7 +22,7 @@ public partial class SpiralPattern : AttackPattern
|
|||
[Export] private BulletOwner owner = BulletOwner.Enemy;
|
||||
[Export] private DamageType _damageType = DamageType.Neutral;
|
||||
[Export] private float _bulletDamage = 1f;
|
||||
[Export] private Resource _modifier;
|
||||
[Export] private BulletCreationModifier _modifier;
|
||||
[Export] private Array<Resource> _timeModifiers;
|
||||
|
||||
[Export] private bool _targetPlayer = false;
|
||||
|
|
@ -69,7 +69,7 @@ public partial class SpiralPattern : AttackPattern
|
|||
Spread = spread,
|
||||
BulletScene = BulletScene,
|
||||
RotationOffset = angleOffset,
|
||||
Modifier = _modifier as IBulletModifier,
|
||||
Modifier = _modifier,
|
||||
TimeModifiers = _timeModifiers?.Where(mod => mod is TimeModifier).Cast<TimeModifier>().ToList() ?? new List<TimeModifier>()
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public partial class TargetedPattern : AttackPattern
|
|||
[Export] private int bulletsPerShot = 1;
|
||||
[Export] private float spread = 0f;
|
||||
[Export] private BulletOwner owner = BulletOwner.Enemy;
|
||||
[Export] private Resource modifier;
|
||||
[Export] private BulletCreationModifier modifier;
|
||||
|
||||
private double timer;
|
||||
private double burstTimer;
|
||||
|
|
@ -42,7 +42,7 @@ public partial class TargetedPattern : AttackPattern
|
|||
burstTimer += delta;
|
||||
if (timer < duration && burstTimer >= burstInterval && _gameManager.PlayerPosition.HasValue)
|
||||
{
|
||||
spawner.SpawnTargetedBullet(Boss.GlobalPosition, _gameManager.PlayerPosition.Value, bulletSpeed, owner, BulletScene, bulletsPerShot, spread, modifier as IBulletModifier);
|
||||
spawner.SpawnTargetedBullet(Boss.GlobalPosition, _gameManager.PlayerPosition.Value, bulletSpeed, owner, BulletScene, bulletsPerShot, spread, modifier);
|
||||
burstTimer = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
9
Scripts/Resources/BulletCreationModifier.cs
Normal file
9
Scripts/Resources/BulletCreationModifier.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Resources;
|
||||
|
||||
[GlobalClass]
|
||||
public abstract partial class BulletCreationModifier : Resource, IBulletModifier
|
||||
{
|
||||
public abstract float ModifySpeed(float baseSpeed, int bulletIndex, int totalBullets);
|
||||
}
|
||||
|
|
@ -19,7 +19,7 @@ public partial class BulletResource : Resource
|
|||
[Export] public DamageType DamageType = DamageType.Neutral;
|
||||
|
||||
[Export]
|
||||
public Resource Modifier;
|
||||
public BulletCreationModifier Modifier;
|
||||
[Export] public Array<Resource> TimeModifiers;
|
||||
|
||||
public BulletInfo MakeBullet(Vector2 position, int count = 1, float spread = 0f, float rotationOffset = 0f)
|
||||
|
|
@ -36,7 +36,7 @@ public partial class BulletResource : Resource
|
|||
Spread = spread,
|
||||
BulletScene = BulletScene,
|
||||
RotationOffset = rotationOffset,
|
||||
Modifier = Modifier as IBulletModifier,
|
||||
Modifier = Modifier,
|
||||
LifeTime = LifeTime,
|
||||
DestructionParticlesScene = DestructionParticlesScene,
|
||||
TimeModifiers = TimeModifiers?.Where(mod => mod is TimeModifier).Cast<TimeModifier>().ToList() ??
|
||||
|
|
|
|||
|
|
@ -3,11 +3,11 @@
|
|||
namespace Cirno.Scripts.Resources;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class DecreasingSpeedModifier : Resource, IBulletModifier
|
||||
public partial class DecreasingSpeedModifier : BulletCreationModifier, IBulletModifier
|
||||
{
|
||||
[Export] private float decreaseRate = 0.1f;
|
||||
|
||||
public float ModifySpeed(float baseSpeed, int bulletIndex, int totalBullets)
|
||||
public override float ModifySpeed(float baseSpeed, int bulletIndex, int totalBullets)
|
||||
{
|
||||
return Mathf.Max(0, baseSpeed - (decreaseRate * bulletIndex));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
namespace Cirno.Scripts.Resources;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class SpeedModifier : Resource, IBulletModifier
|
||||
public partial class SpeedModifier : BulletCreationModifier, IBulletModifier
|
||||
{
|
||||
[Export] public SpeedModifierType ModifierType;
|
||||
[Export] public EasingType Easing;
|
||||
|
|
@ -11,7 +11,7 @@ public partial class SpeedModifier : Resource, IBulletModifier
|
|||
[Export] public float MinimumSpeed = 10f;
|
||||
[Export] public float ScalingFactor = 10.0f;
|
||||
|
||||
public float ModifySpeed(float baseSpeed, int bulletIndex, int totalBullets)
|
||||
public override float ModifySpeed(float baseSpeed, int bulletIndex, int totalBullets)
|
||||
{
|
||||
if (totalBullets <= 1)
|
||||
return baseSpeed;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue