summaryrefslogtreecommitdiff
path: root/Towers/Components/AttackComponent.gd
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-11-06 22:35:04 +0100
committerDaniel Weipert <git@mail.dweipert.de>2024-11-06 22:35:04 +0100
commit63d2a59042fb9d90a586ad85d8364de7c38aea8e (patch)
treef4c648b39313f10f44898d0216a9147dfb4ba491 /Towers/Components/AttackComponent.gd
parentf20b3a48a14f34def41d823fabb476981ef7055e (diff)
next commit
Diffstat (limited to 'Towers/Components/AttackComponent.gd')
-rw-r--r--Towers/Components/AttackComponent.gd29
1 files changed, 12 insertions, 17 deletions
diff --git a/Towers/Components/AttackComponent.gd b/Towers/Components/AttackComponent.gd
index c7660cf..0b09ac1 100644
--- a/Towers/Components/AttackComponent.gd
+++ b/Towers/Components/AttackComponent.gd
@@ -4,32 +4,33 @@ extends TowerComponent
var power := 1
-var speed_base := 1.0
+var speed_base := 2.0
var speed := 1
-var shoot_cooldown := Timer.new()
-var shoot_sound := AudioStreamPlayer2D.new()
+@onready var shoot_cooldown := $ShootCooldown
+@onready var shoot_sound := $ShootSound
-@export var range_component: RangeTowerComponent:
+var range_component: RangeTowerComponent:
get():
return current_tower.components[ComponentType.Range]
-func _init() -> void:
- type = ComponentType.Attack
- set_sprite(preload("res://Towers/Components/Assets/attack-component.png"))
-
+func _ready() -> void:
update_power()
- update_speed()
level_changed.connect(update_power)
+
+ update_speed()
level_changed.connect(update_speed)
func update_power():
- power = ceil(level / 2.0)
+ if level <= 2:
+ power = level
+ else:
+ power = 1 + max(1, level - ceil(level / 2.0))
func update_speed():
- speed = level - ceil(level / 2.0)
+ speed = max(1, ceil(level / 2.0))
shoot_cooldown.wait_time = speed_base / speed
func update_range():
@@ -39,12 +40,6 @@ func update_range():
func on_add(tower: Tower):
super.on_add(tower)
- shoot_cooldown.one_shot = true
- tower.add_child(shoot_cooldown)
-
- shoot_sound.stream = preload("res://Towers/Assets/shoot.ogg")
- tower.add_child(shoot_sound)
-
update_range()
range_component.range_changed.connect(update_range)