Moving FSM Elevator

This commit is contained in:
Marco 2025-03-06 10:27:06 +01:00
commit 8b378abef3
22 changed files with 349 additions and 16 deletions

View file

@ -19,7 +19,7 @@ _name = "Intro"
[sub_resource type="Resource" id="Resource_cfhv5"]
script = ExtResource("1_ov731")
EggIndex = 0
StartingEquipment = []
StartingEquipment = Array[ExtResource("2_bkci5")]([])
[sub_resource type="Resource" id="Resource_0k62o"]
script = ExtResource("2_tnajf")
@ -31,7 +31,7 @@ StartData = SubResource("Resource_cfhv5")
[sub_resource type="Resource" id="Resource_tpb7s"]
script = ExtResource("1_ov731")
EggIndex = 0
StartingEquipment = []
StartingEquipment = Array[ExtResource("2_bkci5")]([])
[sub_resource type="Resource" id="Resource_edoov"]
script = ExtResource("2_tnajf")
@ -43,7 +43,7 @@ StartData = SubResource("Resource_tpb7s")
[sub_resource type="Resource" id="Resource_1sw5g"]
script = ExtResource("1_ov731")
EggIndex = 255
StartingEquipment = []
StartingEquipment = Array[ExtResource("2_bkci5")]([])
[sub_resource type="Resource" id="Resource_47bot"]
script = ExtResource("2_tnajf")
@ -73,7 +73,7 @@ _name = "Rebel Base"
[sub_resource type="Resource" id="Resource_maxpt"]
script = ExtResource("1_ov731")
EggIndex = 0
StartingEquipment = []
StartingEquipment = Array[ExtResource("2_bkci5")]([])
[sub_resource type="Resource" id="Resource_pein5"]
script = ExtResource("2_tnajf")
@ -128,7 +128,7 @@ metadata/_custom_type_script = "uid://dnthdjrx78u6m"
[sub_resource type="Resource" id="Resource_7sue8"]
script = ExtResource("1_ov731")
EggIndex = 255
StartingEquipment = []
StartingEquipment = Array[ExtResource("2_bkci5")]([])
metadata/_custom_type_script = "uid://mja0rk7n2kln"
[sub_resource type="Resource" id="Resource_ognca"]

View file

