Files
Babushka/scripts/CSharp/Common/CharacterControls/Player2D.cs
T

61 lines
1.2 KiB
C#
Raw Normal View History

using Godot;
2025-04-06 18:46:59 +02:00
namespace Babushka.scripts.CSharp.Common.CharacterControls;
public partial class Player2D : CharacterBody2D
{
[Export] private float _speed = 100f;
2025-04-30 17:36:38 +02:00
[Export] private AnimatedSprite2D _sprite;
private bool anyActionPressed;
public override void _Process(double delta)
{
2025-04-30 17:36:38 +02:00
anyActionPressed = false;
if (Input.IsActionPressed("move_right"))
{
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"))
{
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"))
{
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"))
{
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";
}
}
}