converting to built-in Godot Timer
This commit is contained in:
parent
7d95a97181
commit
c019911ef3
8 changed files with 156 additions and 154 deletions
|
|
@ -1 +1 @@
|
||||||
uid://dqlh48eqmee0s
|
uid://3n2m6dvndkh3
|
||||||
|
|
|
||||||
|
|
@ -1,54 +0,0 @@
|
||||||
namespace Dancer;
|
|
||||||
|
|
||||||
public sealed class Ticker
|
|
||||||
{
|
|
||||||
[Export] public float Duration { get; set; }
|
|
||||||
public float RemainingTime { get; private set; }
|
|
||||||
public bool IsRunning => RemainingTime > 0f;
|
|
||||||
public bool HasFinishedLastTick { get; private set; }
|
|
||||||
public float LastTickOverflow { get; private set; }
|
|
||||||
|
|
||||||
|
|
||||||
public void Start() => RemainingTime = Duration;
|
|
||||||
|
|
||||||
public Result Tick(float delta)
|
|
||||||
{
|
|
||||||
TickInternal(delta);
|
|
||||||
return
|
|
||||||
RemainingTime > 0f ? Result.Running :
|
|
||||||
HasFinishedLastTick ? Result.Finished :
|
|
||||||
Result.NotRunning;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float TickWithOverflow(float delta)
|
|
||||||
{
|
|
||||||
TickInternal(delta);
|
|
||||||
return LastTickOverflow;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float Reset()
|
|
||||||
{
|
|
||||||
var result = RemainingTime;
|
|
||||||
RemainingTime = 0f;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void TickInternal(float delta)
|
|
||||||
{
|
|
||||||
HasFinishedLastTick = false;
|
|
||||||
LastTickOverflow = 0f;
|
|
||||||
if (RemainingTime == 0f) return;
|
|
||||||
RemainingTime -= delta;
|
|
||||||
if (RemainingTime > 0f) return;
|
|
||||||
LastTickOverflow = -RemainingTime;
|
|
||||||
RemainingTime = 0f;
|
|
||||||
HasFinishedLastTick = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum Result
|
|
||||||
{
|
|
||||||
Running,
|
|
||||||
Finished,
|
|
||||||
NotRunning,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
uid://csmiba8w3bw7d
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
namespace Dancer;
|
namespace Dancer;
|
||||||
|
|
||||||
|
|
||||||
public sealed class Attack
|
public sealed class Attack
|
||||||
{
|
{
|
||||||
public required Node2D Attacker { get; init; }
|
public required Node2D Attacker { get; init; }
|
||||||
|
|
|
||||||
|
|
@ -32,27 +32,15 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
[Export(PropertyHint.None, "suffix:px/s²")]
|
[Export(PropertyHint.None, "suffix:px/s²")]
|
||||||
public float WaterAccel { get; set; } = 1200.0f;
|
public float WaterAccel { get; set; } = 1200.0f;
|
||||||
|
|
||||||
[Export(PropertyHint.None, "suffix:s")]
|
|
||||||
public float JumpAscentMaxDuration { get; set; } = 0.25f;
|
|
||||||
|
|
||||||
[Export(PropertyHint.None, "suffix:px/s")]
|
[Export(PropertyHint.None, "suffix:px/s")]
|
||||||
public float JumpAscentSpeed { get; set; } = 200.0f;
|
public float JumpAscentSpeed { get; set; } = 200.0f;
|
||||||
|
|
||||||
[Export(PropertyHint.None, "suffix:s")]
|
|
||||||
public float LateJumpLimitDuration { get; set; } = 0.1f;
|
|
||||||
|
|
||||||
[Export(PropertyHint.None, "suffix:px/s")]
|
[Export(PropertyHint.None, "suffix:px/s")]
|
||||||
public float SlashSpeedBoost { get; set; } = 90.0f;
|
public float SlashSpeedBoost { get; set; } = 90.0f;
|
||||||
|
|
||||||
[Export(PropertyHint.None, "suffix:s")]
|
|
||||||
public float DashDuration { get; set; } = 0.15f;
|
|
||||||
|
|
||||||
[Export(PropertyHint.None, "suffix:px/s")]
|
[Export(PropertyHint.None, "suffix:px/s")]
|
||||||
public float DashSpeed { get; set; } = 400.0f;
|
public float DashSpeed { get; set; } = 400.0f;
|
||||||
|
|
||||||
[Export(PropertyHint.None, "suffix:s")]
|
|
||||||
public float DashCooldownDuration { get; set; } = 0.6f;
|
|
||||||
|
|
||||||
/// <summary>The angle difference from perfect left/right that still counts.</summary>
|
/// <summary>The angle difference from perfect left/right that still counts.</summary>
|
||||||
[Export(PropertyHint.Range, "0,360,0.1,radians_as_degrees")]
|
[Export(PropertyHint.Range, "0,360,0.1,radians_as_degrees")]
|
||||||
public float SideInputAngle { get; set; } = Mathf.Pi / 4;
|
public float SideInputAngle { get; set; } = Mathf.Pi / 4;
|
||||||
|
|
@ -66,11 +54,8 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
[Export] public bool CanTurn { get; set; } = true;
|
[Export] public bool CanTurn { get; set; } = true;
|
||||||
[Export] public float MaxDashPoints { get; set; } = 2f;
|
[Export] public float MaxDashPoints { get; set; } = 2f;
|
||||||
|
|
||||||
[Export(PropertyHint.None, "suffix:s")]
|
|
||||||
public float GlobalDamageImmunityDuration { get; set; } = 0.5f;
|
|
||||||
|
|
||||||
private ulong MaxInputBufferTimeMicroseconds => (ulong)(MaxInputBufferTime * 1_000_000);
|
private ulong MaxInputBufferTimeMicroseconds => (ulong)(MaxInputBufferTime * 1_000_000);
|
||||||
public bool IsJumping => JumpTicker.IsRunning;
|
public bool IsJumping => !JumpTimer.IsStopped();
|
||||||
|
|
||||||
/// The direction the player is currently holding.
|
/// The direction the player is currently holding.
|
||||||
/// This vectors components should always be -1/0/1.
|
/// This vectors components should always be -1/0/1.
|
||||||
|
|
@ -78,22 +63,22 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
|
|
||||||
public bool IsFacingRight { get; private set; } = true;
|
public bool IsFacingRight { get; private set; } = true;
|
||||||
private AnimationNodeStateMachinePlayback _playback = null!;
|
private AnimationNodeStateMachinePlayback _playback = null!;
|
||||||
private List<BufferedInput> _inputBuffer = [];
|
public List<BufferedInput> InputBuffer { get; } = [];
|
||||||
public bool IsInWater { get; private set; }
|
public bool IsInWater { get; private set; }
|
||||||
private float PlatformIgnoreTime { get; set; }
|
public Vector2 DashDirection { get; set; }
|
||||||
public Ticker JumpAllowedTicker { get; } = new();
|
|
||||||
private Ticker WaterJumpAllowedTicker { get; } = new();
|
|
||||||
private Ticker DashTicker { get; } = new();
|
|
||||||
private Ticker DashCooldown { get; } = new();
|
|
||||||
private Ticker JumpTicker { get; } = new();
|
|
||||||
private Vector2 DashDirection { get; set; }
|
|
||||||
public float DashPoints { get; set; }
|
public float DashPoints { get; set; }
|
||||||
public float BankedDashPoints { get; set; }
|
public float BankedDashPoints { get; set; }
|
||||||
private Ticker GlobalDamageImmunityTicker { get; } = new();
|
|
||||||
|
|
||||||
[Node] private AnimationTree AnimationTree { get; set; } = null!;
|
[Node] private AnimationTree AnimationTree { get; set; } = null!;
|
||||||
[Node] private Area2D SubmersedSensor { get; set; } = null!;
|
[Node] private Area2D SubmersedSensor { get; set; } = null!;
|
||||||
[Node] private Hitbox DashHitbox { get; set; } = null!;
|
[Node] private Hitbox DashHitbox { get; set; } = null!;
|
||||||
|
[Node] private Timer JumpTimer { get; set; } = null!;
|
||||||
|
[Node] private Timer JumpAllowedTimer { get; set; } = null!;
|
||||||
|
[Node] private Timer WaterJumpAllowedTimer { get; set; } = null!;
|
||||||
|
[Node] private Timer DashTimer { get; set; } = null!;
|
||||||
|
[Node] private Timer DashCooldownTimer { get; set; } = null!;
|
||||||
|
[Node] private Timer GlobalDamageImmunityTimer { get; set; } = null!;
|
||||||
|
[Node] private Timer PlatformIgnoreTimer { get; set; } = null!;
|
||||||
|
|
||||||
public void OnReady()
|
public void OnReady()
|
||||||
{
|
{
|
||||||
|
|
@ -102,11 +87,13 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
SetPhysicsProcess(true);
|
SetPhysicsProcess(true);
|
||||||
Health = MaxHealth;
|
Health = MaxHealth;
|
||||||
_playback = AnimationTree.Get("parameters/playback").As<AnimationNodeStateMachinePlayback>();
|
_playback = AnimationTree.Get("parameters/playback").As<AnimationNodeStateMachinePlayback>();
|
||||||
DashTicker.Duration = DashDuration;
|
SubmersedSensor.BodyEntered += OnEnteredWater;
|
||||||
DashCooldown.Duration = DashCooldownDuration;
|
SubmersedSensor.BodyExited += OnLeftWater;
|
||||||
JumpAllowedTicker.Duration = LateJumpLimitDuration;
|
DashTimer.Timeout += () =>
|
||||||
WaterJumpAllowedTicker.Duration = LateJumpLimitDuration;
|
{
|
||||||
GlobalDamageImmunityTicker.Duration = GlobalDamageImmunityDuration;
|
Velocity *= 0.6f;
|
||||||
|
DashHitbox.StopAttack();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _UnhandledInput(InputEvent @event)
|
public override void _UnhandledInput(InputEvent @event)
|
||||||
|
|
@ -129,7 +116,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
|
|
||||||
if (Action.TryFromEvent(@event, out var action))
|
if (Action.TryFromEvent(@event, out var action))
|
||||||
{
|
{
|
||||||
_inputBuffer.Add(new()
|
InputBuffer.Add(new()
|
||||||
{
|
{
|
||||||
Direction = _currentDirection,
|
Direction = _currentDirection,
|
||||||
Action = action,
|
Action = action,
|
||||||
|
|
@ -148,13 +135,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
|
|
||||||
if (CanTurn) AdjustFacing();
|
if (CanTurn) AdjustFacing();
|
||||||
|
|
||||||
if (DashTicker.HasFinishedLastTick)
|
if (!DashTimer.IsStopped())
|
||||||
{
|
|
||||||
velocity *= 0.6f;
|
|
||||||
DashHitbox.StopAttack();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DashTicker.IsRunning)
|
|
||||||
{
|
{
|
||||||
velocity = DashDirection * DashSpeed;
|
velocity = DashDirection * DashSpeed;
|
||||||
}
|
}
|
||||||
|
|
@ -187,18 +168,16 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move up while holding jump
|
// Move up while holding jump
|
||||||
if (JumpTicker.IsRunning)
|
if (!JumpTimer.IsStopped())
|
||||||
{
|
{
|
||||||
velocity.Y = -JumpAscentSpeed;
|
velocity.Y = -JumpAscentSpeed;
|
||||||
var overflow = JumpTicker.TickWithOverflow(deltaF);
|
|
||||||
velocity += GetGravity() * overflow;
|
|
||||||
}
|
}
|
||||||
else if (!IsOnFloor() && !IsInWater && !DashTicker.IsRunning)
|
else if (!IsOnFloor() && !IsInWater && DashTimer.IsStopped())
|
||||||
{
|
{
|
||||||
velocity += GetGravity() * deltaF;
|
velocity += GetGravity() * deltaF;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!DashTicker.IsRunning)
|
if (DashTimer.IsStopped())
|
||||||
{
|
{
|
||||||
// Drag in water
|
// Drag in water
|
||||||
if (IsInWater)
|
if (IsInWater)
|
||||||
|
|
@ -206,7 +185,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
velocity += Physics.DragForce(-velocity, 0.02f) * deltaF;
|
velocity += Physics.DragForce(-velocity, 0.02f) * deltaF;
|
||||||
}
|
}
|
||||||
// Drag while in air
|
// Drag while in air
|
||||||
else if (!IsOnFloor() && !JumpTicker.IsRunning)
|
else if (!IsOnFloor() && JumpTimer.IsStopped())
|
||||||
{
|
{
|
||||||
velocity += Physics.DragForce(-velocity, 0.009f) * deltaF;
|
velocity += Physics.DragForce(-velocity, 0.009f) * deltaF;
|
||||||
}
|
}
|
||||||
|
|
@ -219,10 +198,9 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
}
|
}
|
||||||
|
|
||||||
Velocity = velocity;
|
Velocity = velocity;
|
||||||
if (PlatformIgnoreTime > 0f)
|
if (!PlatformIgnoreTimer.IsStopped())
|
||||||
{
|
{
|
||||||
CollisionMask = 0b1;
|
CollisionMask = 0b1;
|
||||||
PlatformIgnoreTime = Mathf.Max(0f, PlatformIgnoreTime - deltaF);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -255,12 +233,8 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
JumpAllowedTicker.Tick(deltaF);
|
|
||||||
if (IsOnFloor())
|
if (IsOnFloor())
|
||||||
JumpAllowedTicker.Start();
|
JumpAllowedTimer.Start();
|
||||||
WaterJumpAllowedTicker.Tick(deltaF);
|
|
||||||
DashTicker.Tick(deltaF);
|
|
||||||
DashCooldown.Tick(deltaF);
|
|
||||||
{
|
{
|
||||||
var addedDashPoints = 3f * deltaF;
|
var addedDashPoints = 3f * deltaF;
|
||||||
if (IsInWater)
|
if (IsInWater)
|
||||||
|
|
@ -271,9 +245,8 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
}
|
}
|
||||||
else BankedDashPoints = Mathf.Min(1, BankedDashPoints + 3f * addedDashPoints);
|
else BankedDashPoints = Mathf.Min(1, BankedDashPoints + 3f * addedDashPoints);
|
||||||
}
|
}
|
||||||
GlobalDamageImmunityTicker.Tick(deltaF);
|
|
||||||
|
|
||||||
if (IsOnCeiling()) JumpTicker.Reset();
|
if (IsOnCeiling()) JumpTimer.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnEnteredWater(Node2D body) => IsInWater = true;
|
public void OnEnteredWater(Node2D body) => IsInWater = true;
|
||||||
|
|
@ -282,7 +255,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
{
|
{
|
||||||
if (!IsInWater || SubmersedSensor.HasOverlappingBodies()) return;
|
if (!IsInWater || SubmersedSensor.HasOverlappingBodies()) return;
|
||||||
IsInWater = false;
|
IsInWater = false;
|
||||||
WaterJumpAllowedTicker.Start();
|
WaterJumpAllowedTimer.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AdjustFacing()
|
private void AdjustFacing()
|
||||||
|
|
@ -330,18 +303,18 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
|
|
||||||
// Clear expired input buffer items
|
// Clear expired input buffer items
|
||||||
while (
|
while (
|
||||||
_inputBuffer.Count > 0
|
InputBuffer.Count > 0
|
||||||
&& _inputBuffer[0].Time + MaxInputBufferTimeMicroseconds < currentTime)
|
&& InputBuffer[0].Time + MaxInputBufferTimeMicroseconds < currentTime)
|
||||||
{
|
{
|
||||||
_inputBuffer.RemoveAt(0);
|
InputBuffer.RemoveAt(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check new commands
|
// Check new commands
|
||||||
for (var i = 0; i < _inputBuffer.Count; i++)
|
for (var i = 0; i < InputBuffer.Count; i++)
|
||||||
{
|
{
|
||||||
if (MatchInput(_inputBuffer[i]))
|
if (MatchInput(InputBuffer[i]))
|
||||||
{
|
{
|
||||||
_inputBuffer.RemoveRange(0, i + 1);
|
InputBuffer.RemoveRange(0, i + 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -362,7 +335,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case { Action: Action.Jump, IsPressed: true }
|
case { Action: Action.Jump, IsPressed: true }
|
||||||
when JumpAllowedTicker.IsRunning
|
when !JumpAllowedTimer.IsStopped()
|
||||||
&& (!IsOnFloor() || input.Direction.Y <= 0):
|
&& (!IsOnFloor() || input.Direction.Y <= 0):
|
||||||
GroundJump();
|
GroundJump();
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -373,7 +346,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case { Action: Action.Jump, IsPressed: true }
|
case { Action: Action.Jump, IsPressed: true }
|
||||||
when WaterJumpAllowedTicker.IsRunning:
|
when !WaterJumpAllowedTimer.IsStopped():
|
||||||
WaterExitJump();
|
WaterExitJump();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
@ -387,7 +360,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case { Action: Action.Dash, IsPressed: true }
|
case { Action: Action.Dash, IsPressed: true }
|
||||||
when !DashCooldown.IsRunning && DashPoints >= 1f:
|
when DashCooldownTimer.IsStopped() && DashPoints >= 1f:
|
||||||
Dash();
|
Dash();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
@ -396,32 +369,27 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DropDown()
|
private void DropDown() => PlatformIgnoreTimer.Start();
|
||||||
{
|
|
||||||
PlatformIgnoreTime = 0.1f;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void GroundJump()
|
private void GroundJump()
|
||||||
{
|
{
|
||||||
AdjustFacing();
|
AdjustFacing();
|
||||||
JumpAllowedTicker.Reset();
|
JumpAllowedTimer.Stop();
|
||||||
JumpTicker.Duration = JumpAscentMaxDuration;
|
JumpTimer.Start();
|
||||||
JumpTicker.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WallJump()
|
private void WallJump()
|
||||||
{
|
{
|
||||||
AdjustFacing();
|
AdjustFacing();
|
||||||
JumpAllowedTicker.Reset();
|
JumpAllowedTimer.Stop();
|
||||||
JumpTicker.Duration = JumpAscentMaxDuration;
|
JumpTimer.Start();
|
||||||
JumpTicker.Start();
|
|
||||||
var direction = new Vector2(Mathf.Sign(GetWallNormal().X), -.5f).Normalized();
|
var direction = new Vector2(Mathf.Sign(GetWallNormal().X), -.5f).Normalized();
|
||||||
Velocity = direction * 200.0f;
|
Velocity = direction * 200.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void JumpCut()
|
private void JumpCut()
|
||||||
{
|
{
|
||||||
JumpTicker.Reset();
|
JumpTimer.Stop();
|
||||||
// Jump cut only once, if we're still moving up
|
// Jump cut only once, if we're still moving up
|
||||||
if (Velocity.Y < 0)
|
if (Velocity.Y < 0)
|
||||||
Velocity = Velocity with { Y = Velocity.Y * 0.1f };
|
Velocity = Velocity with { Y = Velocity.Y * 0.1f };
|
||||||
|
|
@ -437,17 +405,16 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
private void WaterExitJump()
|
private void WaterExitJump()
|
||||||
{
|
{
|
||||||
AdjustFacing();
|
AdjustFacing();
|
||||||
WaterJumpAllowedTicker.Reset();
|
WaterJumpAllowedTimer.Stop();
|
||||||
JumpTicker.Duration = JumpAscentMaxDuration * 1.5f;
|
JumpTimer.Start();
|
||||||
JumpTicker.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Dash()
|
private void Dash()
|
||||||
{
|
{
|
||||||
AdjustFacing();
|
AdjustFacing();
|
||||||
DashPoints -= 1f;
|
DashPoints -= 1f;
|
||||||
DashTicker.Start();
|
DashTimer.Start();
|
||||||
DashCooldown.Start();
|
DashCooldownTimer.Start();
|
||||||
DashDirection = (_currentDirection.IsZeroApprox()
|
DashDirection = (_currentDirection.IsZeroApprox()
|
||||||
? FacingVector
|
? FacingVector
|
||||||
: _currentDirection
|
: _currentDirection
|
||||||
|
|
@ -458,7 +425,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
private static Vector2 To8DirectionVector(Vector2 input)
|
private static Vector2 To8DirectionVector(Vector2 input)
|
||||||
{
|
{
|
||||||
if (input.IsZeroApprox()) return Vector2.Zero;
|
if (input.IsZeroApprox()) return Vector2.Zero;
|
||||||
const float tan225 = 0.414213562373f; // tan(22.5°)
|
const float tan225 = 0.414213562f; // tan(22.5°)
|
||||||
Vector2 a = input.Abs(), s = input.Sign();
|
Vector2 a = input.Abs(), s = input.Sign();
|
||||||
return
|
return
|
||||||
a.Y < a.X * tan225 ? new(s.X, 0) :
|
a.Y < a.X * tan225 ? new(s.X, 0) :
|
||||||
|
|
@ -484,9 +451,9 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
|
|
||||||
public void TakeDamage(float amount)
|
public void TakeDamage(float amount)
|
||||||
{
|
{
|
||||||
if (GlobalDamageImmunityTicker.IsRunning) return;
|
if (!GlobalDamageImmunityTimer.IsStopped()) return;
|
||||||
Health -= amount;
|
Health -= amount;
|
||||||
GlobalDamageImmunityTicker.Start();
|
GlobalDamageImmunityTimer.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnHitboxAdded(Hitbox hitbox) => hitbox.BodyHit += OnEnemyHit;
|
public void OnHitboxAdded(Hitbox hitbox) => hitbox.BodyHit += OnEnemyHit;
|
||||||
|
|
@ -494,6 +461,11 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
|
|
||||||
IHitboxOwner IProvide<IHitboxOwner>.
|
IHitboxOwner IProvide<IHitboxOwner>.
|
||||||
Value() => this;
|
Value() => this;
|
||||||
|
|
||||||
|
public enum Move
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class GameActionExtensions
|
public static class GameActionExtensions
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
|
|
@ -3,6 +3,7 @@
|
||||||
[ext_resource type="Script" uid="uid://b5iey2typf2tb" path="res://src/player/Player.cs" id="1_244u8"]
|
[ext_resource type="Script" uid="uid://b5iey2typf2tb" path="res://src/player/Player.cs" id="1_244u8"]
|
||||||
[ext_resource type="Texture2D" uid="uid://d0dy3j0qdycqf" path="res://src/player/player.aseprite" id="2_yw30f"]
|
[ext_resource type="Texture2D" uid="uid://d0dy3j0qdycqf" path="res://src/player/player.aseprite" id="2_yw30f"]
|
||||||
[ext_resource type="Texture2D" uid="uid://i6xi16yki1r5" path="res://src/player/light.aseprite" id="3_mf2ua"]
|
[ext_resource type="Texture2D" uid="uid://i6xi16yki1r5" path="res://src/player/light.aseprite" id="3_mf2ua"]
|
||||||
|
[ext_resource type="Script" uid="uid://ce3atuwxo8fvb" path="res://src/combat/Hurtbox.cs" id="4_5f2sf"]
|
||||||
[ext_resource type="Script" uid="uid://b4k42r866lkut" path="res://src/combat/Hitbox.cs" id="4_244u8"]
|
[ext_resource type="Script" uid="uid://b4k42r866lkut" path="res://src/combat/Hitbox.cs" id="4_244u8"]
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_jiejy"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_jiejy"]
|
||||||
|
|
@ -11,6 +12,9 @@ size = Vector2(8, 28)
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_o822w"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_o822w"]
|
||||||
size = Vector2(8, 12)
|
size = Vector2(8, 12)
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_qi477"]
|
||||||
|
size = Vector2(4, 24)
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_244u8"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_244u8"]
|
||||||
size = Vector2(14, 32)
|
size = Vector2(14, 32)
|
||||||
|
|
||||||
|
|
@ -55,7 +59,7 @@ tracks/2/keys = {
|
||||||
"times": PackedFloat32Array(0),
|
"times": PackedFloat32Array(0),
|
||||||
"transitions": PackedFloat32Array(1),
|
"transitions": PackedFloat32Array(1),
|
||||||
"update": 1,
|
"update": 1,
|
||||||
"values": [false]
|
"values": [true]
|
||||||
}
|
}
|
||||||
tracks/3/type = "value"
|
tracks/3/type = "value"
|
||||||
tracks/3/imported = false
|
tracks/3/imported = false
|
||||||
|
|
@ -67,7 +71,19 @@ tracks/3/keys = {
|
||||||
"times": PackedFloat32Array(0),
|
"times": PackedFloat32Array(0),
|
||||||
"transitions": PackedFloat32Array(1),
|
"transitions": PackedFloat32Array(1),
|
||||||
"update": 1,
|
"update": 1,
|
||||||
"values": [false]
|
"values": [true]
|
||||||
|
}
|
||||||
|
tracks/4/type = "value"
|
||||||
|
tracks/4/imported = false
|
||||||
|
tracks/4/enabled = true
|
||||||
|
tracks/4/path = NodePath("Body/Hurtbox:process_mode")
|
||||||
|
tracks/4/interp = 1
|
||||||
|
tracks/4/loop_wrap = true
|
||||||
|
tracks/4/keys = {
|
||||||
|
"times": PackedFloat32Array(0),
|
||||||
|
"transitions": PackedFloat32Array(1),
|
||||||
|
"update": 1,
|
||||||
|
"values": [0]
|
||||||
}
|
}
|
||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_g6k8r"]
|
[sub_resource type="Animation" id="Animation_g6k8r"]
|
||||||
|
|
@ -122,10 +138,10 @@ tracks/3/path = NodePath("Body/FrontKickHitbox/CollisionShape2D:disabled")
|
||||||
tracks/3/interp = 1
|
tracks/3/interp = 1
|
||||||
tracks/3/loop_wrap = true
|
tracks/3/loop_wrap = true
|
||||||
tracks/3/keys = {
|
tracks/3/keys = {
|
||||||
"times": PackedFloat32Array(0.050000004, 0.28333336),
|
"times": PackedFloat32Array(0, 0.050000004, 0.28333336),
|
||||||
"transitions": PackedFloat32Array(1, 1),
|
"transitions": PackedFloat32Array(1, 1, 1),
|
||||||
"update": 1,
|
"update": 1,
|
||||||
"values": [false, true]
|
"values": [true, false, true]
|
||||||
}
|
}
|
||||||
tracks/4/type = "value"
|
tracks/4/type = "value"
|
||||||
tracks/4/imported = false
|
tracks/4/imported = false
|
||||||
|
|
@ -134,10 +150,10 @@ tracks/4/path = NodePath("Body/FrontKickHitbox/CollisionShape2D2:disabled")
|
||||||
tracks/4/interp = 1
|
tracks/4/interp = 1
|
||||||
tracks/4/loop_wrap = true
|
tracks/4/loop_wrap = true
|
||||||
tracks/4/keys = {
|
tracks/4/keys = {
|
||||||
"times": PackedFloat32Array(0.050000004, 0.20000002),
|
"times": PackedFloat32Array(0, 0.050000004, 0.20000002, 0.36666667),
|
||||||
"transitions": PackedFloat32Array(1, 1),
|
"transitions": PackedFloat32Array(1, 1, 1, 1),
|
||||||
"update": 1,
|
"update": 1,
|
||||||
"values": [true, false]
|
"values": [true, true, false, true]
|
||||||
}
|
}
|
||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_qjkh3"]
|
[sub_resource type="Animation" id="Animation_qjkh3"]
|
||||||
|
|
@ -158,6 +174,23 @@ tracks/0/keys = {
|
||||||
"values": [0]
|
"values": [0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id="Animation_jiejy"]
|
||||||
|
resource_name = "parry"
|
||||||
|
length = 0.6666683681027964
|
||||||
|
step = 0.016666668
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/path = NodePath("Body/Hurtbox:process_mode")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"times": PackedFloat32Array(0, 0.5),
|
||||||
|
"transitions": PackedFloat32Array(1, 1),
|
||||||
|
"update": 1,
|
||||||
|
"values": [4, 0]
|
||||||
|
}
|
||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_boad6"]
|
[sub_resource type="Animation" id="Animation_boad6"]
|
||||||
resource_name = "run"
|
resource_name = "run"
|
||||||
length = 0.8
|
length = 0.8
|
||||||
|
|
@ -215,6 +248,7 @@ _data = {
|
||||||
&"RESET": SubResource("Animation_yw30f"),
|
&"RESET": SubResource("Animation_yw30f"),
|
||||||
&"front_kick": SubResource("Animation_g6k8r"),
|
&"front_kick": SubResource("Animation_g6k8r"),
|
||||||
&"idle": SubResource("Animation_qjkh3"),
|
&"idle": SubResource("Animation_qjkh3"),
|
||||||
|
&"parry": SubResource("Animation_jiejy"),
|
||||||
&"run": SubResource("Animation_boad6"),
|
&"run": SubResource("Animation_boad6"),
|
||||||
&"wall_hold": SubResource("Animation_rgyib"),
|
&"wall_hold": SubResource("Animation_rgyib"),
|
||||||
&"water_idle": SubResource("Animation_244u8")
|
&"water_idle": SubResource("Animation_244u8")
|
||||||
|
|
@ -226,6 +260,9 @@ animation = &"front_kick"
|
||||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_yw30f"]
|
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_yw30f"]
|
||||||
animation = &"idle"
|
animation = &"idle"
|
||||||
|
|
||||||
|
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_5f2sf"]
|
||||||
|
animation = &"parry"
|
||||||
|
|
||||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_g6k8r"]
|
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_g6k8r"]
|
||||||
animation = &"run"
|
animation = &"run"
|
||||||
|
|
||||||
|
|
@ -266,20 +303,22 @@ advance_expression = "not IsHoldingWall()"
|
||||||
allow_transition_to_self = true
|
allow_transition_to_self = true
|
||||||
states/End/position = Vector2(772, 100)
|
states/End/position = Vector2(772, 100)
|
||||||
states/front_kick/node = SubResource("AnimationNodeAnimation_qjkh3")
|
states/front_kick/node = SubResource("AnimationNodeAnimation_qjkh3")
|
||||||
states/front_kick/position = Vector2(604.5, 41.5)
|
states/front_kick/position = Vector2(612.5, 32.5)
|
||||||
states/idle/node = SubResource("AnimationNodeAnimation_yw30f")
|
states/idle/node = SubResource("AnimationNodeAnimation_yw30f")
|
||||||
states/idle/position = Vector2(428.5, 88.5)
|
states/idle/position = Vector2(428.5, 88.5)
|
||||||
|
states/parry/node = SubResource("AnimationNodeAnimation_5f2sf")
|
||||||
|
states/parry/position = Vector2(544.82965, 277.5)
|
||||||
states/run/node = SubResource("AnimationNodeAnimation_g6k8r")
|
states/run/node = SubResource("AnimationNodeAnimation_g6k8r")
|
||||||
states/run/position = Vector2(628.5, 203.5)
|
states/run/position = Vector2(678.5, 215.5)
|
||||||
states/wall_hold/node = SubResource("AnimationNodeAnimation_boad6")
|
states/wall_hold/node = SubResource("AnimationNodeAnimation_boad6")
|
||||||
states/wall_hold/position = Vector2(362.82965, 231.5)
|
states/wall_hold/position = Vector2(362.82965, 231.5)
|
||||||
transitions = ["front_kick", "idle", SubResource("AnimationNodeStateMachineTransition_boad6"), "idle", "front_kick", SubResource("AnimationNodeStateMachineTransition_rgyib"), "Start", "idle", SubResource("AnimationNodeStateMachineTransition_hg6s5"), "idle", "run", SubResource("AnimationNodeStateMachineTransition_8t03j"), "run", "idle", SubResource("AnimationNodeStateMachineTransition_2ieo8"), "run", "front_kick", SubResource("AnimationNodeStateMachineTransition_ebec5"), "idle", "wall_hold", SubResource("AnimationNodeStateMachineTransition_yllr7"), "wall_hold", "idle", SubResource("AnimationNodeStateMachineTransition_kb6p2")]
|
transitions = ["front_kick", "idle", SubResource("AnimationNodeStateMachineTransition_boad6"), "idle", "front_kick", SubResource("AnimationNodeStateMachineTransition_rgyib"), "Start", "idle", SubResource("AnimationNodeStateMachineTransition_hg6s5"), "idle", "run", SubResource("AnimationNodeStateMachineTransition_8t03j"), "run", "idle", SubResource("AnimationNodeStateMachineTransition_2ieo8"), "run", "front_kick", SubResource("AnimationNodeStateMachineTransition_ebec5"), "idle", "wall_hold", SubResource("AnimationNodeStateMachineTransition_yllr7"), "wall_hold", "idle", SubResource("AnimationNodeStateMachineTransition_kb6p2")]
|
||||||
graph_offset = Vector2(-103.670364, -38)
|
graph_offset = Vector2(-48.670364, -38)
|
||||||
|
|
||||||
[node name="Player" type="CharacterBody2D" unique_id=500011307]
|
[node name="Player" type="CharacterBody2D" unique_id=500011307]
|
||||||
physics_interpolation_mode = 1
|
physics_interpolation_mode = 1
|
||||||
auto_translate_mode = 1
|
auto_translate_mode = 1
|
||||||
collision_layer = 2
|
collision_layer = 0
|
||||||
collision_mask = 65
|
collision_mask = 65
|
||||||
floor_constant_speed = true
|
floor_constant_speed = true
|
||||||
floor_max_angle = 0.24783675
|
floor_max_angle = 0.24783675
|
||||||
|
|
@ -291,6 +330,7 @@ shape = SubResource("RectangleShape2D_jiejy")
|
||||||
|
|
||||||
[node name="SubmersedSensor" type="Area2D" parent="." unique_id=1595680866]
|
[node name="SubmersedSensor" type="Area2D" parent="." unique_id=1595680866]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
|
visible = false
|
||||||
collision_layer = 0
|
collision_layer = 0
|
||||||
collision_mask = 32
|
collision_mask = 32
|
||||||
|
|
||||||
|
|
@ -346,25 +386,39 @@ metadata/_aseprite_wizard_config_ = {
|
||||||
}
|
}
|
||||||
metadata/_aseprite_wizard_source_file_hash_ = "61168df4a163c039cfaab97f4fccb905"
|
metadata/_aseprite_wizard_source_file_hash_ = "61168df4a163c039cfaab97f4fccb905"
|
||||||
|
|
||||||
|
[node name="Hurtbox" type="Area2D" parent="Body" unique_id=1918418417]
|
||||||
|
visible = false
|
||||||
|
collision_layer = 8
|
||||||
|
collision_mask = 4
|
||||||
|
script = ExtResource("4_5f2sf")
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Body/Hurtbox" unique_id=2048987579]
|
||||||
|
position = Vector2(0, -14)
|
||||||
|
shape = SubResource("RectangleShape2D_qi477")
|
||||||
|
disabled = true
|
||||||
|
debug_color = Color(0.99430805, 0, 0.2314094, 0.41960785)
|
||||||
|
|
||||||
[node name="HandAttachment" type="Node2D" parent="Body" unique_id=1002134601]
|
[node name="HandAttachment" type="Node2D" parent="Body" unique_id=1002134601]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
position = Vector2(0, -14)
|
position = Vector2(0, -14)
|
||||||
|
|
||||||
[node name="FrontKickHitbox" type="Area2D" parent="Body" unique_id=1918418417]
|
[node name="FrontKickHitbox" type="Area2D" parent="Body" unique_id=2024612404]
|
||||||
visible = false
|
visible = false
|
||||||
position = Vector2(0, -16)
|
position = Vector2(0, -16)
|
||||||
collision_layer = 8
|
collision_layer = 8
|
||||||
collision_mask = 4
|
collision_mask = 4
|
||||||
script = ExtResource("4_244u8")
|
script = ExtResource("4_244u8")
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Body/FrontKickHitbox" unique_id=2048987579]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Body/FrontKickHitbox" unique_id=1088025767]
|
||||||
position = Vector2(5, 7)
|
position = Vector2(5, 7)
|
||||||
shape = SubResource("RectangleShape2D_244u8")
|
shape = SubResource("RectangleShape2D_244u8")
|
||||||
|
disabled = true
|
||||||
debug_color = Color(0.99430805, 0, 0.2314094, 0.41960785)
|
debug_color = Color(0.99430805, 0, 0.2314094, 0.41960785)
|
||||||
|
|
||||||
[node name="CollisionShape2D2" type="CollisionShape2D" parent="Body/FrontKickHitbox" unique_id=734742131]
|
[node name="CollisionShape2D2" type="CollisionShape2D" parent="Body/FrontKickHitbox" unique_id=734742131]
|
||||||
position = Vector2(16, -2)
|
position = Vector2(16, -2)
|
||||||
shape = SubResource("RectangleShape2D_5f2sf")
|
shape = SubResource("RectangleShape2D_5f2sf")
|
||||||
|
disabled = true
|
||||||
debug_color = Color(0.99430805, 0, 0.2314094, 0.41960785)
|
debug_color = Color(0.99430805, 0, 0.2314094, 0.41960785)
|
||||||
|
|
||||||
[node name="DashHitbox" type="Area2D" parent="Body" unique_id=45996338]
|
[node name="DashHitbox" type="Area2D" parent="Body" unique_id=45996338]
|
||||||
|
|
@ -391,5 +445,35 @@ tree_root = SubResource("AnimationNodeStateMachine_yllr7")
|
||||||
advance_expression_base_node = NodePath("../..")
|
advance_expression_base_node = NodePath("../..")
|
||||||
anim_player = NodePath("..")
|
anim_player = NodePath("..")
|
||||||
|
|
||||||
[connection signal="body_entered" from="SubmersedSensor" to="." method="OnEnteredWater"]
|
[node name="JumpTimer" type="Timer" parent="." unique_id=1535675433]
|
||||||
[connection signal="body_exited" from="SubmersedSensor" to="." method="OnLeftWater"]
|
unique_name_in_owner = true
|
||||||
|
process_callback = 0
|
||||||
|
wait_time = 0.25
|
||||||
|
|
||||||
|
[node name="JumpAllowedTimer" type="Timer" parent="." unique_id=705792352]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
process_callback = 0
|
||||||
|
wait_time = 0.1
|
||||||
|
|
||||||
|
[node name="WaterJumpAllowedTimer" type="Timer" parent="." unique_id=1597932610]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
process_callback = 0
|
||||||
|
wait_time = 0.1
|
||||||
|
|
||||||
|
[node name="DashTimer" type="Timer" parent="." unique_id=18391348]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
process_callback = 0
|
||||||
|
wait_time = 0.15
|
||||||
|
|
||||||
|
[node name="DashCooldownTimer" type="Timer" parent="." unique_id=452015930]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
process_callback = 0
|
||||||
|
wait_time = 0.6
|
||||||
|
|
||||||
|
[node name="GlobalDamageImmunityTimer" type="Timer" parent="." unique_id=1358670796]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
process_callback = 0
|
||||||
|
|
||||||
|
[node name="PlatformIgnoreTimer" type="Timer" parent="." unique_id=1912509940]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
process_callback = 0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue