From 63d2a59042fb9d90a586ad85d8364de7c38aea8e Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Wed, 6 Nov 2024 22:35:04 +0100 Subject: next commit --- Towers/Components/RangeComponent.gd | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) (limited to 'Towers/Components/RangeComponent.gd') 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) -- cgit v1.2.3