24 lines
593 B
GDScript
24 lines
593 B
GDScript
class_name DamageReceiver
|
|
extends Area2D
|
|
|
|
signal damage_received(amount: int, hit_type: StringName, from: Vector2)
|
|
|
|
|
|
func _ready() -> void:
|
|
add_to_group("damage_receivers")
|
|
|
|
|
|
func take_damage(amount: int, hit_type: StringName, from: Vector2) -> void:
|
|
damage_received.emit(amount, hit_type, from)
|
|
_event_bus().emit_signal("damage_dealt", self, amount, hit_type)
|
|
|
|
|
|
func _event_bus() -> Node:
|
|
var root := get_tree().root
|
|
var bus := root.get_node_or_null("EventBus")
|
|
if bus == null:
|
|
bus = load("res://autoload/event_bus.gd").new()
|
|
bus.name = "EventBus"
|
|
root.add_child(bus)
|
|
return bus
|