Refactored states
This commit is contained in:
parent
7bc6454ce1
commit
740c7c8ea2
2
Dungeon RPG.sln.DotSettings.user
Normal file
2
Dungeon RPG.sln.DotSettings.user
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANode_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003Ff1d69ec2da76ccf9bc8a75c8e0fdca9a7ba1adf8c8c9d5047e2fa5991c02eca_003FNode_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
|
||||||
@ -192,3 +192,7 @@ script = ExtResource("33_4yec0")
|
|||||||
|
|
||||||
[node name="DashState" type="Node" parent="StateMachine"]
|
[node name="DashState" type="Node" parent="StateMachine"]
|
||||||
script = ExtResource("41_2qsty")
|
script = ExtResource("41_2qsty")
|
||||||
|
|
||||||
|
[node name="Timer" type="Timer" parent="StateMachine/DashState"]
|
||||||
|
wait_time = 0.4
|
||||||
|
one_shot = true
|
||||||
|
|||||||
@ -12,12 +12,6 @@ public partial class Player : CharacterBody3D
|
|||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
public override void _PhysicsProcess(double delta)
|
|
||||||
{
|
|
||||||
Velocity = new Vector3(Direction.X, 0, Direction.Y);
|
|
||||||
Velocity *= 5;
|
|
||||||
MoveAndSlide();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void _Input(InputEvent @event)
|
public override void _Input(InputEvent @event)
|
||||||
{
|
{
|
||||||
@ -34,4 +28,8 @@ public partial class Player : CharacterBody3D
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,41 +2,41 @@ using Godot;
|
|||||||
using System;
|
using System;
|
||||||
using DungeonRPG.Scripts.General;
|
using DungeonRPG.Scripts.General;
|
||||||
|
|
||||||
public partial class PlayerDashState : Node
|
public partial class PlayerDashState : PlayerState
|
||||||
{
|
{
|
||||||
private Player characterNode;
|
|
||||||
|
|
||||||
|
private Timer timer;
|
||||||
|
|
||||||
|
[Export] private float speed = 10;
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
characterNode = GetOwner<Player>();
|
base._Ready();
|
||||||
SetPhysicsProcess(false);
|
timer = GetNode<Timer>("Timer");
|
||||||
SetProcessInput(false);
|
timer.Timeout += HandleDashTimeout;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _PhysicsProcess(double delta)
|
public override void _PhysicsProcess(double delta)
|
||||||
{
|
{
|
||||||
|
characterNode.MoveAndSlide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public override void _Notification(int what)
|
protected override void EnterState()
|
||||||
{
|
{
|
||||||
base._Notification(what);
|
characterNode.AnimatedSprite.Play(GameConstants.ANIM_DASH);
|
||||||
|
characterNode.Velocity = new Vector3(characterNode.Direction.X, 0, characterNode.Direction.Y);
|
||||||
|
|
||||||
if (what == GameConstants.STATE_NOTIFICATION_ENABLE)
|
if (characterNode.Velocity == Vector3.Zero)
|
||||||
{
|
{
|
||||||
characterNode.AnimatedSprite.Play(GameConstants.ANIM_DASH);
|
characterNode.Velocity = characterNode.AnimatedSprite.FlipH ? Vector3.Left : Vector3.Right;
|
||||||
SetPhysicsProcess(true);
|
|
||||||
SetProcessInput(true);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (what == GameConstants.STATE_NOTIFICATION_DISABLE)
|
|
||||||
{
|
characterNode.Velocity *= speed;
|
||||||
SetPhysicsProcess(false);
|
timer.Start();
|
||||||
SetProcessInput(false);
|
}
|
||||||
|
|
||||||
}
|
private void HandleDashTimeout()
|
||||||
|
{
|
||||||
|
characterNode.StateMachine.SwitchState<PlayerIdleState>();
|
||||||
|
characterNode.Velocity = Vector3.Zero;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2,15 +2,9 @@ using Godot;
|
|||||||
using System;
|
using System;
|
||||||
using DungeonRPG.Scripts.General;
|
using DungeonRPG.Scripts.General;
|
||||||
|
|
||||||
public partial class PlayerIdleState : Node
|
public partial class PlayerIdleState : PlayerState
|
||||||
{
|
{
|
||||||
private Player characterNode;
|
|
||||||
public override void _Ready()
|
|
||||||
{
|
|
||||||
characterNode = GetOwner<Player>();
|
|
||||||
SetPhysicsProcess(false);
|
|
||||||
SetProcessInput(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void _PhysicsProcess(double delta)
|
public override void _PhysicsProcess(double delta)
|
||||||
{
|
{
|
||||||
@ -28,21 +22,10 @@ public partial class PlayerIdleState : Node
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _Notification(int what)
|
protected override void EnterState()
|
||||||
{
|
{
|
||||||
base._Notification(what);
|
base.EnterState();
|
||||||
|
|
||||||
if (what == GameConstants.STATE_NOTIFICATION_ENABLE)
|
|
||||||
{
|
|
||||||
characterNode.AnimatedSprite.Play(GameConstants.ANIM_IDLE);
|
|
||||||
SetPhysicsProcess(true);
|
|
||||||
SetProcessInput(true);
|
|
||||||
}
|
|
||||||
else if (what == GameConstants.STATE_NOTIFICATION_DISABLE)
|
|
||||||
{
|
|
||||||
SetPhysicsProcess(false);
|
|
||||||
SetProcessInput(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
characterNode.AnimatedSprite.Play(GameConstants.ANIM_IDLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,24 +2,19 @@ using Godot;
|
|||||||
using System;
|
using System;
|
||||||
using DungeonRPG.Scripts.General;
|
using DungeonRPG.Scripts.General;
|
||||||
|
|
||||||
public partial class PlayerMoveState : Node
|
public partial class PlayerMoveState : PlayerState
|
||||||
{
|
{
|
||||||
private Player characterNode;
|
|
||||||
|
|
||||||
public override void _Ready()
|
|
||||||
{
|
|
||||||
characterNode = GetOwner<Player>();
|
|
||||||
SetPhysicsProcess(false);
|
|
||||||
SetProcessInput(false);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void _PhysicsProcess(double delta)
|
public override void _PhysicsProcess(double delta)
|
||||||
{
|
{
|
||||||
if (characterNode.Direction == Vector2.Zero)
|
if (characterNode.Direction == Vector2.Zero)
|
||||||
{
|
{
|
||||||
characterNode.StateMachine.SwitchState<PlayerIdleState>();
|
characterNode.StateMachine.SwitchState<PlayerIdleState>();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
characterNode.Velocity = new Vector3(characterNode.Direction.X, 0, characterNode.Direction.Y);
|
||||||
|
characterNode.Velocity *= 5;
|
||||||
|
characterNode.MoveAndSlide();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _Input(InputEvent @event)
|
public override void _Input(InputEvent @event)
|
||||||
@ -29,23 +24,8 @@ public partial class PlayerMoveState : Node
|
|||||||
characterNode.StateMachine.SwitchState<PlayerDashState>();
|
characterNode.StateMachine.SwitchState<PlayerDashState>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
protected override void EnterState()
|
||||||
public override void _Notification(int what)
|
|
||||||
{
|
{
|
||||||
base._Notification(what);
|
characterNode.AnimatedSprite.Play(GameConstants.ANIM_MOVE);
|
||||||
|
|
||||||
if (what == GameConstants.STATE_NOTIFICATION_ENABLE)
|
|
||||||
{
|
|
||||||
characterNode.AnimatedSprite.Play(GameConstants.ANIM_MOVE);
|
|
||||||
SetPhysicsProcess(true);
|
|
||||||
SetProcessInput(true);
|
|
||||||
|
|
||||||
}
|
|
||||||
else if (what == GameConstants.STATE_NOTIFICATION_DISABLE)
|
|
||||||
{
|
|
||||||
SetPhysicsProcess(false);
|
|
||||||
SetProcessInput(false);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
36
Scripts/Characters/Player/PlayerState.cs
Normal file
36
Scripts/Characters/Player/PlayerState.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
using DungeonRPG.Scripts.General;
|
||||||
|
using Godot;
|
||||||
|
|
||||||
|
|
||||||
|
public partial class PlayerState : Node
|
||||||
|
{
|
||||||
|
protected Player characterNode;
|
||||||
|
public override void _Ready()
|
||||||
|
{
|
||||||
|
characterNode = GetOwner<Player>();
|
||||||
|
SetPhysicsProcess(false);
|
||||||
|
SetProcessInput(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void _Notification(int what)
|
||||||
|
{
|
||||||
|
base._Notification(what);
|
||||||
|
|
||||||
|
if (what == GameConstants.STATE_NOTIFICATION_ENABLE)
|
||||||
|
{
|
||||||
|
SetPhysicsProcess(true);
|
||||||
|
SetProcessInput(true);
|
||||||
|
EnterState();
|
||||||
|
}
|
||||||
|
else if (what == GameConstants.STATE_NOTIFICATION_DISABLE)
|
||||||
|
{
|
||||||
|
SetPhysicsProcess(false);
|
||||||
|
SetProcessInput(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected virtual void EnterState()
|
||||||
|
{ }
|
||||||
|
}
|
||||||
1
Scripts/Characters/Player/PlayerState.cs.uid
Normal file
1
Scripts/Characters/Player/PlayerState.cs.uid
Normal file
@ -0,0 +1 @@
|
|||||||
|
uid://c0jjjfwcbxi2s
|
||||||
Loading…
Reference in New Issue
Block a user