diff options
Diffstat (limited to 'Towers/Components/RangeComponent.gd')
-rw-r--r-- | Towers/Components/RangeComponent.gd | 33 |
1 files changed, 11 insertions, 22 deletions
diff --git a/Towers/Components/RangeComponent.gd b/Towers/Components/RangeComponent.gd index a2f7ae7..74a6eeb 100644 --- a/Towers/Components/RangeComponent.gd +++ b/Towers/Components/RangeComponent.gd @@ -9,17 +9,14 @@ var range := 0: range = value range_changed.emit() -var area := Area2D.new() -var collision_shape := CollisionShape2D.new() -var shape := CircleShape2D.new() +@onready var area: Area2D = $Range +@onready var collision_shape := $Range/CollisionShape2D +@onready var shape: CircleShape2D = collision_shape.shape var units_in_range: Array[Unit] -func _init() -> void: - type = ComponentType.Range - set_sprite(preload("res://Towers/Components/Assets/range-component.png")) - +func _ready() -> void: update_range() level_changed.connect(update_range) @@ -34,19 +31,11 @@ func update_range(): func on_add(tower: Tower): super.on_add(tower) - area.set_collision_layer_value(1, false) - area.set_collision_mask_value(1, true) - - area.body_entered.connect(func(body: Node2D): - units_in_range.append(body) - ) - area.body_exited.connect(func(body: Node2D): - units_in_range.erase(body) - ) - area.position = tower.get_node("CenterAnchor").position - - collision_shape.shape = shape - area.add_child(collision_shape) - - tower.add_child(area) + + +func _on_range_body_entered(body: Node2D) -> void: + units_in_range.append(body) + +func _on_range_body_exited(body: Node2D) -> void: + units_in_range.erase(body) |