added player hurtbox

This commit is contained in:
Lilith Schier 2026-08-01 20:07:49 +02:00
parent 7bb6854335
commit 5a6c711296
8 changed files with 54 additions and 35 deletions

View file

@ -1,4 +1,5 @@
using System.Diagnostics;
using System.Linq;
using Bt = Dancer.Behavior;
namespace Dancer;
@ -64,7 +65,7 @@ public sealed partial class Birb : CharacterBody2D, IAttackable,
new Bt.Selector([
new Bt.MemoSequence([
new Bt.Sequence([
new Bt.Check(() => StabHitbox.GetOverlappingBodies().Contains(Target))
new Bt.Check(() => StabHitbox.GetOverlappingAreas().Any(area => area.FindParent(Target!.Name) == Target))
{ Name = "Target in stab hitbox?" },
new Bt.MemoSequence([
new Bt.Action(Stop) { Name = "Stop" },
@ -195,12 +196,12 @@ public sealed partial class Birb : CharacterBody2D, IAttackable,
IHitboxOwner IProvide<IHitboxOwner>.Value() => this;
public void OnHitboxAdded(Hitbox hitbox) => hitbox.BodyHit += OnBodyHit;
public void OnHitboxRemoved(Hitbox hitbox) => hitbox.BodyHit -= OnBodyHit;
public void OnHitboxAdded(Hitbox hitbox) => hitbox.TargetHit += OnTargetHit;
public void OnHitboxRemoved(Hitbox hitbox) => hitbox.TargetHit -= OnTargetHit;
private void OnBodyHit(Hitbox hitbox, Node2D body)
private void OnTargetHit(Hitbox hitbox, Node2D target)
{
if (body is not IAttackable attackable) return;
if (target is not IAttackable attackable) return;
attackable.GetAttacked(new()
{
Attacker = this,

View file

@ -47,7 +47,7 @@ animations = [{
"texture": SubResource("AtlasTexture_ha735")
}],
"loop": 1,
"name": &"prepare",
"name": &"prepare_attack",
"speed": 5.0
}, {
"frames": [{
@ -177,7 +177,7 @@ tracks/1/keys = {
[sub_resource type="Animation" id="Animation_3ly8m"]
resource_name = "stab"
length = 0.8333333
length = 1.0833334
step = 0.016666668
tracks/0/type = "value"
tracks/0/imported = false
@ -198,7 +198,7 @@ tracks/1/path = NodePath("Body:frame")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 0.1, 0.5, 0.55, 0.6333333),
"times": PackedFloat32Array(0, 0.1, 0.75000006, 0.8000001, 0.8833334),
"transitions": PackedFloat32Array(1, 1, 1, 1, 1),
"update": 1,
"values": [0, 1, 2, 3, 4]
@ -210,7 +210,7 @@ tracks/2/path = NodePath(".")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(0.8333333),
"times": PackedFloat32Array(1.0833334),
"transitions": PackedFloat32Array(1),
"values": [{
"args": [],
@ -224,7 +224,7 @@ tracks/3/path = NodePath("Body/StabHitbox")
tracks/3/interp = 1
tracks/3/loop_wrap = true
tracks/3/keys = {
"times": PackedFloat32Array(0.5, 0.6333333),
"times": PackedFloat32Array(0.75000006, 0.8833334),
"transitions": PackedFloat32Array(1, 1),
"values": [{
"args": [],
@ -258,7 +258,6 @@ offset = Vector2(9, -4)
[node name="StabHitbox" type="Area2D" parent="Body" unique_id=1373491990]
unique_name_in_owner = true
visible = false
position = Vector2(20, 9)
collision_layer = 16
collision_mask = 2
@ -276,7 +275,7 @@ shape = SubResource("CapsuleShape2D_feb5d")
visible = false
position = Vector2(0, -22)
collision_layer = 0
collision_mask = 2
collision_mask = 128
monitorable = false
[node name="CollisionShape2D" type="CollisionShape2D" parent="Detection" unique_id=1217467707]
@ -287,7 +286,7 @@ debug_color = Color(0, 0.6, 0.69803923, 0.16862746)
visible = false
position = Vector2(0, -22)
collision_layer = 0
collision_mask = 2
collision_mask = 128
monitorable = false
[node name="CollisionShape2D" type="CollisionShape2D" parent="Chase" unique_id=567870323]
@ -315,5 +314,6 @@ show_percentage = false
unique_name_in_owner = true
libraries/ = SubResource("AnimationLibrary_1i6dk")
[connection signal="area_entered" from="Body/StabHitbox" to="." method="OnStabHitboxAreaEntered"]
[connection signal="body_entered" from="Detection" to="." method="OnDetectionBodyEntered"]
[connection signal="body_exited" from="Chase" to="." method="OnChaseBodyExited"]