Elevator top body

This commit is contained in:
Marco 2025-03-11 15:03:44 +01:00
commit c8cd4ffb1d
10 changed files with 84 additions and 33 deletions

View file

@ -12,10 +12,11 @@
[sub_resource type="RectangleShape2D" id="RectangleShape2D_3lpp4"]
size = Vector2(20, 19)
[node name="Elevator" type="Area2D"]
[node name="Elevator" type="Area2D" node_paths=PackedStringArray("TopBody")]
collision_layer = 0
collision_mask = 2
script = ExtResource("1_xv5vg")
TopBody = NodePath("")
[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("1_0xq5m")

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=37 format=4 uid="uid://6a6tjohypmmb"]
[gd_scene load_steps=39 format=4 uid="uid://6a6tjohypmmb"]
[ext_resource type="Script" uid="uid://doxmbokehw8ci" path="res://Scripts/GameManager.cs" id="1_t2k72"]
[ext_resource type="PackedScene" uid="uid://c4pr2707hbeph" path="res://Scenes/Actors/fsm_player.tscn" id="2_2jsgm"]
@ -25,6 +25,7 @@
[ext_resource type="PackedScene" uid="uid://bc64lr3vlwchq" path="res://Scenes/Door_Vertical.tscn" id="20_qudbj"]
[ext_resource type="PackedScene" uid="uid://b4gugris5j5kd" path="res://Scenes/Activable/WallEmitter.tscn" id="21_qi6uc"]
[ext_resource type="Resource" uid="uid://dqnvesdj0dk3v" path="res://Resources/Bullets/simple_enemy_bullet.tres" id="22_uaqq6"]
[ext_resource type="PackedScene" uid="uid://cxjumgf8bhr3l" path="res://Scenes/Elevator.tscn" id="23_577wb"]
[ext_resource type="PackedScene" uid="uid://d1h48wgasakk4" path="res://Scenes/Interactable/alarm_box.tscn" id="23_uaqq6"]
[ext_resource type="PackedScene" uid="uid://cdr4m7pydqk6u" path="res://Scenes/Interactable/control_pad_red_keycard.tscn" id="24_fdi4d"]
[ext_resource type="Script" uid="uid://c8hd02ggvk1p2" path="res://Scripts/Actors/AlarmTeleporterActorSpawner.cs" id="24_uh2op"]
@ -53,6 +54,12 @@ Targets = Array[NodePath]([NodePath("../WallEmitter"), NodePath("../WallEmitter2
WaitForCompletion = true
metadata/_custom_type_script = "uid://bwox5lmgiijcs"
[sub_resource type="Curve2D" id="Curve2D_hw1so"]
_data = {
"points": PackedVector2Array(0, 0, 0, 0, 0, -31, 0, 0, 0, 0, 0, 0)
}
point_count = 2
[node name="GameScene" type="Node2D"]
script = ExtResource("1_t2k72")
PlayerTemplate = ExtResource("2_2jsgm")
@ -144,6 +151,14 @@ EmitCoolDown = 0.5
[node name="AlarmBox" parent="Tilemaps/Actors" instance=ExtResource("23_uaqq6")]
position = Vector2(-9, 516)
[node name="Path2D" type="Path2D" parent="Tilemaps/Actors/AlarmBox"]
position = Vector2(-56, 60)
curve = SubResource("Curve2D_hw1so")
metadata/_edit_group_ = true
[node name="Elevator" parent="Tilemaps/Actors/AlarmBox/Path2D" node_paths=PackedStringArray("ElevatorPath") instance=ExtResource("23_577wb")]
ElevatorPath = NodePath("..")
[node name="AlarmBox2" parent="Tilemaps/Actors" instance=ExtResource("23_uaqq6")]
position = Vector2(73, 247)

File diff suppressed because one or more lines are too long

View file

@ -12,6 +12,10 @@ public partial class Bottom : BaseState<ElevatorState, ElevatorProxy>
MainObject.SetPosition(MainObject.Bottom);
MainObject.Activated += ElevatorActivated;
// Enable top body
MainObject.TopBody.Disabled = false;
}
private void ElevatorActivated(ActivationType type)

View file

@ -15,4 +15,5 @@ public partial class Descending : ElevatorMovementState
protected override Vector2 StartingPosition => MainObject.Top;
protected override Vector2 EndingPosition => MainObject.Bottom;
protected override ElevatorState EndState => ElevatorState.Bottom;
}

View file

@ -10,17 +10,16 @@ namespace Cirno.Scripts.Components.FSM.Elevator;
public abstract partial class ElevatorMovementState : BaseState<ElevatorState, ElevatorProxy>
{
protected GTween Tween;
//protected Node2D OldPlayerParent;
protected abstract Vector2 StartingPosition { get; }
protected abstract Vector2 EndingPosition { get; }
protected abstract ElevatorState EndState { get; }
protected CharacterBody2D PlayerBody => MainObject.CachedPlayer?.StateMachine.MainObject;
public override void EnterState()
{
Tween?.Kill();
@ -31,9 +30,15 @@ public abstract partial class ElevatorMovementState : BaseState<ElevatorState, E
public override void ExitState()
{
Tween?.Kill();
RestorePlayerParent();
RestorePlayerParent();
}
// public override void PhysicsProcessState(double delta)
// {
// base.PhysicsProcessState(delta);
// MainObject.TopBody.SetPosition(MainObject.Top);
// }
private void RestorePlayerParent()
{
if (PlayerBody is null) return;
@ -66,7 +71,7 @@ public abstract partial class ElevatorMovementState : BaseState<ElevatorState, E
.Build();
await Tween.PlayAsync(CancellationToken.None);
StateMachine.SetState(EndState);
}
}

View file

@ -7,27 +7,27 @@ 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);
[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; }
[Export] public CollisionShape2D TopBody { 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 IStateMachine<ElevatorState, ElevatorProxy> StateMachine { get; set; }
// public void SetPosition(Vector2 position)
// {
//
// }
public InteractionController CachedPlayer { get; private set; }
public bool Activate(ActivationType activationType = ActivationType.Toggle)
@ -43,7 +43,7 @@ public partial class ElevatorProxy : Area2D, IActivable
CachedPlayer = player;
}
}
private void _on_area_exited(Area2D area)
{
if (area is InteractionController player)

View file

@ -9,6 +9,8 @@ public partial class Init : BaseState<ElevatorState, ElevatorProxy>
public override void EnterState()
{
MainObject.StateMachine = StateMachine;
MainObject.TopBody.Position = MainObject.Top;
StateMachine.SetState(MainObject.StartingState);
}

View file

@ -11,6 +11,9 @@ public partial class Top : BaseState<ElevatorState, ElevatorProxy>
MainObject.SetPosition(MainObject.ElevatorPath.Curve.GetPointPosition(0));
MainObject.Activated += ElevatorActivated;
// Disable top body
MainObject.TopBody.Disabled = true;
}
private void ElevatorActivated(ActivationType type)
@ -42,5 +45,7 @@ public partial class Top : BaseState<ElevatorState, ElevatorProxy>
public override void ExitState()
{
MainObject.Activated -= ElevatorActivated;
// Enable top body
MainObject.TopBody.Disabled = false;
}
}

