Added offsets and remade modifiers system

This commit is contained in:
Marco 2025-05-09 11:46:58 +02:00
commit aab69fb609
16 changed files with 474 additions and 426 deletions

View file

@ -1,4 +1,5 @@
using Godot;
using Cirno.Scripts.Components;
using Godot;
namespace Cirno.Scripts.Resources;
@ -6,5 +7,6 @@ namespace Cirno.Scripts.Resources;
[Tool]
public abstract partial class BulletCreationModifier : Resource, IBulletModifier
{
public abstract float ModifySpeed(float baseSpeed, int bulletIndex, int totalBullets);
public abstract BulletInfo ModifyBullet(BulletInfo bullet, int bulletIndex, int totalBullets);
//public abstract float ModifySpeed(float baseSpeed, int bulletIndex, int totalBullets);
}

View file

@ -33,7 +33,7 @@ public partial class BulletResource : Resource
public BulletInfo MakeBullet(Vector2 position, int count = 1, float spread = 0f, float rotationOffset = 0f)
{
return new BulletInfo()
return new BulletInfo(this)
{
Position = position,
Direction = Direction,

View file

@ -1,4 +1,5 @@
using Godot;
using Cirno.Scripts.Components;
using Godot;
namespace Cirno.Scripts.Resources;
@ -8,7 +9,13 @@ public partial class DecreasingSpeedModifier : BulletCreationModifier, IBulletMo
{
[Export] private float decreaseRate = 0.1f;
public override float ModifySpeed(float baseSpeed, int bulletIndex, int totalBullets)
public override BulletInfo ModifyBullet(BulletInfo bullet, int bulletIndex, int totalBullets)
{
bullet.Speed = ModifySpeed(bullet.OriginalBulletResource.BulletSpeed, bulletIndex, totalBullets);
return bullet;
}
public float ModifySpeed(float baseSpeed, int bulletIndex, int totalBullets)
{
return Mathf.Max(0, baseSpeed - (decreaseRate * bulletIndex));
}

View file

@ -1,8 +1,10 @@
using Godot;
using Cirno.Scripts.Components;
using Godot;
namespace Cirno.Scripts.Resources;
public interface IBulletModifier
{
float ModifySpeed(float baseSpeed, int bulletIndex, int totalBullets);
BulletInfo ModifyBullet(BulletInfo bullet, int bulletIndex, int totalBullets);
//float ModifySpeed(float baseSpeed, int bulletIndex, int totalBullets);
}

View file

@ -0,0 +1,56 @@
using System.Collections.Generic;
using Cirno.Scripts.AttackPatterns;
using Godot;
using Godot.Collections;
namespace Cirno.Scripts.Resources.ScriptableBullets;
[GlobalClass]
public partial class ParallelPatternGroup : AttackPattern
{
[Export(PropertyHint.None, "suffix:s")] public float Duration { get; private set; } = 10f;
[Export] public Array<AttackPattern> Patterns { get; private set; } = [];
public override IPatternMachine MakeMachine(Node2D parent)
{
return new ParallelPatternGroupMachine(this, parent);
}
public class ParallelPatternGroupMachine(ParallelPatternGroup patternGroup, Node2D parent) : IPatternMachine
{
public Node2D Parent => parent;
//private int _currentPatternIndex = 0;
//private AttackPattern CurrentPattern => patternGroup.Patterns[_currentPatternIndex];
private List<IPatternMachine> _patternMachines = [];
public void Start()
{
//_currentPatternIndex = 0;
foreach (var pattern in patternGroup.Patterns)
{
var machine = pattern.MakeMachine(parent);
_patternMachines.Add(machine);
machine.Start();
}
}
public void UpdatePattern(double delta)
{
foreach (var patternMachine in _patternMachines)
{
//if (!CurrentPattern.WaitForCompletion || _patternMachine.IsComplete())
if ( patternMachine.IsComplete()) continue;
patternMachine.UpdatePattern(delta);
}
}
public bool IsComplete()
{
return _patternMachines.TrueForAll(x => x.IsComplete());
}
}
}

View file

@ -0,0 +1 @@
uid://rqtkxuqmo7gi

View file

@ -1,4 +1,5 @@
using Godot;
using Cirno.Scripts.Components;
using Godot;
namespace Cirno.Scripts.Resources;
@ -12,7 +13,13 @@ public partial class SpeedModifier : BulletCreationModifier, IBulletModifier
[Export] public float MinimumSpeed = 10f;
[Export] public float ScalingFactor = 10.0f;
public override float ModifySpeed(float baseSpeed, int bulletIndex, int totalBullets)
public override BulletInfo ModifyBullet(BulletInfo bullet, int bulletIndex, int totalBullets)
{
bullet.Speed = ModifySpeed(bullet.OriginalBulletResource.BulletSpeed, bulletIndex, totalBullets);
return bullet;
}
public float ModifySpeed(float baseSpeed, int bulletIndex, int totalBullets)
{
if (totalBullets <= 1)
return baseSpeed;