64 lines
1.9 KiB
C#
64 lines
1.9 KiB
C#
|
|
using Godot;
|
||
|
|
using PokemonLike.Library.Support;
|
||
|
|
using PokemonLike.Library.Utilities;
|
||
|
|
|
||
|
|
namespace PokemonLike.Library.Characters.States;
|
||
|
|
|
||
|
|
[GlobalClass]
|
||
|
|
public partial class PlayerRoamState : State
|
||
|
|
{
|
||
|
|
[ExportCategory("State Vars")]
|
||
|
|
[Export] public PlayerInput PlayerInput;
|
||
|
|
|
||
|
|
public override void _Process(double delta)
|
||
|
|
{
|
||
|
|
GetInputDirection();
|
||
|
|
GetInput(delta);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void GetInputDirection()
|
||
|
|
{
|
||
|
|
if (Input.IsActionJustPressed("move_up"))
|
||
|
|
{
|
||
|
|
PlayerInput.Direction = Vector2.Up;
|
||
|
|
PlayerInput.TargetPosition = new Vector2(0, -Globals.Instance.GRID_SIZE);
|
||
|
|
}
|
||
|
|
else if (Input.IsActionJustPressed("move_down"))
|
||
|
|
{
|
||
|
|
PlayerInput.Direction = Vector2.Down;
|
||
|
|
PlayerInput.TargetPosition = new Vector2(0, Globals.Instance.GRID_SIZE);
|
||
|
|
}
|
||
|
|
else if (Input.IsActionJustPressed("move_left"))
|
||
|
|
{
|
||
|
|
PlayerInput.Direction = Vector2.Left;
|
||
|
|
PlayerInput.TargetPosition = new Vector2(-Globals.Instance.GRID_SIZE, 0);
|
||
|
|
}
|
||
|
|
else if (Input.IsActionJustPressed("move_right"))
|
||
|
|
{
|
||
|
|
PlayerInput.Direction = Vector2.Right;
|
||
|
|
PlayerInput.TargetPosition = new Vector2(Globals.Instance.GRID_SIZE, 0);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void GetInput(double delta)
|
||
|
|
{
|
||
|
|
if (Modules.IsActionJustReleased())
|
||
|
|
{
|
||
|
|
if (PlayerInput.HoldTime > PlayerInput.HoldThreshold)
|
||
|
|
PlayerInput.EmitSignal(CharacterInput.SignalName.Walk);
|
||
|
|
else
|
||
|
|
PlayerInput.EmitSignal(CharacterInput.SignalName.Turn);
|
||
|
|
PlayerInput.HoldThreshold = 0.0f;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (Modules.IsActionPressed())
|
||
|
|
{
|
||
|
|
PlayerInput.HoldTime += delta;
|
||
|
|
|
||
|
|
if (PlayerInput.HoldTime > PlayerInput.HoldThreshold)
|
||
|
|
PlayerInput.EmitSignal(CharacterInput.SignalName.Walk);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|