View file

@ -1,4 +1,4 @@
[gd_resource type="TileSet" load_steps=48 format=3 uid="uid://6k28roiljylj"]
[gd_resource type="TileSet" load_steps=49 format=3 uid="uid://6k28roiljylj"]
[ext_resource type="Texture2D" uid="uid://tphqodqyere1" path="res://Tilesets/factory.png" id="1_70kxh"]
[ext_resource type="PackedScene" uid="uid://bj28qiai2x2ar" path="res://Scenes/Props/Barrel.tscn" id="2_cxg4b"]
@ -157,6 +157,12 @@ polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3)])
outlines = Array[PackedVector2Array]([PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)])
agent_radius = 0.0
[sub_resource type="NavigationPolygon" id="NavigationPolygon_y1d7q"]
vertices = PackedVector2Array(8, 8, -8, 8, -8, -8, 8, -8)
polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3)])
outlines = Array[PackedVector2Array]([PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)])
agent_radius = 0.0
[sub_resource type="NavigationPolygon" id="NavigationPolygon_vkcfe"]
vertices = PackedVector2Array(8, 8, -8, 8, -8, -8, 8, -8)
polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3)])
@ -968,8 +974,11 @@ texture = ExtResource("1_70kxh")
9:15/0/physics_layer_1/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)
8:15/0 = 0
8:15/0/physics_layer_1/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)
7:15/next_alternative_id = 2
7:15/0 = 0
7:15/0/physics_layer_1/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)
7:15/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_y1d7q")
7:15/1 = 1
6:15/0 = 0
6:15/0/physics_layer_1/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)
11:8/0 = 0