parent
17a807365b
commit
0d152e62eb
3 changed files with 21 additions and 2 deletions
|
|
@ -9,4 +9,5 @@ public static class ActionName
|
||||||
public static readonly StringName Jump = "jump";
|
public static readonly StringName Jump = "jump";
|
||||||
public static readonly StringName Attack = "attack";
|
public static readonly StringName Attack = "attack";
|
||||||
public static readonly StringName Dash = "dash";
|
public static readonly StringName Dash = "dash";
|
||||||
|
public static readonly StringName Parry = "parry";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
[Node] private Timer DashCooldownTimer { get; set; } = null!;
|
[Node] private Timer DashCooldownTimer { get; set; } = null!;
|
||||||
[Node] private Timer GlobalDamageImmunityTimer { get; set; } = null!;
|
[Node] private Timer GlobalDamageImmunityTimer { get; set; } = null!;
|
||||||
[Node] private Timer PlatformIgnoreTimer { get; set; } = null!;
|
[Node] private Timer PlatformIgnoreTimer { get; set; } = null!;
|
||||||
|
[Node] private Timer ParryTimer { get; set; } = null!;
|
||||||
|
|
||||||
public void OnReady()
|
public void OnReady()
|
||||||
{
|
{
|
||||||
|
|
@ -284,7 +285,9 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
|
|
||||||
public void OnProcess(double delta)
|
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
|
public readonly struct BufferedInput
|
||||||
|
|
@ -300,6 +303,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
Jump,
|
Jump,
|
||||||
Attack,
|
Attack,
|
||||||
Dash,
|
Dash,
|
||||||
|
Parry,
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleBufferedInputs()
|
private void HandleBufferedInputs()
|
||||||
|
|
@ -369,6 +373,10 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
Dash();
|
Dash();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
case { Action: Action.Parry, IsPressed: true }:
|
||||||
|
Parry();
|
||||||
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -430,6 +438,8 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
DashHitbox.StartAttack();
|
DashHitbox.StartAttack();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Parry() => ParryTimer.Start();
|
||||||
|
|
||||||
private static Vector2 To8DirectionVector(Vector2 input)
|
private static Vector2 To8DirectionVector(Vector2 input)
|
||||||
{
|
{
|
||||||
if (input.IsZeroApprox()) return Vector2.Zero;
|
if (input.IsZeroApprox()) return Vector2.Zero;
|
||||||
|
|
@ -454,6 +464,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
|
|
||||||
public void GetAttacked(in Attack attack)
|
public void GetAttacked(in Attack attack)
|
||||||
{
|
{
|
||||||
|
if (!ParryTimer.IsStopped()) return;
|
||||||
TakeDamage(attack.Damage);
|
TakeDamage(attack.Damage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -477,7 +488,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
|
|
||||||
public void OnAttacked(Hurtbox hurtbox, in Attack attack)
|
public void OnAttacked(Hurtbox hurtbox, in Attack attack)
|
||||||
{
|
{
|
||||||
TakeDamage(attack.Damage);
|
GetAttacked(attack);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnHurtboxAdded(Hurtbox hurtbox)
|
public void OnHurtboxAdded(Hurtbox hurtbox)
|
||||||
|
|
@ -501,6 +512,7 @@ public static class GameActionExtensions
|
||||||
(ActionName.Attack, Player.Action.Attack),
|
(ActionName.Attack, Player.Action.Attack),
|
||||||
(ActionName.Dash, Player.Action.Dash),
|
(ActionName.Dash, Player.Action.Dash),
|
||||||
(ActionName.Jump, Player.Action.Jump),
|
(ActionName.Jump, Player.Action.Jump),
|
||||||
|
(ActionName.Parry, Player.Action.Parry),
|
||||||
];
|
];
|
||||||
|
|
||||||
extension(Player.Action)
|
extension(Player.Action)
|
||||||
|
|
|
||||||
|
|
@ -477,3 +477,9 @@ one_shot = true
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
process_callback = 0
|
process_callback = 0
|
||||||
one_shot = true
|
one_shot = true
|
||||||
|
|
||||||
|
[node name="ParryTimer" type="Timer" parent="." unique_id=279087565]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
process_callback = 0
|
||||||
|
wait_time = 0.2
|
||||||
|
one_shot = true
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue