added behavior trees!
This commit is contained in:
parent
4d0ad13bf3
commit
d362d93b12
9 changed files with 510 additions and 197 deletions
|
|
@ -20,14 +20,17 @@ public sealed partial class Hitbox : Area2D
|
|||
|
||||
private readonly Dictionary<Node2D, ImmunityEntry> _immunityEntries = [];
|
||||
private readonly HashSet<Node2D> _bodies = [];
|
||||
private bool _checkingForHits;
|
||||
|
||||
public void OnResolved()
|
||||
public void OnReady()
|
||||
{
|
||||
ProcessMode = ProcessModeEnum.Disabled;
|
||||
BodyEntered += OnEntered;
|
||||
HitboxOwner.OnHitboxAdded(this);
|
||||
BodyExited += OnLeft;
|
||||
SetPhysicsProcess(true);
|
||||
}
|
||||
|
||||
public void OnResolved() => HitboxOwner.OnHitboxAdded(this);
|
||||
|
||||
public void OnExitTree() => HitboxOwner.OnHitboxRemoved(this);
|
||||
|
||||
private void OnEntered(Node2D body)
|
||||
|
|
@ -43,7 +46,7 @@ public sealed partial class Hitbox : Area2D
|
|||
|
||||
public void OnPhysicsProcess(double delta)
|
||||
{
|
||||
foreach (var body in _bodies) CheckForHit(body);
|
||||
foreach (var body in _bodies) CheckForHit(body, delta);
|
||||
}
|
||||
|
||||
private void CheckForHit(Node2D body, double delta = 0.0)
|
||||
|
|
@ -51,7 +54,7 @@ public sealed partial class Hitbox : Area2D
|
|||
if (!_immunityEntries.TryGetValue(body, out var entry)) _immunityEntries.Add(body, entry = new());
|
||||
|
||||
entry.Immunity -= (float)delta;
|
||||
if (entry.Immunity <= 0f && entry.HitCount < LocalCountLimit)
|
||||
if (_checkingForHits && entry.Immunity <= 0f && entry.HitCount < LocalCountLimit)
|
||||
{
|
||||
entry.Immunity += LocalImmunity;
|
||||
entry.HitCount += 1;
|
||||
|
|
@ -64,7 +67,7 @@ public sealed partial class Hitbox : Area2D
|
|||
public void StartAttack()
|
||||
{
|
||||
if (Engine.IsEditorHint()) Visible = true;
|
||||
ProcessMode = ProcessModeEnum.Inherit;
|
||||
_checkingForHits = true;
|
||||
foreach (var immunityEntry in _immunityEntries.Values)
|
||||
immunityEntry.HitCount = 0;
|
||||
}
|
||||
|
|
@ -72,7 +75,7 @@ public sealed partial class Hitbox : Area2D
|
|||
public void StopAttack()
|
||||
{
|
||||
if (Engine.IsEditorHint()) Visible = false;
|
||||
ProcessMode = ProcessModeEnum.Disabled;
|
||||
_checkingForHits = false;
|
||||
}
|
||||
|
||||
private sealed class ImmunityEntry
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue