summaryrefslogtreecommitdiff
path: root/Towers
diff options
context:
space:
mode:
Diffstat (limited to 'Towers')
-rw-r--r--Towers/Tower.gd104
-rw-r--r--Towers/Tower.tscn35
2 files changed, 121 insertions, 18 deletions
diff --git a/Towers/Tower.gd b/Towers/Tower.gd
index 7eb8bf6..2de8216 100644
--- a/Towers/Tower.gd
+++ b/Towers/Tower.gd
@@ -36,24 +36,43 @@ var mobs_in_range: Array = []
#var selection_area: Area2D
+signal selection_group_id_changed(previous_id: String)
+@onready var selection_group_id := get_group_id():
+ set(value):
+ var previous_id = selection_group_id
+ selection_group_id = value
+ selection_group_id_changed.emit(previous_id)
+
# rpc owner id
@export var owner_id = 1
+signal attack_value_changed(value: int)
@export var attack_range: int = 32
@export var attack_power: int = 1
+
@export var attack_speed: int = 1
+var speed_base: float = 2.0
-@export var components: Array[TowerComponent] = []
+signal components_changed
+@export var components: Array[TowerComponent] = []#:
+ #set(value):
+ #components = value
+ #components_changed.emit()
func _ready():
$Range/CollisionShape2D.shape.radius = attack_range
- $ShootCooldown.wait_time = attack_speed
+ $ShootCooldown.wait_time = speed_base / attack_speed
%Data.text = "Range: %s - Power: %s - Speed: %s" % [
attack_range, attack_power, attack_speed
]
-
+
+ %HUD.visible = false
+
+ components_changed.connect(func():
+ selection_group_id = get_group_id()
+ )
#for component in [
#preload("res://Towers/Components/FrostComponent.gd").new(),
@@ -138,6 +157,7 @@ func add_component(component: TowerComponent):
var sprite = component.sprite
$ComponentsAnchor.add_child(sprite)
redraw_components()
+ components_changed.emit()
func remove_component(component_name: String):
for component in components:
@@ -146,6 +166,7 @@ func remove_component(component_name: String):
$ComponentsAnchor.remove_child($ComponentsAnchor.get_node(NodePath(component.name)))
break
redraw_components()
+ components_changed.emit()
func redraw_components():
for idx in range(components.size()):
@@ -176,7 +197,10 @@ func shoot():
func get_hud():
- return %HUD.get_child(0).duplicate()
+ var data = %HUD.get_child(0).duplicate()
+ data.name = name
+
+ return data
func get_region():
@@ -189,6 +213,19 @@ func get_region():
)
+func get_group_id() -> String:
+ var string := ""
+
+ string += str(attack_range)
+ string += str(attack_power)
+ string += str(attack_speed)
+
+ for component in components:
+ string += component.name
+
+ return str(components.size()) + string.md5_text()
+
+
func _on_tree_exiting() -> void:
is_selected = false
@@ -197,7 +234,9 @@ func _on_h_box_container_gui_input(event: InputEvent) -> void:
if event.is_action_pressed("select"):
get_viewport().set_input_as_handled()
- for tower in selected_towers:
+ var hud: HUD = Client.current_stage.get_node("HUD")
+ var towers = hud.selection_groups[hud.selected_group].duplicate()
+ for tower in towers:
var found = false
for idx in range(tower.components.size()):
var component = tower.components[idx]
@@ -216,7 +255,9 @@ func _on_h_box_container_2_gui_input(event: InputEvent) -> void:
if event.is_action_pressed("select"):
get_viewport().set_input_as_handled()
- for tower in selected_towers:
+ var hud: HUD = Client.current_stage.get_node("HUD")
+ var towers = hud.selection_groups[hud.selected_group].duplicate()
+ for tower in towers:
var found = false
for idx in range(tower.components.size()):
var component = tower.components[idx]
@@ -231,6 +272,57 @@ func _on_h_box_container_2_gui_input(event: InputEvent) -> void:
Client.update_tower(tower.get_path(), tower.to_network_data())
+func _on_button_1_pressed() -> void:
+ if Client.player.money < (attack_range / 8.0) + 10:
+ return
+
+ var hud: HUD = Client.current_stage.get_node("HUD")
+ var towers = hud.selection_groups[hud.selected_group].duplicate()
+ for tower: Tower in towers:
+ tower.attack_range += 8
+ tower.attack_value_changed.emit((attack_range / 8.0) - 1)
+ tower.get_node("%Data").text = "Range: %s - Power: %s - Speed: %s" % [
+ tower.attack_range, tower.attack_power, tower.attack_speed
+ ]
+ tower.get_node("%Range/CollisionShape2D").shape.radius = attack_range
+ tower.selection_group_id = tower.get_group_id()
+ Client.update_tower(tower.get_path(), tower.to_network_data())
+
+
+func _on_button_2_pressed() -> void:
+ if Client.player.money < attack_power * 10:
+ return
+
+ var hud: HUD = Client.current_stage.get_node("HUD")
+ var towers = hud.selection_groups[hud.selected_group].duplicate()
+ for tower: Tower in towers:
+ tower.attack_power += 1
+ tower.attack_value_changed.emit(attack_power - 1)
+ tower.get_node("%Data").text = "Range: %s - Power: %s - Speed: %s" % [
+ tower.attack_range, tower.attack_power, tower.attack_speed
+ ]
+ tower.selection_group_id = tower.get_group_id()
+ Client.update_tower(tower.get_path(), tower.to_network_data())
+
+
+func _on_button_3_pressed() -> void:
+ if Client.player.money < attack_speed * 10:
+ return
+
+ var hud: HUD = Client.current_stage.get_node("HUD")
+ var towers = hud.selection_groups[hud.selected_group].duplicate()
+ for tower: Tower in towers:
+ tower.attack_speed += 1
+ tower.attack_value_changed.emit(attack_speed - 1)
+ tower.get_node("%Data").text = "Range: %s - Power: %s - Speed: %s" % [
+ tower.attack_range, tower.attack_power, tower.attack_speed
+ ]
+ tower.get_node("%ShootCooldown").wait_time = (speed_base / attack_speed)
+ tower.selection_group_id = tower.get_group_id()
+ Client.update_tower(tower.get_path(), tower.to_network_data())
+
+
+
class NetworkData extends Resource:
var name: String
var owner_id: int
diff --git a/Towers/Tower.tscn b/Towers/Tower.tscn
index 55ae928..3c5241b 100644
--- a/Towers/Tower.tscn
+++ b/Towers/Tower.tscn
@@ -52,6 +52,7 @@ position = Vector2(16, 16)
shape = SubResource("RectangleShape2D_atm5x")
[node name="Range" type="Area2D" parent="."]
+unique_name_in_owner = true
collision_layer = 0
[node name="CollisionShape2D" type="CollisionShape2D" parent="Range"]
@@ -59,6 +60,7 @@ position = Vector2(16, 16)
shape = SubResource("CircleShape2D_qa8kt")
[node name="ShootCooldown" type="Timer" parent="."]
+unique_name_in_owner = true
one_shot = true
[node name="SelectableArea" parent="." instance=ExtResource("3_57d5u")]
@@ -72,25 +74,31 @@ position = Vector2(0, 32)
[node name="HUD" type="CanvasLayer" parent="."]
unique_name_in_owner = true
-visible = false
[node name="VBoxContainer" type="VBoxContainer" parent="HUD"]
-anchors_preset = 8
-anchor_left = 0.5
-anchor_top = 0.5
-anchor_right = 0.5
-anchor_bottom = 0.5
-offset_left = -38.0
-offset_top = -25.0
-offset_right = 38.0
-offset_bottom = 25.0
-grow_horizontal = 2
-grow_vertical = 2
+offset_left = 64.0
+offset_right = 140.0
+offset_bottom = 77.0
[node name="Data" type="Label" parent="HUD/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
+[node name="HBoxContainer" type="HBoxContainer" parent="HUD/VBoxContainer"]
+layout_mode = 2
+
+[node name="Button1" type="Button" parent="HUD/VBoxContainer/HBoxContainer"]
+layout_mode = 2
+text = "+Range"
+
+[node name="Button2" type="Button" parent="HUD/VBoxContainer/HBoxContainer"]
+layout_mode = 2
+text = "+Power"
+
+[node name="Button3" type="Button" parent="HUD/VBoxContainer/HBoxContainer"]
+layout_mode = 2
+text = "+Speed"
+
[node name="Components" type="VBoxContainer" parent="HUD/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
@@ -133,5 +141,8 @@ replication_config = SubResource("SceneReplicationConfig_spp26")
[connection signal="hover_enter" from="SelectableArea" to="." method="_on_selectable_area_hover_enter"]
[connection signal="hover_exit" from="SelectableArea" to="." method="_on_selectable_area_hover_exit"]
[connection signal="select" from="SelectableArea" to="." method="_on_selectable_area_select"]
+[connection signal="pressed" from="HUD/VBoxContainer/HBoxContainer/Button1" to="." method="_on_button_1_pressed"]
+[connection signal="pressed" from="HUD/VBoxContainer/HBoxContainer/Button2" to="." method="_on_button_2_pressed"]
+[connection signal="pressed" from="HUD/VBoxContainer/HBoxContainer/Button3" to="." method="_on_button_3_pressed"]
[connection signal="gui_input" from="HUD/VBoxContainer/Components/HBoxContainer" to="." method="_on_h_box_container_gui_input"]
[connection signal="gui_input" from="HUD/VBoxContainer/Components/HBoxContainer2" to="." method="_on_h_box_container_2_gui_input"]