wip hurtbox

This commit is contained in:
Lilith Schier 2026-07-25 13:24:47 +02:00
parent 74c888fa6e
commit d8117a062a
3 changed files with 58 additions and 0 deletions

45
src/combat/Hurtbox.cs Normal file
View file

@ -0,0 +1,45 @@
using System.Collections.Generic;
namespace Dancer;
[Meta(typeof(IAutoNode)), Tool]
public sealed partial class Hurtbox : Area2D, IAttackable
{
public override void _Notification(int what) => this.Notify(what);
[Dependency]
private IHurtboxOwner HurtboxOwner => this.DependOn<IHurtboxOwner>(() => new DummyHurtboxOwner());
[Export(PropertyHint.None, "suffix:s")]
private float LocalImmunity { get; set; }
[Export]
private int LocalCountLimit { get; set; } = 1;
public delegate void AttackedEventHandler(Hurtbox hurtbox, in Attack attack);
public event AttackedEventHandler? Attacked;
public void OnReady() { }
public void OnResolved() => HurtboxOwner.OnHurtboxAdded(this);
public void OnExitTree() => HurtboxOwner.OnHurtboxRemoved(this);
public void GetAttacked(in Attack attack) => Attacked?.Invoke(this, in attack);
}
public interface IHurtboxOwner
{
public void OnHurtboxAdded(Hurtbox hurtbox);
public void OnHurtboxRemoved(Hurtbox hurtbox);
}
public class DummyHurtboxOwner : IHurtboxOwner
{
public void OnHurtboxAdded(Hurtbox hurtbox)
{
}
public void OnHurtboxRemoved(Hurtbox hurtbox)
{
}
}

View file

@ -0,0 +1 @@
uid://b4k42r866lkut

12
src/combat/hurtbox.tscn Normal file
View file

@ -0,0 +1,12 @@
[gd_scene format=3 uid="uid://b02xxaidgagux"]
[ext_resource type="Script" uid="uid://b4k42r866lkut" path="res://src/combat/Hitbox.cs" id="1_chyeu"]
[node name="Hurtbox" type="Area2D" unique_id=1918418417]
collision_layer = 8
collision_mask = 4
script = ExtResource("1_chyeu")
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=2048987579]
disabled = true
debug_color = Color(0.99430805, 0, 0.2314094, 0.41960785)