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

@ -3,8 +3,8 @@ using System.Collections.Generic;
namespace Dancer;
[Meta(typeof(IAutoNode))]
public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
IProvide<IHitboxOwner>
public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner, IHurtboxOwner,
IProvide<IHitboxOwner>, IProvide<IHurtboxOwner>
{
public override void _Notification(int what) => this.Notify(what);
@ -456,8 +456,8 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
GlobalDamageImmunityTimer.Start();
}
public void OnHitboxAdded(Hitbox hitbox) => hitbox.BodyHit += OnEnemyHit;
public void OnHitboxRemoved(Hitbox hitbox) => hitbox.BodyHit -= OnEnemyHit;
public void OnHitboxAdded(Hitbox hitbox) => hitbox.TargetHit += OnEnemyHit;
public void OnHitboxRemoved(Hitbox hitbox) => hitbox.TargetHit -= OnEnemyHit;
IHitboxOwner IProvide<IHitboxOwner>.
Value() => this;
@ -466,6 +466,23 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
{
}
public void OnAttacked(Hurtbox hurtbox, in Attack attack)
{
TakeDamage(attack.Damage);
}
public void OnHurtboxAdded(Hurtbox hurtbox)
{
hurtbox.Attacked += OnAttacked;
}
public void OnHurtboxRemoved(Hurtbox hurtbox)
{
hurtbox.Attacked -= OnAttacked;
}
public IHurtboxOwner Value() => this;
}
public static class GameActionExtensions

View file

@ -317,18 +317,20 @@ graph_offset = Vector2(-48.670364, -38)
[node name="Player" type="CharacterBody2D" unique_id=500011307]
physics_interpolation_mode = 1
auto_translate_mode = 1
collision_layer = 0
collision_layer = 128
collision_mask = 65
floor_constant_speed = true
floor_max_angle = 0.24783675
script = ExtResource("1_244u8")
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=84142517]
visible = false
position = Vector2(0, -14)
shape = SubResource("RectangleShape2D_jiejy")
[node name="SubmersedSensor" type="Area2D" parent="." unique_id=1595680866]
unique_name_in_owner = true
visible = false
collision_layer = 0
collision_mask = 32
@ -379,16 +381,15 @@ metadata/_aseprite_wizard_config_ = {
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
collision_layer = 2
collision_mask = 0
monitoring = false
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)
debug_color = Color(0.36554977, 0.61805135, 9.62615e-07, 0.41960785)
[node name="HandAttachment" type="Node2D" parent="Body" unique_id=1002134601]
unique_name_in_owner = true