Player movement and camera

This commit is contained in:
Marco 2025-06-11 15:28:26 +02:00
commit a324f2e347
43 changed files with 1777 additions and 316 deletions

View file

@ -112,14 +112,15 @@ public partial class SpiralPattern : AttackPattern
// };
}
public override IPatternMachine MakeMachine(Node2D parent)
public override IPatternMachine MakeMachine(Node parent)
{
return new SpiralPatternMachine(this, parent);
}
public class SpiralPatternMachine(SpiralPattern pattern, Node2D parent) : IPatternMachine
public class SpiralPatternMachine(SpiralPattern pattern, Node parent) : IPatternMachine
{
public Node2D Parent => parent;
public Node Parent => parent;
public IScriptHost ScriptHost { get; private set; }
private double timer;
private double burstTimer;
//private double _burstRateTimer;
@ -131,6 +132,8 @@ public partial class SpiralPattern : AttackPattern
public void Start()
{
ScriptHost = Parent as IScriptHost;
timer = 0;
_burstBullets = pattern.ShotsPerBurst;
burstTimer = pattern.burstInterval; // start immediately
@ -231,21 +234,21 @@ public partial class SpiralPattern : AttackPattern
{
if (pattern._predictPlayer && GameManager.Instance.PlayerVelocity.HasValue)
{
var predictedDirection = MathFunctions.PredictInterceptPosition(Parent.GlobalPosition,
var predictedDirection = MathFunctions.PredictInterceptPosition(ScriptHost.ParentObject.GlobalPosition,
GameManager.Instance.PlayerPosition.Value, GameManager.Instance.PlayerVelocity.Value,
pattern.BulletResource.BulletSpeed);
if (predictedDirection.HasValue)
{
direction = (predictedDirection.Value - Parent.GlobalPosition).Normalized();
direction = (predictedDirection.Value - ScriptHost.ParentObject.GlobalPosition).Normalized();
}
}
else
{
direction = (GameManager.Instance.PlayerPosition.Value - Parent.GlobalPosition).Normalized();
direction = (GameManager.Instance.PlayerPosition.Value - ScriptHost.ParentObject.GlobalPosition).Normalized();
}
}
var bullet = pattern.MakeBullet(Parent.GlobalPosition + pattern.EmitterOffset, pattern.bulletCount,
var bullet = pattern.MakeBullet(ScriptHost.ParentObject.GlobalPosition + pattern.EmitterOffset, pattern.bulletCount,
pattern.spread, angleOffset);
bullet.Direction = direction;