mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-09 04:55:54 +00:00
FSM Player input
This commit is contained in:
parent
c59a480ffd
commit
cc0d698bb5
7 changed files with 180 additions and 106 deletions
|
|
@ -9,4 +9,10 @@ public abstract partial class InputProvider : Node2D
|
|||
|
||||
public abstract bool GetActionJustPressed(string action);
|
||||
public abstract bool GetActionPressed(string action);
|
||||
|
||||
public abstract bool GetShootPressed();
|
||||
public abstract bool GetUseJustPressed();
|
||||
public abstract bool GetStrafePressed();
|
||||
public abstract bool GetWeaponNextJustPressed();
|
||||
public abstract bool GetWeaponPreviousJustPressed();
|
||||
}
|
||||
|
|
@ -4,9 +4,36 @@ namespace Cirno.Scripts.Components.Actors;
|
|||
|
||||
public partial class KeyboardInputProvider : InputProvider
|
||||
{
|
||||
[ExportCategory("Movement")]
|
||||
[Export]
|
||||
public string LeftAxisName { get; private set; } = "left";
|
||||
[Export]
|
||||
public string RightAxisName { get; private set; } = "right";
|
||||
[Export]
|
||||
public string UpAxisName { get; private set; } = "up";
|
||||
[Export]
|
||||
public string DownAxisName { get; private set; } = "down";
|
||||
|
||||
[ExportCategory("Aiming")]
|
||||
[Export]
|
||||
public string LeftAimName { get; private set; } = "aim_left";
|
||||
[Export]
|
||||
public string RightAimName { get; private set; } = "aim_right";
|
||||
[Export]
|
||||
public string UpAimName { get; private set; } = "aim_up";
|
||||
[Export]
|
||||
public string DownAimName { get; private set; } = "aim_down";
|
||||
|
||||
[ExportCategory("Action Names")]
|
||||
[Export] private string _shootActionName = "shoot";
|
||||
[Export] private string _useActionName = "Use";
|
||||
[Export] private string _strafeActionName = "strafe";
|
||||
[Export] private string _nextWeaponActionName = "next_weapon";
|
||||
[Export] private string _previousWeaponActionName = "previous_weapon";
|
||||
|
||||
public override Vector2 GetMovementInput()
|
||||
{
|
||||
return Input.GetVector("left", "right", "up", "down");
|
||||
return Input.GetVector(LeftAxisName, RightAxisName, UpAxisName, DownAxisName);
|
||||
}
|
||||
|
||||
public override Vector2 GetAimInput()
|
||||
|
|
@ -17,8 +44,8 @@ public partial class KeyboardInputProvider : InputProvider
|
|||
private Vector2 GetRightStickInput()
|
||||
{
|
||||
return new Vector2(
|
||||
Input.GetAxis("aim_left","aim_right"),
|
||||
Input.GetAxis("aim_up", "aim_down")
|
||||
Input.GetAxis(LeftAimName,RightAimName),
|
||||
Input.GetAxis(UpAimName, DownAimName)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -31,4 +58,30 @@ public partial class KeyboardInputProvider : InputProvider
|
|||
{
|
||||
return Input.IsActionPressed(action);
|
||||
}
|
||||
|
||||
public override bool GetShootPressed()
|
||||
{
|
||||
return GetActionPressed(_shootActionName);
|
||||
}
|
||||
|
||||
public override bool GetUseJustPressed()
|
||||
{
|
||||
return GetActionJustPressed(_useActionName);
|
||||
}
|
||||
|
||||
public override bool GetStrafePressed()
|
||||
{
|
||||
return GetActionPressed(_strafeActionName);
|
||||
}
|
||||
|
||||
public override bool GetWeaponNextJustPressed()
|
||||
{
|
||||
return GetActionJustPressed(_nextWeaponActionName);
|
||||
}
|
||||
|
||||
public override bool GetWeaponPreviousJustPressed()
|
||||
{
|
||||
return GetActionJustPressed(_previousWeaponActionName);
|
||||
}
|
||||
|
||||
}
|
||||
48
Scripts/Components/Actors/PlayerAnimationProvider.cs
Normal file
48
Scripts/Components/Actors/PlayerAnimationProvider.cs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
using Godot;
|
||||
|
||||
public partial class PlayerAnimationProvider : Node2D
|
||||
{
|
||||
[Export]
|
||||
public AnimatedSprite2D _animatedSprite {get; private set;}
|
||||
|
||||
[ExportCategory("Animation Names")]
|
||||
[Export]
|
||||
public string WalkRightAnimationName {get; private set;} = "walk_right";
|
||||
|
||||
[Export]
|
||||
public string WalkLeftAnimationName {get; private set;} = "walk_left";
|
||||
[Export]
|
||||
public string WalkDownAnimationName {get; private set;} = "walk_down";
|
||||
[Export]
|
||||
public string WalkUpAnimationName {get; private set;} = "walk_up";
|
||||
|
||||
public void SetAnimation(Vector2 velocity)
|
||||
{
|
||||
if (velocity.X == 0 && velocity.Y == 0)
|
||||
{
|
||||
_animatedSprite.SpeedScale = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_animatedSprite.SpeedScale = 1;
|
||||
}
|
||||
|
||||
if (velocity.X > 0)
|
||||
{
|
||||
_animatedSprite.Play(WalkRightAnimationName);
|
||||
}
|
||||
else if (velocity.X < 0)
|
||||
{
|
||||
_animatedSprite.Play(WalkLeftAnimationName);
|
||||
}
|
||||
else if (velocity.Y > 0)
|
||||
{
|
||||
_animatedSprite.Play(WalkDownAnimationName);
|
||||
}
|
||||
else if (velocity.Y < 0)
|
||||
{
|
||||
_animatedSprite.Play(WalkUpAnimationName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
1
Scripts/Components/Actors/PlayerAnimationProvider.cs.uid
Normal file
1
Scripts/Components/Actors/PlayerAnimationProvider.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bo5sgbv1t8ril
|
||||
Loading…
Add table
Add a link
Reference in a new issue