mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:45:33 +00:00
128 lines
3.1 KiB
C#
128 lines
3.1 KiB
C#
using System;
|
|
using Godot;
|
|
|
|
namespace Cirno.Scripts.Components.FSM.Player;
|
|
|
|
public partial class Active : PlayerFSMState
|
|
{
|
|
private Vector2 _movementDirection { get; set; }
|
|
private Vector2 _facingDirection { get; set; }
|
|
|
|
[Export] public Sprite2D HitboxSprite { get; set; }
|
|
|
|
[ExportGroup("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";
|
|
|
|
private bool _isStrafing { get; set; }
|
|
|
|
public override void EnterState()
|
|
{
|
|
// enable sprite
|
|
// enable crosshair
|
|
}
|
|
|
|
public override void ExitState()
|
|
{
|
|
|
|
}
|
|
|
|
public override void PhysicsProcessState(double delta)
|
|
{
|
|
|
|
}
|
|
|
|
public override void ProcessState(double delta)
|
|
{
|
|
SetAnimation();
|
|
|
|
_movementDirection = GetInput();
|
|
_isStrafing = Input.IsActionPressed(_strafeActionName);
|
|
|
|
// Toggle visibility of the hitbox sprite based on strafing
|
|
if (HitboxSprite != null)
|
|
{
|
|
HitboxSprite.Visible = _isStrafing;
|
|
}
|
|
|
|
var rightStickInput = GetRightStickInput();
|
|
|
|
// Update Facing Direction
|
|
if (!_isStrafing)
|
|
{
|
|
if (rightStickInput.Length() > 0.1f) // If the right stick is moved
|
|
{
|
|
_facingDirection = rightStickInput.Normalized();
|
|
}
|
|
else if (_movementDirection != Vector2.Zero) // Fall back to movement direction
|
|
{
|
|
_facingDirection = _movementDirection;
|
|
}
|
|
}
|
|
|
|
// HandleShoot();
|
|
// FindInteractable();
|
|
|
|
// if (Input.IsActionJustPressed(_nextWeaponActionName))
|
|
// {
|
|
// NextWeapon();
|
|
// }
|
|
|
|
// if (Input.IsActionJustPressed(_previousWeaponActionName))
|
|
// {
|
|
// PreviousWeapon();
|
|
// }
|
|
|
|
// _crosshair.Position = CalculateCrosshairPosition();
|
|
|
|
}
|
|
|
|
private void SetAnimation()
|
|
{
|
|
|
|
// if (Velocity.X == 0 && Velocity.Y == 0)
|
|
// {
|
|
// _animatedSprite.SpeedScale = 0;
|
|
// }
|
|
// else
|
|
// {
|
|
// _animatedSprite.SpeedScale = 1;
|
|
// }
|
|
|
|
// if (Velocity.X > 0)
|
|
// {
|
|
// _animatedSprite.Play("walk_right");
|
|
// }
|
|
// else if (Velocity.X < 0)
|
|
// {
|
|
// _animatedSprite.Play("walk_left");
|
|
// }
|
|
// else if (Velocity.Y > 0)
|
|
// {
|
|
// _animatedSprite.Play("walk_down");
|
|
// }
|
|
// else if (Velocity.Y < 0)
|
|
// {
|
|
// _animatedSprite.Play("walk_up");
|
|
// }
|
|
|
|
|
|
}
|
|
|
|
public Vector2 GetInput()
|
|
{
|
|
return Input.GetVector("left", "right", "up", "down");
|
|
}
|
|
|
|
private Vector2 GetRightStickInput()
|
|
{
|
|
return new Vector2(
|
|
Input.GetAxis("aim_left", "aim_right"),
|
|
Input.GetAxis("aim_up", "aim_down")
|
|
);
|
|
}
|
|
|
|
}
|