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/AttackComponent.gd | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'Towers/Components/AttackComponent.gd') 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) -- cgit v1.2.3