mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-07-02 14:11:15 +00:00
Elevators move players
This commit is contained in:
parent
8b378abef3
commit
2e0ad40f33
8 changed files with 156 additions and 93 deletions
|
|
@ -10,15 +10,18 @@
|
||||||
[ext_resource type="Script" uid="uid://72sfdklqrc6d" path="res://Scripts/Components/FSM/Elevator/Descending.cs" id="8_flmvm"]
|
[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"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_3lpp4"]
|
||||||
size = Vector2(32, 32)
|
size = Vector2(20, 19)
|
||||||
|
|
||||||
[node name="Elevator" type="Area2D"]
|
[node name="Elevator" type="Area2D"]
|
||||||
|
collision_layer = 0
|
||||||
|
collision_mask = 2
|
||||||
script = ExtResource("1_xv5vg")
|
script = ExtResource("1_xv5vg")
|
||||||
|
|
||||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||||
texture = ExtResource("1_0xq5m")
|
texture = ExtResource("1_0xq5m")
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
|
position = Vector2(0, -0.5)
|
||||||
shape = SubResource("RectangleShape2D_3lpp4")
|
shape = SubResource("RectangleShape2D_3lpp4")
|
||||||
|
|
||||||
[node name="StateMachine" type="Node2D" parent="."]
|
[node name="StateMachine" type="Node2D" parent="."]
|
||||||
|
|
@ -40,3 +43,6 @@ script = ExtResource("7_r4wj7")
|
||||||
script = ExtResource("8_flmvm")
|
script = ExtResource("8_flmvm")
|
||||||
|
|
||||||
[node name="Disabled" type="Node2D" parent="StateMachine"]
|
[node name="Disabled" type="Node2D" parent="StateMachine"]
|
||||||
|
|
||||||
|
[connection signal="area_entered" from="." to="." method="_on_area_entered"]
|
||||||
|
[connection signal="area_exited" from="." to="." method="_on_area_exited"]
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -8,40 +8,10 @@ using GTweensGodot.Extensions;
|
||||||
|
|
||||||
namespace Cirno.Scripts.Components.FSM.Elevator;
|
namespace Cirno.Scripts.Components.FSM.Elevator;
|
||||||
|
|
||||||
public partial class Ascending : BaseState<ElevatorState, ElevatorProxy>
|
public partial class Ascending : ElevatorMovementState
|
||||||
{
|
{
|
||||||
public override ElevatorState StateId => ElevatorState.Ascending;
|
public override ElevatorState StateId => ElevatorState.Ascending;
|
||||||
|
protected override Vector2 StartingPosition => MainObject.Bottom;
|
||||||
private GTween _tween;
|
protected override Vector2 EndingPosition => MainObject.Top;
|
||||||
|
protected override ElevatorState EndState => ElevatorState.Top;
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -8,40 +8,11 @@ using GTweensGodot.Extensions;
|
||||||
|
|
||||||
namespace Cirno.Scripts.Components.FSM.Elevator;
|
namespace Cirno.Scripts.Components.FSM.Elevator;
|
||||||
|
|
||||||
public partial class Descending : BaseState<ElevatorState, ElevatorProxy>
|
public partial class Descending : ElevatorMovementState
|
||||||
{
|
{
|
||||||
public override ElevatorState StateId => ElevatorState.Descending;
|
public override ElevatorState StateId => ElevatorState.Descending;
|
||||||
|
|
||||||
private GTween _tween;
|
protected override Vector2 StartingPosition => MainObject.Top;
|
||||||
|
protected override Vector2 EndingPosition => MainObject.Bottom;
|
||||||
public override void EnterState()
|
protected override ElevatorState EndState => ElevatorState.Bottom;
|
||||||
{
|
|
||||||
_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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
72
Scripts/Components/FSM/Elevator/ElevatorMovementState.cs
Normal file
72
Scripts/Components/FSM/Elevator/ElevatorMovementState.cs
Normal file
|
|
@ -0,0 +1,72 @@
|
||||||
|
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 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();
|
||||||
|
MainObject.SetPosition(StartingPosition);
|
||||||
|
Move();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ExitState()
|
||||||
|
{
|
||||||
|
Tween?.Kill();
|
||||||
|
RestorePlayerParent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RestorePlayerParent()
|
||||||
|
{
|
||||||
|
if (PlayerBody is null) return;
|
||||||
|
PlayerBody.Reparent(OldPlayerParent);
|
||||||
|
OldPlayerParent = null;
|
||||||
|
MainObject.CachedPlayer?.StateMachine.SetState(PlayerState.Active);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CatchPlayer()
|
||||||
|
{
|
||||||
|
if (PlayerBody is null) return;
|
||||||
|
OldPlayerParent = PlayerBody.GetParent<Node2D>();
|
||||||
|
MainObject.CachedPlayer.StateMachine.SetState(PlayerState.Cutscene);
|
||||||
|
PlayerBody.Reparent(MainObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Move()
|
||||||
|
{
|
||||||
|
// Grab player if in range
|
||||||
|
CatchPlayer();
|
||||||
|
|
||||||
|
//Ascend
|
||||||
|
_ = PlayAnimation();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task PlayAnimation()
|
||||||
|
{
|
||||||
|
Tween = GTweenSequenceBuilder.New()
|
||||||
|
.Append(MainObject.TweenPosition(EndingPosition, MainObject.MovementTime))
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
await Tween.PlayAsync(CancellationToken.None);
|
||||||
|
|
||||||
|
StateMachine.SetState(EndState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
uid://bfqgithjaweqr
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using Cirno.Scripts.Enums;
|
using Cirno.Scripts.Enums;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
|
|
@ -27,8 +28,26 @@ public partial class ElevatorProxy : Area2D, IActivable
|
||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
public InteractionController CachedPlayer { get; private set; }
|
||||||
|
|
||||||
public void Activate(ActivationType activationType = ActivationType.Toggle)
|
public void Activate(ActivationType activationType = ActivationType.Toggle)
|
||||||
{
|
{
|
||||||
EmitSignal(SignalName.Activated, (int)activationType);
|
EmitSignal(SignalName.Activated, (int)activationType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void _on_area_entered(Area2D area)
|
||||||
|
{
|
||||||
|
if (area is InteractionController player)
|
||||||
|
{
|
||||||
|
CachedPlayer = player;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void _on_area_exited(Area2D area)
|
||||||
|
{
|
||||||
|
if (area is InteractionController player)
|
||||||
|
{
|
||||||
|
CachedPlayer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue