2025-03-27 23:12:16 +01:00
|
|
|
using Godot;
|
|
|
|
|
|
2025-04-06 18:46:59 +02:00
|
|
|
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
2025-03-27 23:12:16 +01:00
|
|
|
|
2025-05-11 23:20:35 +02:00
|
|
|
public partial class Player2D : CharacterBody2D
|
2025-03-27 23:12:16 +01:00
|
|
|
{
|
|
|
|
|
[Export] private float _speed = 100f;
|
2025-04-30 17:36:38 +02:00
|
|
|
[Export] private AnimatedSprite2D _sprite;
|
|
|
|
|
|
|
|
|
|
private bool anyActionPressed;
|
2025-03-27 23:12:16 +01:00
|
|
|
|
|
|
|
|
public override void _Process(double delta)
|
|
|
|
|
{
|
2025-04-30 17:36:38 +02:00
|
|
|
anyActionPressed = false;
|
|
|
|
|
|
|
|
|
|
if (Input.IsActionPressed("move_right"))
|
|
|
|
|
{
|
2025-05-11 23:20:35 +02:00
|
|
|
Velocity = new Vector2(_speed, 0);
|
|
|
|
|
MoveAndSlide();
|
2025-04-30 17:36:38 +02:00
|
|
|
_sprite.FlipH = false;
|
|
|
|
|
_sprite.Animation = "side_walking";
|
|
|
|
|
anyActionPressed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Input.IsActionPressed("move_left"))
|
|
|
|
|
{
|
2025-05-11 23:20:35 +02:00
|
|
|
Velocity = new Vector2(-_speed, 0);
|
|
|
|
|
MoveAndSlide();
|
2025-04-30 17:36:38 +02:00
|
|
|
_sprite.FlipH = true;
|
|
|
|
|
_sprite.Animation = "side_walking";
|
|
|
|
|
anyActionPressed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Input.IsActionPressed("move_up"))
|
|
|
|
|
{
|
2025-05-11 23:20:35 +02:00
|
|
|
Velocity = new Vector2(0, -_speed);
|
|
|
|
|
MoveAndSlide();
|
2025-04-30 17:36:38 +02:00
|
|
|
_sprite.Animation = "back walking";
|
|
|
|
|
anyActionPressed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Input.IsActionPressed("move_down"))
|
|
|
|
|
{
|
2025-05-11 23:20:35 +02:00
|
|
|
Velocity = new Vector2(0, _speed);
|
|
|
|
|
MoveAndSlide();
|
2025-04-30 17:36:38 +02:00
|
|
|
_sprite.Animation = "front walking";
|
|
|
|
|
anyActionPressed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (anyActionPressed)
|
|
|
|
|
{
|
|
|
|
|
_sprite.Play();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_sprite.Animation = "front idle";
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-27 23:12:16 +01:00
|
|
|
}
|
|
|
|
|
}
|