feat: 添加Hitbox和Hurtbox,添加敌人和玩家之间的碰撞
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
extends Area2D
|
||||
class_name HitboxComponent
|
||||
|
||||
signal on_hit_hurtbox(hurtbox: HurtboxComponent)
|
||||
|
||||
var damage := 1.0
|
||||
var critical := false
|
||||
var knockback_power := 0.0
|
||||
var source: Node2D
|
||||
|
||||
|
||||
func enable() -> void:
|
||||
set_deferred("monitoring", true)
|
||||
set_deferred("monitorable", true)
|
||||
|
||||
|
||||
|
||||
func disable() -> void:
|
||||
set_deferred("monitoring", false)
|
||||
set_deferred("monitorable", false)
|
||||
|
||||
|
||||
func setup(damage: float, critical: bool, knockback: float, source: Node2D) -> void:
|
||||
self.damage = damage
|
||||
self.critical = critical
|
||||
knockback_power = knockback
|
||||
self.source = source
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
|
||||
pass
|
||||
|
||||
|
||||
func _on_area_entered(area: Area2D) -> void:
|
||||
if area is HurtboxComponent:
|
||||
on_hit_hurtbox.emit(area)
|
||||
print(area.owner.name)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
uid://blhk17rquv0cp
|
||||
@@ -0,0 +1,8 @@
|
||||
[gd_scene format=3 uid="uid://c0fyx8gj5uexl"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://blhk17rquv0cp" path="res://scenes/components/hitbox_component.gd" id="1_okvui"]
|
||||
|
||||
[node name="HitboxComponent" type="Area2D" unique_id=151235566]
|
||||
script = ExtResource("1_okvui")
|
||||
|
||||
[connection signal="area_entered" from="." to="." method="_on_area_entered"]
|
||||
@@ -0,0 +1,19 @@
|
||||
extends Area2D
|
||||
class_name HurtboxComponent
|
||||
|
||||
signal on_damaged(hitbox: HitboxComponent)
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
|
||||
func _on_area_entered(area: Area2D) -> void:
|
||||
if area is HitboxComponent:
|
||||
on_damaged.emit(area)
|
||||
@@ -0,0 +1 @@
|
||||
uid://c7k3ou0kpgbcs
|
||||
@@ -0,0 +1,8 @@
|
||||
[gd_scene format=3 uid="uid://bkyyic3okyjxx"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://c7k3ou0kpgbcs" path="res://scenes/components/hurtbox_component.gd" id="1_trd8p"]
|
||||
|
||||
[node name="HurtboxComponent" type="Area2D" unique_id=1155790880]
|
||||
script = ExtResource("1_trd8p")
|
||||
|
||||
[connection signal="area_entered" from="." to="." method="_on_area_entered"]
|
||||
Reference in New Issue
Block a user