You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Babushka/scripts/CSharp/Common/CharacterControls/Player2D.cs

61 lines
1.2 KiB

using Godot;
namespace Babushka.scripts.CSharp.Common.CharacterControls;
public partial class Player2D : CharacterBody2D
{
[Export] private float _speed = 100f;
[Export] private AnimatedSprite2D _sprite;
private bool anyActionPressed;
public override void _Process(double delta)
{
anyActionPressed = false;
if (Input.IsActionPressed("move_right"))
{
Velocity = new Vector2(_speed, 0);
MoveAndSlide();
_sprite.FlipH = false;
_sprite.Animation = "side_walking";
anyActionPressed = true;
}
if (Input.IsActionPressed("move_left"))
{
Velocity = new Vector2(-_speed, 0);
MoveAndSlide();
_sprite.FlipH = true;
_sprite.Animation = "side_walking";
anyActionPressed = true;
}
if (Input.IsActionPressed("move_up"))
{
Velocity = new Vector2(0, -_speed);
MoveAndSlide();
_sprite.Animation = "back walking";
anyActionPressed = true;
}
if (Input.IsActionPressed("move_down"))
{
Velocity = new Vector2(0, _speed);
MoveAndSlide();
_sprite.Animation = "front walking";
anyActionPressed = true;
}
if (anyActionPressed)
{
_sprite.Play();
}
else
{
_sprite.Animation = "front idle";
}
}
}