added damaging spikes

This commit is contained in:
Lilith Schier 2026-07-22 20:20:10 +02:00
parent a16601fa1d
commit 959ade4668
4 changed files with 61 additions and 9 deletions

View file

@ -66,6 +66,9 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
[Export] public bool CanTurn { get; set; } = true;
[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);
public bool IsJumping => JumpTicker.IsRunning;
@ -85,6 +88,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
private Ticker JumpTicker { get; } = new();
private Vector2 DashDirection { get; set; }
public float DashPoints { get; set; }
private Ticker GlobalDamageImmunityTicker { get; } = new();
[Node] private AnimationTree AnimationTree { get; set; } = null!;
[Node] private Area2D SubmersedSensor { get; set; } = null!;
@ -100,6 +104,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
DashCooldown.Duration = DashCooldownDuration;
JumpAllowedTicker.Duration = LateJumpLimitDuration;
WaterJumpAllowedTicker.Duration = LateJumpLimitDuration;
GlobalDamageImmunityTicker.Duration = GlobalDamageImmunityDuration;
}
public override void _UnhandledInput(InputEvent @event)
@ -224,6 +229,30 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
MoveAndSlide();
{
var count = GetSlideCollisionCount();
for (var i = 0; i < count; i++)
{
var collision = GetSlideCollision(i);
if (collision.GetCollider() is not TileMapLayer tileMapLayer)
continue;
var collisionPos = collision.GetPosition() + collision.GetTravel();
var mapCoords = tileMapLayer.GlobalToMap(collisionPos);
if (tileMapLayer.GetCellTileData(mapCoords) is not { } tileData
|| !tileData.HasCustomData("damage"))
continue;
if (tileData.GetCustomData("damage") is not { VariantType: Variant.Type.Float } variant)
continue;
if (variant.AsSingle() is > 0f and var damage)
TakeDamage(damage);
}
}
JumpAllowedTicker.Tick(deltaF);
if (IsOnFloor())
JumpAllowedTicker.Start();
@ -231,6 +260,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
DashTicker.Tick(deltaF);
DashCooldown.Tick(deltaF);
if (IsInWater) DashPoints = Mathf.Min(MaxDashPoints, DashPoints + 3f * deltaF);
GlobalDamageImmunityTicker.Tick(deltaF);
if (IsOnCeiling()) JumpTicker.Reset();
}
@ -438,12 +468,21 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
public void GetAttacked(in Attack attack)
{
Health -= attack.Damage;
TakeDamage(attack.Damage);
}
public void TakeDamage(float amount)
{
if (GlobalDamageImmunityTicker.IsRunning) return;
Health -= amount;
GlobalDamageImmunityTicker.Start();
}
public void OnHitboxAdded(Hitbox hitbox) => hitbox.BodyHit += OnEnemyHit;
public void OnHitboxRemoved(Hitbox hitbox) => hitbox.BodyHit -= OnEnemyHit;
IHitboxOwner IProvide<IHitboxOwner>.Value() => this;
IHitboxOwner IProvide<IHitboxOwner>.
Value() => this;
}
public static class GameActionExtensions