mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-06 13:05:54 +00:00
FSM Test
This commit is contained in:
parent
36147f955d
commit
dfd9abe91b
5 changed files with 126 additions and 6 deletions
|
|
@ -1,13 +1,15 @@
|
|||
[gd_scene load_steps=14 format=4 uid="uid://prgabjxh44lf"]
|
||||
[gd_scene load_steps=17 format=4 uid="uid://prgabjxh44lf"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://doxmbokehw8ci" path="res://Scripts/GameManager.cs" id="1_4uv21"]
|
||||
[ext_resource type="PackedScene" uid="uid://bghghp5ep4w2j" path="res://Scenes/player.tscn" id="2_j0vja"]
|
||||
[ext_resource type="PackedScene" uid="uid://crry0rgk7a8sm" path="res://Scenes/Weapons/BaseWeapon.tscn" id="3_a16tm"]
|
||||
[ext_resource type="Script" uid="uid://epnwjptvks3t" path="res://Scripts/Resources/LootItem.cs" id="4_3bxj4"]
|
||||
[ext_resource type="Script" uid="uid://mja0rk7n2kln" path="res://Scripts/Resources/MapStartDataResource.cs" id="4_bc0u7"]
|
||||
[ext_resource type="TileSet" uid="uid://6k28roiljylj" path="res://Tilesets/factory_tileset.tres" id="4_em3f4"]
|
||||
[ext_resource type="Script" uid="uid://krean0uywtms" path="res://Scripts/TilemapAvoidance.cs" id="5_75e1c"]
|
||||
[ext_resource type="Script" uid="uid://v2f387aad33k" path="res://Scripts/Components/FSM/ActorStateMachine.cs" id="7_cko4a"]
|
||||
[ext_resource type="SpriteFrames" uid="uid://bcc5mlwwnkvri" path="res://Resources/Sprites/Fairy.tres" id="8_gp1xa"]
|
||||
[ext_resource type="Script" uid="uid://cfya7sndh7vy2" path="res://Scenes/CameraController.gd" id="11_uct4d"]
|
||||
[ext_resource type="PackedScene" uid="uid://b3tyacxxw88lx" path="res://Scenes/Utils/StreamPlayerWithName.tscn" id="12_3bxj4"]
|
||||
[ext_resource type="Script" uid="uid://c5nxsq3tyxcx6" path="res://Scripts/InventoryManager.cs" id="12_hibtc"]
|
||||
[ext_resource type="PackedScene" uid="uid://dkwi1hu1bixoe" path="res://Scenes/HUD/HUD.tscn" id="13_66bei"]
|
||||
[ext_resource type="Script" uid="uid://bdshph801ac2i" path="res://Scenes/CameraTarget.gd" id="14_2aa7w"]
|
||||
|
|
@ -16,15 +18,17 @@
|
|||
[sub_resource type="Resource" id="Resource_6wo78"]
|
||||
script = ExtResource("4_bc0u7")
|
||||
EggIndex = 0
|
||||
StartingEquipment = Array[ExtResource("4_3bxj4")]([])
|
||||
StartingEquipment = []
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_5xgmc"]
|
||||
|
||||
[node name="GameScene" type="Node2D"]
|
||||
process_mode = 3
|
||||
script = ExtResource("1_4uv21")
|
||||
PlayerTemplate = ExtResource("2_j0vja")
|
||||
SpawnMarkers = {
|
||||
SpawnMarkers = Dictionary[int, NodePath]({
|
||||
0: NodePath("PlayerStartPosition")
|
||||
}
|
||||
})
|
||||
WeaponTemplate = ExtResource("3_a16tm")
|
||||
MapStartData = SubResource("Resource_6wo78")
|
||||
|
||||
|
|
@ -50,6 +54,20 @@ metadata/_edit_lock_ = true
|
|||
[node name="Actors" type="Node2D" parent="Tilemaps"]
|
||||
metadata/_edit_lock_ = true
|
||||
|
||||
[node name="FSMEnemy" type="CharacterBody2D" parent="Tilemaps/Actors"]
|
||||
position = Vector2(161.783, 298.229)
|
||||
script = ExtResource("7_cko4a")
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Tilemaps/Actors/FSMEnemy"]
|
||||
shape = SubResource("CircleShape2D_5xgmc")
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="Tilemaps/Actors/FSMEnemy"]
|
||||
sprite_frames = ExtResource("8_gp1xa")
|
||||
animation = &"down"
|
||||
|
||||
[node name="Idle" type="Node2D" parent="Tilemaps/Actors/FSMEnemy"]
|
||||
|
||||
[node name="CameraController" type="Camera2D" parent="."]
|
||||
process_mode = 1
|
||||
script = ExtResource("11_uct4d")
|
||||
|
|
@ -77,3 +95,9 @@ position = Vector2(111, 305)
|
|||
[node name="AlarmManager" type="Node2D" parent="."]
|
||||
process_mode = 1
|
||||
script = ExtResource("15_d7e3u")
|
||||
|
||||
[node name="AudioStreamPlayer2D" parent="." instance=ExtResource("12_3bxj4")]
|
||||
process_mode = 3
|
||||
autoplay = true
|
||||
TrackName = "Test"
|
||||
AuthorName = "Nobody"
|
||||
|
|
|
|||
44
Scripts/Components/FSM/ActorStateMachine.cs
Normal file
44
Scripts/Components/FSM/ActorStateMachine.cs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Cirno.Scripts.Components.FSM;
|
||||
|
||||
public partial class ActorStateMachine : Node2D
|
||||
{
|
||||
public Dictionary<int, State> States { get; private set; } = new();
|
||||
|
||||
private int _currentStateIndex = 0;
|
||||
|
||||
public State CurrentState => States[_currentStateIndex];
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
var children = GetChildren();
|
||||
|
||||
foreach (var child in children)
|
||||
{
|
||||
if (child is State state)
|
||||
{
|
||||
States.Add(state.StateId, state);
|
||||
state.Init(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetState(int stateId)
|
||||
{
|
||||
CurrentState.ExitState();
|
||||
_currentStateIndex = stateId;
|
||||
CurrentState.EnterState();
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
CurrentState.ProcessState(delta);
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
CurrentState.PhysicsProcessState(delta);
|
||||
}
|
||||
}
|
||||
1
Scripts/Components/FSM/ActorStateMachine.cs.uid
Normal file
1
Scripts/Components/FSM/ActorStateMachine.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://v2f387aad33k
|
||||
36
Scripts/Components/FSM/EnemyIdle.cs
Normal file
36
Scripts/Components/FSM/EnemyIdle.cs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,22 @@
|
|||
|
||||
namespace Cirno.Scripts.Components.FSM;
|
||||
|
||||
public partial class State : Node2D
|
||||
public abstract partial class State : Node2D
|
||||
{
|
||||
public virtual int StateId { get; }
|
||||
|
||||
protected ActorStateMachine _stateMachine;
|
||||
|
||||
public virtual void Init(ActorStateMachine stateMachine)
|
||||
{
|
||||
_stateMachine = stateMachine;
|
||||
}
|
||||
|
||||
public abstract void EnterState();
|
||||
|
||||
public abstract void ExitState();
|
||||
|
||||
public abstract void ProcessState(double delta);
|
||||
public abstract void PhysicsProcessState(double delta);
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue