added very basic parry functionality

closes #3
This commit is contained in:
Lilith Schier 2026-08-03 19:07:32 +02:00
parent 17a807365b
commit 0d152e62eb
3 changed files with 21 additions and 2 deletions

View file

@ -79,6 +79,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
[Node] private Timer DashCooldownTimer { get; set; } = null!;
[Node] private Timer GlobalDamageImmunityTimer { get; set; } = null!;
[Node] private Timer PlatformIgnoreTimer { get; set; } = null!;
[Node] private Timer ParryTimer { get; set; } = null!;
public void OnReady()
{
@ -284,7 +285,9 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
public void OnProcess(double delta)
{
GetNode<Node2D>("%Body").Scale = new(IsFacingRight ? 1 : -1, 1);
var body = GetNode<Node2D>("%Body");
body.Scale = new(IsFacingRight ? 1 : -1, 1);
body.Modulate = ParryTimer.IsStopped() ? Colors.White : new(2f, 2f, 2f);
}
public readonly struct BufferedInput
@ -300,6 +303,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
Jump,
Attack,
Dash,
Parry,
}
private void HandleBufferedInputs()
@ -369,6 +373,10 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
Dash();
return true;
case { Action: Action.Parry, IsPressed: true }:
Parry();
return true;
default:
return false;
}
@ -430,6 +438,8 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
DashHitbox.StartAttack();
}
private void Parry() => ParryTimer.Start();
private static Vector2 To8DirectionVector(Vector2 input)
{
if (input.IsZeroApprox()) return Vector2.Zero;
@ -454,6 +464,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
public void GetAttacked(in Attack attack)
{
if (!ParryTimer.IsStopped()) return;
TakeDamage(attack.Damage);
}
@ -477,7 +488,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
public void OnAttacked(Hurtbox hurtbox, in Attack attack)
{
TakeDamage(attack.Damage);
GetAttacked(attack);
}
public void OnHurtboxAdded(Hurtbox hurtbox)
@ -501,6 +512,7 @@ public static class GameActionExtensions
(ActionName.Attack, Player.Action.Attack),
(ActionName.Dash, Player.Action.Dash),
(ActionName.Jump, Player.Action.Jump),
(ActionName.Parry, Player.Action.Parry),
];
extension(Player.Action)