modular movement ability states

godot-4.2
John Montagu, the 4th Earl of Sandvich 2023-09-16 22:14:23 -07:00
parent 42da94cd63
commit b167354ba7
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
4 changed files with 23 additions and 7 deletions

View File

@ -18,6 +18,11 @@ public partial class CharacterDashState : CharacterState
public Vector2 DashDirection = Vector2.Zero; public Vector2 DashDirection = Vector2.Zero;
public CharacterDashState()
{
CanEnterWhileUsingItem = true;
}
public override IState<CharacterState> Enter(IState<CharacterState> previousState) public override IState<CharacterState> Enter(IState<CharacterState> previousState)
{ {
_timeLeftToDash = TimeToDash; _timeLeftToDash = TimeToDash;

View File

@ -7,6 +7,8 @@ public abstract partial class CharacterState : Node, IState<CharacterState>
[Export] [Export]
public Characters.Character Character { get; set; } public Characters.Character Character { get; set; }
public bool CanEnterWhileUsingItem { get; set; }
public virtual IState<CharacterState> Enter(IState<CharacterState> prev) => null; public virtual IState<CharacterState> Enter(IState<CharacterState> prev) => null;
public virtual void Exit(IState<CharacterState> next) public virtual void Exit(IState<CharacterState> next)

View File

@ -5,10 +5,7 @@ namespace SupaLidlGame.State.Character;
public partial class PlayerMoveState : PlayerState public partial class PlayerMoveState : PlayerState
{ {
[Export] [Export]
public PlayerRollState RollState { get; set; } public CharacterState AbilityState { get; set; }
[Export]
public CharacterDashState DashState { get; set; }
public double MoveDuration { get; private set; } public double MoveDuration { get; private set; }
@ -36,14 +33,21 @@ public partial class PlayerMoveState : PlayerState
{ {
if (Character.Inventory.SelectedItem is Items.Weapon weapon) if (Character.Inventory.SelectedItem is Items.Weapon weapon)
{ {
if (!weapon.IsUsing) bool canUseAbility = true;
if (!AbilityState.CanEnterWhileUsingItem && weapon.IsUsing)
{ {
return RollState; canUseAbility = false;
}
if (canUseAbility)
{
return AbilityState;
} }
} }
else else
{ {
return RollState; return AbilityState;
} }
} }
return base.Input(@event); return base.Input(@event);

View File

@ -10,6 +10,11 @@ public partial class PlayerRollState : PlayerState
private GpuParticles2D _particles; private GpuParticles2D _particles;
public PlayerRollState()
{
CanEnterWhileUsingItem = false;
}
public override void _Ready() public override void _Ready()
{ {
base._Ready(); base._Ready();