4 direction dash
This commit is contained in:
parent
26dc7d4f57
commit
8577de2c04
3 changed files with 22 additions and 16 deletions
|
|
@ -59,6 +59,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
|
||||
/// The direction the player is currently holding.
|
||||
/// This vectors components should always be -1/0/1.
|
||||
private Vector2 _currentRawDirection = Vector2.Zero;
|
||||
private Vector2 _currentDirection = Vector2.Zero;
|
||||
|
||||
public bool IsFacingRight { get; private set; } = true;
|
||||
|
|
@ -109,11 +110,12 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
|| @event.IsAction(ActionName.MoveUp)
|
||||
|| @event.IsAction(ActionName.MoveDown))
|
||||
{
|
||||
_currentDirection = To8DirectionVector(Input.GetVector(
|
||||
_currentRawDirection = Input.GetVector(
|
||||
ActionName.MoveLeft,
|
||||
ActionName.MoveRight,
|
||||
ActionName.MoveUp,
|
||||
ActionName.MoveDown));
|
||||
ActionName.MoveDown);
|
||||
_currentDirection = To8DirectionVector(_currentRawDirection);
|
||||
}
|
||||
|
||||
if (Action.TryFromEvent(@event, out var action))
|
||||
|
|
@ -206,16 +208,12 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
IsFacingRight = Mathf.Sign(GetWallNormal().X) > 0;
|
||||
}
|
||||
|
||||
Velocity = velocity;
|
||||
if (!PlatformIgnoreTimer.IsStopped())
|
||||
{
|
||||
CollisionMask = 0b1;
|
||||
}
|
||||
else
|
||||
{
|
||||
CollisionMask = 0b0100_0001;
|
||||
}
|
||||
|
||||
var collideWithPlatforms = PlatformIgnoreTimer.IsStopped();
|
||||
// layer 7 is platforms
|
||||
SetCollisionMaskValue(7, collideWithPlatforms);
|
||||
|
||||
Velocity = velocity;
|
||||
MoveAndSlide();
|
||||
|
||||
{
|
||||
|
|
@ -434,7 +432,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
DashCooldownTimer.Start();
|
||||
DashDirection = (_currentDirection.IsZeroApprox()
|
||||
? FacingVector
|
||||
: _currentDirection
|
||||
: To4DirectionVector(_currentRawDirection)
|
||||
).Normalized();
|
||||
DashHitbox.StartAttack();
|
||||
_playback.Travel("side_dash");
|
||||
|
|
@ -453,6 +451,14 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
s;
|
||||
}
|
||||
|
||||
private static Vector2 To4DirectionVector(Vector2 input)
|
||||
{
|
||||
if (input.IsZeroApprox()) return Vector2.Zero;
|
||||
Vector2 a = input.Abs(), s = input.Sign();
|
||||
return
|
||||
a.Y < a.X ? new(s.X, 0) : new(0, s.Y);
|
||||
}
|
||||
|
||||
private void OnEnemyHit(Hitbox hitbox, Node2D enemy)
|
||||
{
|
||||
if (enemy is not IAttackable attackable) return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue