mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-22 19:43:55 +00:00
FSM
This commit is contained in:
parent
51ceb4ee3c
commit
054db28c77
5 changed files with 57 additions and 36 deletions
15
Scripts/Components/FSM/EnemyFSMState.cs
Normal file
15
Scripts/Components/FSM/EnemyFSMState.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
using Godot;
|
||||||
|
|
||||||
|
namespace Cirno.Scripts.Components.FSM;
|
||||||
|
|
||||||
|
public abstract partial class EnemyFSMState : State
|
||||||
|
{
|
||||||
|
[Export]
|
||||||
|
public EnemyState State { get; private set; }
|
||||||
|
public override int StateId => (int)State;
|
||||||
|
|
||||||
|
protected void ChangeState(EnemyState newState)
|
||||||
|
{
|
||||||
|
_stateMachine.SetState((int)newState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
using Godot;
|
|
||||||
|
|
||||||
namespace Cirno.Scripts.Components.FSM;
|
|
||||||
|
|
||||||
public partial class EnemyIdle : State
|
|
||||||
{
|
|
||||||
//[Export]
|
|
||||||
//public EnemyState State { get; private set; }
|
|
||||||
public override int StateId => (int)EnemyState.Idle;
|
|
||||||
|
|
||||||
public override void EnterState()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void ExitState()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void ProcessState(double delta)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void PhysicsProcessState(double delta)
|
|
||||||
{
|
|
||||||
// Scan for player
|
|
||||||
// Wait for alarms
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void ChangeState(EnemyState newState)
|
|
||||||
{
|
|
||||||
_stateMachine.SetState((int)newState);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
11
Scripts/Components/FSM/FSMStateModule.cs
Normal file
11
Scripts/Components/FSM/FSMStateModule.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
using System;
|
||||||
|
using Godot;
|
||||||
|
|
||||||
|
namespace Cirno.Scripts.Components.FSM;
|
||||||
|
|
||||||
|
public abstract partial class FSMStateModule : Node2D
|
||||||
|
{
|
||||||
|
public abstract void Init(Actor actor);
|
||||||
|
public abstract void Update(double delta);
|
||||||
|
public abstract void PhysicsUpdate(double delta);
|
||||||
|
}
|
||||||
22
Scripts/Components/FSM/PlayerFSMState.cs
Normal file
22
Scripts/Components/FSM/PlayerFSMState.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
using Godot;
|
||||||
|
|
||||||
|
namespace Cirno.Scripts.Components.FSM;
|
||||||
|
|
||||||
|
public abstract partial class PlayerFSMState : State
|
||||||
|
{
|
||||||
|
[Export]
|
||||||
|
public PlayerState State { get; private set; }
|
||||||
|
public override int StateId => (int)State;
|
||||||
|
|
||||||
|
protected void ChangeState(PlayerState newState)
|
||||||
|
{
|
||||||
|
_stateMachine.SetState((int)newState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum PlayerState
|
||||||
|
{
|
||||||
|
Idle,
|
||||||
|
Walking,
|
||||||
|
Cutscene
|
||||||
|
}
|
||||||
|
|
@ -1,9 +1,13 @@
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using Godot.Collections;
|
||||||
|
|
||||||
namespace Cirno.Scripts.Components.FSM;
|
namespace Cirno.Scripts.Components.FSM;
|
||||||
|
|
||||||
public abstract partial class State : Node2D
|
public abstract partial class State : Node2D
|
||||||
{
|
{
|
||||||
|
[Export]
|
||||||
|
public Array<FSMStateModule> Modules { get; private set; } = new();
|
||||||
|
|
||||||
public virtual int StateId { get; }
|
public virtual int StateId { get; }
|
||||||
|
|
||||||
protected ActorStateMachine _stateMachine;
|
protected ActorStateMachine _stateMachine;
|
||||||
|
|
@ -11,6 +15,11 @@ public abstract partial class State : Node2D
|
||||||
public virtual void Init(ActorStateMachine stateMachine)
|
public virtual void Init(ActorStateMachine stateMachine)
|
||||||
{
|
{
|
||||||
_stateMachine = stateMachine;
|
_stateMachine = stateMachine;
|
||||||
|
|
||||||
|
foreach (var module in Modules)
|
||||||
|
{
|
||||||
|
//module.Init()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void EnterState();
|
public abstract void EnterState();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue