Now boss FSM Actor movement

This commit is contained in:
Marco 2025-05-16 17:38:02 +02:00
commit c37278075d
19 changed files with 215 additions and 28 deletions

View file

@ -23,6 +23,8 @@ public partial class Boss : Enemy, IActivable, IScriptHost
private Vector2 _homePosition;
public Vector2 HomePosition => _homePosition;
public CharacterBody2D Body => this;
public Node2D ParentObject => this;
private BossPhase CurrentPhase => BossScript.Phases[currentPhaseIndex];
private Marker2D _cameraMarker;

View file

@ -7,6 +7,8 @@ namespace Cirno.Scripts.Actors;
public partial class ScriptableBulletsEmitter : Node2D, IActivable, IScriptHost
{
public Node2D ParentObject => this;
[Export]
public BulletScript Script { get; set; }

View file

@ -5,6 +5,7 @@ namespace Cirno.Scripts.AttackPatterns;
public partial class AutonomousBulletEmitter : Node2D, IScriptHost
{
public Node2D ParentObject => this;
[Export]
public BulletScript Script { get; set; }
[Export]

View file

@ -4,6 +4,8 @@ namespace Cirno.Scripts.AttackPatterns;
public interface IScriptHost
{
public Node2D ParentObject { get; }
public Vector2 HomePosition { get; }
public void ChangeSpriteDirection(Vector2 direction);
}

View file

@ -1,5 +1,9 @@
using Cirno.Scripts.Resources;
using Godot;
using GTweens.Builders;
using GTweens.Easings;
using GTweens.Tweens;
using GTweensGodot.Extensions;
namespace Cirno.Scripts.AttackPatterns;
@ -8,8 +12,8 @@ public partial class NodeMovementPattern : AttackPattern
{
[Export] private Vector2 relativeTargetPosition;
[Export] private float moveDuration = 2f;
[Export] private Tween.TransitionType transitionType = Tween.TransitionType.Linear;
[Export] private Tween.EaseType easeType = Tween.EaseType.InOut;
// [Export] private Tween.TransitionType transitionType = Tween.TransitionType.Linear;
[Export] public GTweens.Easings.Easing EaseType { get; private set; } = Easing.Linear;
public override IPatternMachine MakeMachine(Node2D parent)
{
@ -20,7 +24,7 @@ public partial class NodeMovementPattern : AttackPattern
{
public Node2D Parent => parent;
private Tween tween;
private GTween _tween;
private bool isComplete = false;
public void Start()
@ -32,18 +36,30 @@ public partial class NodeMovementPattern : AttackPattern
return;
}
tween = Parent.CreateTween();
_tween?.Complete();
isComplete = false;
Vector2 targetPosition = (scriptHost?.HomePosition ?? Parent.GlobalPosition) + pattern.relativeTargetPosition;
_tween = GTweenSequenceBuilder.New()
.Append(scriptHost.ParentObject.TweenGlobalPosition(targetPosition, pattern.moveDuration))
.AppendCallback(() =>
{
isComplete = true;
})
.Build();
_tween.SetEasing(pattern.EaseType);
tween.TweenProperty(Parent, "global_position", targetPosition, pattern.moveDuration)
.SetTrans(pattern.transitionType)
.SetEase(pattern.easeType)
.Finished += () =>
{
isComplete = true;
};
_tween.Play();
// tween.TweenProperty(Parent, "global_position", targetPosition, pattern.moveDuration)
// .SetTrans(pattern.transitionType)
// .SetEase(pattern.easeType)
// .Finished += () =>
// {
// isComplete = true;
// };
}
public void UpdatePattern(double delta) { }

View file

@ -0,0 +1,47 @@
using Cirno.Scripts.AttackPatterns;
using Cirno.Scripts.Components.FSM.Enemy;
using Cirno.Scripts.Enums;
using Godot;
namespace Cirno.Scripts.Components.FSM.Boss;
public partial class BossScriptHostModule : ModuleBase<EnemyState, CharacterBody2D>, IScriptHost
{
[Export]
public EnemyStorageModule StorageModule { get; private set; }
public Node2D ParentObject => _machine.MainObject;
public Vector2 HomePosition => StorageModule.HomePosition;
private IStateMachine<EnemyState, CharacterBody2D> _machine;
public void ChangeSpriteDirection(Vector2 direction)
{
}
public override void EnterState(EnemyState state)
{
}
public override void ExitState(EnemyState state)
{
}
public override void Init(IStateMachine<EnemyState, CharacterBody2D> machine)
{
_machine = machine;
}
public override void Process(double delta)
{
}
public override void PhysicsProcess(double delta)
{
}
}

View file

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

View file

@ -19,6 +19,9 @@ public partial class Idle : EnemyStateBase
public override void EnterState()
{
base.EnterState();
StorageModule.HomePosition = StateMachine.MainObject.GlobalPosition;
DamageReceiver.ChangeState(false);
GD.Print("Boss idle");
_ = DelayStart();

View file

@ -17,6 +17,8 @@ public partial class Shooting : EnemyStateBase
[Export] public EnemyStorageModule StorageModule { get; private set; }
[Export] public BossScriptHostModule BossScriptHostModule { get; private set; }
[Export] public BossScript BossScript { get; set; }
// private Marker2D _cameraMarker;
@ -101,7 +103,7 @@ public partial class Shooting : EnemyStateBase
}
else
{
phase.Start(this);
phase.Start(BossScriptHostModule);
}
}