SupaLidlGame/State/Weapon/SwordAnticipateState.cs

48 lines
1.2 KiB
C#
Raw Permalink Normal View History

2023-05-23 00:23:53 -07:00
using Godot;
2023-06-03 18:21:46 -07:00
namespace SupaLidlGame.State.Weapon;
public partial class SwordAnticipateState : WeaponState
2023-05-23 00:23:53 -07:00
{
2023-06-03 18:21:46 -07:00
[Export]
public SupaLidlGame.Items.Weapons.Sword Sword { get; set; }
[Export]
public SwordAttackState AttackState { get; set; }
2023-05-23 00:23:53 -07:00
2023-07-23 23:39:20 -07:00
[Export]
public bool HasAlternateAninmation { get; set; } = false;
2023-06-03 18:21:46 -07:00
private double _anticipateTime;
2023-05-23 00:23:53 -07:00
2023-06-03 18:21:46 -07:00
public override WeaponState Enter(IState<WeaponState> prevState)
{
if (Sword.Character is SupaLidlGame.Characters.Player)
{
return AttackState;
}
2023-05-23 00:23:53 -07:00
2023-07-23 23:39:20 -07:00
float rotThreshold = Mathf.DegToRad(50);
if (HasAlternateAninmation && Sword.Anchor.Rotation > rotThreshold)
2023-06-03 18:21:46 -07:00
{
Sword.AnimationPlayer.Play("anticipate_alternate");
}
else
{
Sword.AnimationPlayer.Play("anticipate");
2023-05-23 00:23:53 -07:00
}
2023-06-03 18:21:46 -07:00
_anticipateTime = Sword.NPCAnticipateTime;
return null;
}
2023-05-23 00:23:53 -07:00
2023-06-03 18:21:46 -07:00
public override WeaponState Process(double delta)
{
// go into attack state if anticipation time is delta
if ((_anticipateTime -= delta) <= 0)
2023-05-23 00:23:53 -07:00
{
2023-06-03 18:21:46 -07:00
return AttackState;
2023-05-23 00:23:53 -07:00
}
2023-06-03 18:21:46 -07:00
return null;
2023-05-23 00:23:53 -07:00
}
}