Added basic action animation
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Fight;
|
||||
|
||||
public partial class ActionAnimationController : Node
|
||||
{
|
||||
#region Shortcuts
|
||||
|
||||
private FightWorld.FightHappeningData HappeningData => FightWorld.Instance.fightHappeningData ?? throw new NoFightHappeningException();
|
||||
|
||||
#endregion
|
||||
|
||||
[Export] private AllFightersVisual _allFightersVisual = null!;
|
||||
|
||||
|
||||
public void StateEnter()
|
||||
{
|
||||
_ = HappeningData.actionStaging!.AnimateAction(_allFightersVisual);
|
||||
}
|
||||
|
||||
public void StateExit()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://dtf4ejct4m682
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Babushka.scripts.CSharp.Common.Fight.ActionDetails;
|
||||
using Babushka.scripts.CSharp.Common.Util;
|
||||
using Godot;
|
||||
@@ -43,4 +44,17 @@ public class AllyAttackAction : FighterAction
|
||||
{
|
||||
targetSelect.GetTarget().AddHealth(-5);
|
||||
}
|
||||
|
||||
public override async Task AnimateAction(AllFightersVisual allFightersVisual)
|
||||
{
|
||||
var currentFighter = HappeningData.fighterStack.Current;
|
||||
var targetFighter = targetSelect.GetTarget();
|
||||
|
||||
var currentFighterVisual = allFightersVisual.GetVisualForFighter(currentFighter);
|
||||
var targetFighterVisual = allFightersVisual.GetVisualForFighter(targetFighter);
|
||||
|
||||
await currentFighterVisual.AnimatePosToTarget(targetFighterVisual);
|
||||
_ = targetFighterVisual.AnimateHit();
|
||||
await currentFighterVisual.AnimatePosToBase();
|
||||
}
|
||||
}
|
||||
@@ -122,4 +122,11 @@ public partial class AllFightersVisual : Node
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public FighterVisual GetVisualForFighter(FightWorld.Fighter fighter)
|
||||
{
|
||||
return _fighterVisuals.TryGetValue(fighter, out var visual)
|
||||
? visual
|
||||
: throw new InvalidOperationException("No visual for this fighter");
|
||||
}
|
||||
}
|
||||
@@ -7,10 +7,13 @@ public partial class FightHappeningStateDebugger : Node
|
||||
{
|
||||
[Export] private Label _label;
|
||||
|
||||
[Export] private Label _current;
|
||||
|
||||
private FightWorld.FightHappeningData Data => FightWorld.Instance.fightHappeningData!;
|
||||
|
||||
public void StateChange(FightHappening.FightState from, FightHappening.FightState to)
|
||||
{
|
||||
_current.Text = $"{to}";
|
||||
_label.Text += $"State changed from {from} to {to}\n";
|
||||
switch (to)
|
||||
{
|
||||
@@ -49,5 +52,6 @@ public partial class FightHappeningStateDebugger : Node
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(to), to, null);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,8 @@ public abstract class FighterAction
|
||||
/// <summary>
|
||||
/// Animates the action.
|
||||
/// </summary>
|
||||
public virtual async Task AnimateAction()
|
||||
/// <param name="allFightersVisual"></param>
|
||||
public virtual async Task AnimateAction(AllFightersVisual allFightersVisual)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Babushka.scripts.CSharp.Common.Fight.ActionDetails;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
@@ -67,31 +68,55 @@ public partial class FighterVisual : Node2D
|
||||
}
|
||||
|
||||
// Animations
|
||||
public void AttackAnimation(FightAttack attack)
|
||||
//public void AttackAnimation(FightAttack attack)
|
||||
//{
|
||||
// EmitSignalAttacking();
|
||||
// var tween = GetTree().CreateTween();
|
||||
// tween.TweenProperty(this, "global_position", attack.target.GlobalPosition, 0.15);
|
||||
// tween.TweenCallback(Callable.From(() => attack.target?.HitAnimation(attack)));
|
||||
// tween.TweenProperty(this, "position", new Vector2(0, 0), 0.7)
|
||||
// .SetTrans(Tween.TransitionType.Cubic).SetEase(Tween.EaseType.Out);
|
||||
//}
|
||||
|
||||
public async Task AnimatePosToTarget(FighterVisual targetVisual, double duration = 0.15)
|
||||
{
|
||||
EmitSignalAttacking();
|
||||
var tween = GetTree().CreateTween();
|
||||
tween.TweenProperty(this, "global_position", attack.target.GlobalPosition, 0.15);
|
||||
tween.TweenCallback(Callable.From(() => attack.target?.HitAnimation(attack)));
|
||||
tween.TweenProperty(this, "position", new Vector2(0, 0), 0.7)
|
||||
.SetTrans(Tween.TransitionType.Cubic).SetEase(Tween.EaseType.Out);
|
||||
tween.TweenProperty(_visualParent, "global_position", targetVisual.GlobalPosition, 0.15);
|
||||
await ToSignal(tween, "finished");
|
||||
}
|
||||
|
||||
private void HitAnimation(FightAttack attack)
|
||||
public async Task AnimatePosToBase(double duration = 0.7)
|
||||
{
|
||||
var tween = GetTree().CreateTween();
|
||||
tween.TweenProperty(_visualParent, "position", new Vector2(0, 0), 0.15);
|
||||
await ToSignal(tween, "finished");
|
||||
}
|
||||
|
||||
public async Task AnimateHit()
|
||||
{
|
||||
EmitSignalDamageTaken();
|
||||
var tween = GetTree().CreateTween();
|
||||
tween.TweenProperty(this, "scale", new Vector2(1.4f, 0.6f), 0.15);
|
||||
tween.TweenProperty(this, "scale", new Vector2(1, 1), 0.4)
|
||||
.SetTrans(Tween.TransitionType.Cubic).SetEase(Tween.EaseType.Out);
|
||||
await ToSignal(tween, "finished");
|
||||
}
|
||||
|
||||
|
||||
public void HealAnimation()
|
||||
{
|
||||
EmitSignalHealed();
|
||||
var tween = GetTree().CreateTween();
|
||||
tween.TweenProperty(this, "scale", new Vector2(0.6f, 1.4f), 0.15);
|
||||
tween.TweenProperty(this, "scale", new Vector2(1, 1), 0.4)
|
||||
.SetTrans(Tween.TransitionType.Cubic).SetEase(Tween.EaseType.Out);
|
||||
}
|
||||
//private void HitAnimation(FightAttack attack)
|
||||
//{
|
||||
// EmitSignalDamageTaken();
|
||||
// var tween = GetTree().CreateTween();
|
||||
// tween.TweenProperty(this, "scale", new Vector2(1.4f, 0.6f), 0.15);
|
||||
// tween.TweenProperty(this, "scale", new Vector2(1, 1), 0.4)
|
||||
// .SetTrans(Tween.TransitionType.Cubic).SetEase(Tween.EaseType.Out);
|
||||
//}
|
||||
//
|
||||
//public void HealAnimation()
|
||||
//{
|
||||
// EmitSignalHealed();
|
||||
// var tween = GetTree().CreateTween();
|
||||
// tween.TweenProperty(this, "scale", new Vector2(0.6f, 1.4f), 0.15);
|
||||
// tween.TweenProperty(this, "scale", new Vector2(1, 1), 0.4)
|
||||
// .SetTrans(Tween.TransitionType.Cubic).SetEase(Tween.EaseType.Out);
|
||||
//}
|
||||
}
|
||||
Reference in New Issue
Block a user