summaryrefslogtreecommitdiff
path: root/Towers/Components/RangeComponent.gd
blob: 74a6eebe569b591b75021123bef4b3070d6b2b66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class_name RangeTowerComponent
extends TowerComponent


signal range_changed
@warning_ignore("shadowed_global_identifier")
var range := 0:
	set(value):
		range = value
		range_changed.emit()

@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 _ready() -> void:
	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.position = tower.get_node("CenterAnchor").position


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)