@ -1,14 +1,42 @@
[gd_scene load_steps=3 format=3 uid="uid://cxjumgf8bhr3l"]
[gd_scene load_steps=10 format=3 uid="uid://cxjumgf8bhr3l"]
[ext_resource type="Texture2D" uid="uid://cyq6f1n0nrgrs" path="res://Sprites/Elevator.png" id="1_0xq5m"]
[ext_resource type="Script" uid="uid://b6jp6fhmwmobv" path="res://Scripts/Components/FSM/Elevator/ElevatorProxy.cs" id="1_xv5vg"]
[ext_resource type="Script" uid="uid://bpey64n21hyhu" path="res://Scripts/Activables/Elevator.cs" id="2_dmimb"]
[ext_resource type="Script" uid="uid://cuxk8rrhvpe2c" path="res://Scripts/Components/FSM/Elevator/Init.cs" id="3_xv5vg"]
[ext_resource type="Script" uid="uid://ju87yydywmxi" path="res://Scripts/Components/FSM/Elevator/Bottom.cs" id="5_57077"]
[ext_resource type="Script" uid="uid://cxxu5ed50wiev" path="res://Scripts/Components/FSM/Elevator/Top.cs" id="6_rd3yl"]
[ext_resource type="Script" uid="uid://bgmehqn7g7fvj" path="res://Scripts/Components/FSM/Elevator/Ascending.cs" id="7_r4wj7"]
[ext_resource type="Script" uid="uid://72sfdklqrc6d" path="res://Scripts/Components/FSM/Elevator/Descending.cs" id="8_flmvm"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_3lpp4"]
size = Vector2(32, 32)
[node name="Elevator" type="Area2D"]
script = ExtResource("1_xv5vg")
[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("1_0xq5m")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_3lpp4")
[node name="StateMachine" type="Node2D" parent="."]
script = ExtResource("2_dmimb")
[node name="Init" type="Node2D" parent="StateMachine"]
script = ExtResource("3_xv5vg")
[node name="Bottom" type="Node2D" parent="StateMachine"]
script = ExtResource("5_57077")
[node name="Top" type="Node2D" parent="StateMachine"]
script = ExtResource("6_rd3yl")
[node name="Ascending" type="Node2D" parent="StateMachine"]
script = ExtResource("7_r4wj7")
[node name="Descending" type="Node2D" parent="StateMachine"]
script = ExtResource("8_flmvm")
[node name="Disabled" type="Node2D" parent="StateMachine"]

File diff suppressed because one or more lines are too long

View file

@ -1,7 +1,8 @@
[gd_scene load_steps=50 format=4 uid="uid://bpnahwxmjgb6t"]
[gd_scene load_steps=51 format=4 uid="uid://bpnahwxmjgb6t"]
[ext_resource type="Script" uid="uid://doxmbokehw8ci" path="res://Scripts/GameManager.cs" id="1_qxyfr"]
[ext_resource type="PackedScene" uid="uid://c4pr2707hbeph" path="res://Scenes/Actors/fsm_player.tscn" id="2_ajkcn"]
[ext_resource type="Script" uid="uid://epnwjptvks3t" path="res://Scripts/Resources/LootItem.cs" id="3_covcf"]
[ext_resource type="Script" uid="uid://mja0rk7n2kln" path="res://Scripts/Resources/MapStartDataResource.cs" id="4_g48r8"]
[ext_resource type="TileSet" uid="uid://6k28roiljylj" path="res://Tilesets/factory_tileset.tres" id="5_2m462"]
[ext_resource type="Script" uid="uid://krean0uywtms" path="res://Scripts/TilemapAvoidance.cs" id="6_bnfdx"]
@ -37,7 +38,7 @@
[sub_resource type="Resource" id="Resource_6wo78"]
script = ExtResource("4_g48r8")
EggIndex = 0
StartingEquipment = []
StartingEquipment = Array[ExtResource("3_covcf")]([])
[sub_resource type="Resource" id="Resource_hppa0"]
script = ExtResource("14_wc2f3")

View file

@ -215,7 +215,7 @@ SpawnMarkers = Dictionary[int, NodePath]({
2: NodePath("Factory Tilemaps/LevelProps/BossDebugTeleporterDestination"),
255: NodePath("Factory Tilemaps/Debug Room/DebugRoomStartPosition")
})
StartingEquipment = [ExtResource("4_swym2"), ExtResource("5_nqier")]
StartingEquipment = Array[ExtResource("6_8tdlb")]([ExtResource("4_swym2"), ExtResource("5_nqier")])
MapStartData = SubResource("Resource_6sau4")
metadata/_edit_lock_ = true
@ -971,7 +971,7 @@ position = Vector2(-2000, -736)
[node name="ControlPad8" parent="Factory Tilemaps/LevelProps" node_paths=PackedStringArray("Targets") instance=ExtResource("12_hfkf1")]
position = Vector2(-2027, -735)
Targets = [NodePath("../HorizontalForceField")]
Requirements = [ExtResource("84_ma1ta")]
Requirements = Array[ExtResource("6_8tdlb")]([ExtResource("84_ma1ta")])
[node name="Ammo6" parent="Factory Tilemaps/LevelProps" instance=ExtResource("34_17pjh")]
position = Vector2(-872, -220)

View file

@ -0,0 +1,12 @@
using Cirno.Scripts.Components.FSM;
using Cirno.Scripts.Components.FSM.Elevator;
using Cirno.Scripts.Enums;
using Godot;
namespace Cirno.Scripts.Activables;
public partial class Elevator : StateMachineBase<ElevatorState, ElevatorProxy>
{
[Export] public override ElevatorState InitialState { get; protected set; } = ElevatorState.Init;
}

View file

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

View file

@ -0,0 +1,47 @@
using System.Threading;
using System.Threading.Tasks;
using Cirno.Scripts.Enums;
using Godot;
using GTweens.Builders;
using GTweens.Tweens;
using GTweensGodot.Extensions;
namespace Cirno.Scripts.Components.FSM.Elevator;
public partial class Ascending : BaseState<ElevatorState, ElevatorProxy>
{
public override ElevatorState StateId => ElevatorState.Ascending;
private GTween _tween;
public override void EnterState()
{
_tween?.Kill();
MainObject.SetPosition(MainObject.Bottom);
Ascend();
}
public override void ExitState()
{
_tween?.Kill();
}
private void Ascend()
{
// Grab player if in range
//Ascend
_ = RisingAnimation();
}
private async Task RisingAnimation()
{
_tween = GTweenSequenceBuilder.New()
.Append(MainObject.TweenPosition(MainObject.Top, MainObject.MovementTime))
.Build();
await _tween.PlayAsync(CancellationToken.None);
StateMachine.SetState(ElevatorState.Top);
}
}

View file

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

View file

@ -0,0 +1,47 @@
using System;
using Cirno.Scripts.Enums;
using Godot;
namespace Cirno.Scripts.Components.FSM.Elevator;
public partial class Bottom : BaseState<ElevatorState, ElevatorProxy>
{
public override ElevatorState StateId => ElevatorState.Bottom;
public override void EnterState()
{
MainObject.SetPosition(MainObject.Bottom);
MainObject.Activated += ElevatorActivated;
}
private void ElevatorActivated(ActivationType type)
{
switch (type)
{
case ActivationType.Use:
case ActivationType.Toggle:
MoveToTop();
break;
case ActivationType.Enable:
break;
case ActivationType.Disable:
break;
case ActivationType.Destroy:
break;
case ActivationType.Open:
break;
case ActivationType.Close:
break;
}
}
private void MoveToTop()
{
StateMachine.SetState(ElevatorState.Ascending);
}
public override void ExitState()
{
MainObject.Activated -= ElevatorActivated;
}
}

View file

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

View file

@ -0,0 +1,47 @@
using System.Threading;
using System.Threading.Tasks;
using Cirno.Scripts.Enums;
using Godot;
using GTweens.Builders;
using GTweens.Tweens;
using GTweensGodot.Extensions;
namespace Cirno.Scripts.Components.FSM.Elevator;
public partial class Descending : BaseState<ElevatorState, ElevatorProxy>
{
public override ElevatorState StateId => ElevatorState.Descending;
private GTween _tween;
public override void EnterState()
{
_tween?.Kill();
MainObject.SetPosition(MainObject.Top);
Descend();
}
public override void ExitState()
{
_tween?.Kill();
}
private void Descend()
{
// Grab player if in range
//Ascend
_ = DescendingAnimation();
}
private async Task DescendingAnimation()
{
_tween = GTweenSequenceBuilder.New()
.Append(MainObject.TweenPosition(MainObject.Bottom, MainObject.MovementTime))
.Build();
await _tween.PlayAsync(CancellationToken.None);
StateMachine.SetState(ElevatorState.Bottom);
}
}

View file

@ -0,0 +1 @@
uid://72sfdklqrc6d

View file

@ -0,0 +1,34 @@
using System;
using Cirno.Scripts.Enums;
using Godot;
namespace Cirno.Scripts.Components.FSM.Elevator;
public partial class ElevatorProxy : Area2D, IActivable
{
[Export]
public ElevatorState StartingState { get; protected set; } = ElevatorState.Bottom;
[Export]
public float MovementTime { get; protected set; } = 1.0f;
[Export]
public Path2D ElevatorPath { get; protected set; }
[Signal] public delegate void ActivatedEventHandler(ActivationType type);
public Vector2 Top => ElevatorPath.Curve.GetPointPosition(0);
public Vector2 Bottom => ElevatorPath.Curve.GetPointPosition(1);
public IStateMachine<ElevatorState,ElevatorProxy> StateMachine { get; set; }
// public void SetPosition(Vector2 position)
// {
//
// }
public void Activate(ActivationType activationType = ActivationType.Toggle)
{
EmitSignal(SignalName.Activated, (int)activationType);
}
}

View file

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

View file

@ -0,0 +1,20 @@
using Cirno.Scripts.Enums;
using Godot;
namespace Cirno.Scripts.Components.FSM.Elevator;
public partial class Init : BaseState<ElevatorState, ElevatorProxy>
{
public override ElevatorState StateId => ElevatorState.Init;
public override void EnterState()
{
MainObject.StateMachine = StateMachine;
StateMachine.SetState(MainObject.StartingState);
}
public override void ExitState()
{
}
}

View file

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

View file

@ -0,0 +1,46 @@
using Cirno.Scripts.Enums;
using Godot;
namespace Cirno.Scripts.Components.FSM.Elevator;
public partial class Top : BaseState<ElevatorState, ElevatorProxy>
{
public override ElevatorState StateId => ElevatorState.Top;
public override void EnterState()
{
MainObject.SetPosition(MainObject.ElevatorPath.Curve.GetPointPosition(0));
MainObject.Activated += ElevatorActivated;
}
private void ElevatorActivated(ActivationType type)
{
switch (type)
{
case ActivationType.Use:
case ActivationType.Toggle:
MoveToBottom();
break;
case ActivationType.Enable:
break;
case ActivationType.Disable:
break;
case ActivationType.Destroy:
break;
case ActivationType.Open:
break;
case ActivationType.Close:
break;
}
}
private void MoveToBottom()
{
StateMachine.SetState(ElevatorState.Descending);
}
public override void ExitState()
{
MainObject.Activated -= ElevatorActivated;
}
}

View file

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

View file

@ -28,7 +28,6 @@ public abstract partial class StateMachineBase<TKey, TType> : Node2D, IStateMach
state.Init(this);
}
}
GD.Print("FSM Ready");
SetState(InitialState);
}
@ -41,9 +40,7 @@ public abstract partial class StateMachineBase<TKey, TType> : Node2D, IStateMach
CurrentStateIndex = stateId;
CurrentState.EnterState();
}
public override void _Process(double delta)
{
if (CurrentStateIndex is null) return;

View file

@ -0,0 +1,11 @@
namespace Cirno.Scripts.Enums;
public enum ElevatorState
{
Init,
Bottom,
Top,
Ascending,
Descending,
Disabled,
}

View file

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