summaryrefslogtreecommitdiff
path: root/Towers/Components/RangeComponent.gd
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-11-06 21:00:56 +0100
committerDaniel Weipert <git@mail.dweipert.de>2024-11-06 21:00:56 +0100
commitf20b3a48a14f34def41d823fabb476981ef7055e (patch)
tree35608bd22ff3ec8d9210747df39186d212aa6ab7 /Towers/Components/RangeComponent.gd
parent6f17d6c1d458275e8744d57a7f433cc3eb5434d7 (diff)
next commit
Diffstat (limited to 'Towers/Components/RangeComponent.gd')
-rw-r--r--Towers/Components/RangeComponent.gd52
1 files changed, 52 insertions, 0 deletions
diff --git a/Towers/Components/RangeComponent.gd b/Towers/Components/RangeComponent.gd
new file mode 100644
index 0000000..a2f7ae7
--- /dev/null
+++ b/Towers/Components/RangeComponent.gd
@@ -0,0 +1,52 @@
+class_name RangeTowerComponent
+extends TowerComponent
+
+
+signal range_changed
+@warning_ignore("shadowed_global_identifier")
+var range := 0:
+ set(value):
+ range = value
+ range_changed.emit()
+
+var area := Area2D.new()
+var collision_shape := CollisionShape2D.new()
+var shape := CircleShape2D.new()
+
+var units_in_range: Array[Unit]
+
+
+func _init() -> void:
+ type = ComponentType.Range
+ set_sprite(preload("res://Towers/Components/Assets/range-component.png"))
+
+ update_range()
+ level_changed.connect(update_range)
+
+
+func update_range():
+ var tile_size = Client.current_stage.map.tile_set.tile_size.x
+ @warning_ignore("integer_division")
+ range = (tile_size * 2) + ((tile_size / 2) * level)
+ shape.radius = 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)