Added vesna animations
This commit is contained in:
@@ -6,8 +6,15 @@ public partial class Player3D : CharacterBody3D
|
||||
{
|
||||
[Export] private float _speed = 1.0f;
|
||||
[Export] private Camera3D _camera;
|
||||
[Export] private Sprite3D _frontSprite;
|
||||
[Export] private Sprite3D _sideSprite;
|
||||
|
||||
/// <summary>
|
||||
/// The sprite arrays are all setup like this:
|
||||
/// 0 - idle
|
||||
/// 1 - walking
|
||||
/// </summary>
|
||||
[Export] private AnimatedSprite3D[] _frontSpritesAnimated;
|
||||
[Export] private AnimatedSprite3D[] _sideSpritesAnimated;
|
||||
[Export] private AnimatedSprite3D[] _backSpritesAnimated;
|
||||
|
||||
private bool _sideFlipped;
|
||||
|
||||
@@ -40,40 +47,70 @@ public partial class Player3D : CharacterBody3D
|
||||
|
||||
if (X == 0.0 && Y == 0.0)
|
||||
{
|
||||
ActivateFrontSprite(true);
|
||||
ActivateFrontSpriteIdle(0, true, false, false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (X != 0)
|
||||
{
|
||||
ActivateFrontSprite(false);
|
||||
ActivateFrontSpriteIdle(1, false, true, false);
|
||||
|
||||
if (X > 0.0f)
|
||||
{
|
||||
_sideFlipped = false;
|
||||
_sideSprite.FlipH = _sideFlipped;
|
||||
}
|
||||
|
||||
if (X < 0.0f)
|
||||
{
|
||||
_sideFlipped = true;
|
||||
_sideSprite.FlipH = _sideFlipped;
|
||||
}
|
||||
|
||||
foreach (var animatedSprite in _sideSpritesAnimated)
|
||||
{
|
||||
animatedSprite.FlipH = _sideFlipped;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (Y != 0)
|
||||
{
|
||||
ActivateFrontSprite(true);
|
||||
if (Y < 0.0f)
|
||||
{
|
||||
ActivateFrontSpriteIdle(1, false, false, true);
|
||||
}
|
||||
|
||||
if (Y > 0.0f)
|
||||
{
|
||||
ActivateFrontSpriteIdle(0, true, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ActivateFrontSprite(bool activate)
|
||||
private void ActivateFrontSpriteIdle(int index, bool frontActive, bool sideActive, bool backActive)
|
||||
{
|
||||
_frontSprite.Visible = activate;
|
||||
_sideSprite.Visible = !activate;
|
||||
DeactivateAll();
|
||||
_frontSpritesAnimated[index].Visible = frontActive;
|
||||
_sideSpritesAnimated[index].Visible = sideActive;
|
||||
_backSpritesAnimated[index].Visible = backActive;
|
||||
}
|
||||
|
||||
private void DeactivateAll()
|
||||
{
|
||||
foreach (var animatedSprite in _frontSpritesAnimated)
|
||||
{
|
||||
animatedSprite.Visible = false;
|
||||
}
|
||||
|
||||
foreach (var animatedSprite in _sideSpritesAnimated)
|
||||
{
|
||||
animatedSprite.Visible = false;
|
||||
}
|
||||
|
||||
foreach (var animatedSprite in _backSpritesAnimated)
|
||||
{
|
||||
animatedSprite.Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user