From 15a1d2a66e48324e1d560dc13b776627820f3999 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sun, 27 Oct 2024 15:52:48 +0100 Subject: next commit --- Towers/Tower.gd | 75 ++++++++++++++++++++++++++++++++++--------------------- Towers/Tower.tscn | 19 +++++++------- 2 files changed, 55 insertions(+), 39 deletions(-) (limited to 'Towers') diff --git a/Towers/Tower.gd b/Towers/Tower.gd index 2de8216..8acdf38 100644 --- a/Towers/Tower.gd +++ b/Towers/Tower.gd @@ -8,7 +8,7 @@ signal deselected static var selected_towers: Array[Tower] static var hovered_tower: Tower -var is_selected = false : +var is_selected := false: set(value): if value: if not Tower.selected_towers.has(self): @@ -17,10 +17,11 @@ var is_selected = false : else: Tower.selected_towers.erase(self) deselected.emit() + is_highlighted = false is_selected = value queue_redraw() -var is_hovered = false : +var is_hovered := false: set(value): if value: hovered_tower = self @@ -32,6 +33,11 @@ var is_hovered = false : is_hovered = value queue_redraw() +var is_highlighted := false: + set(value): + is_highlighted = value + queue_redraw() + var mobs_in_range: Array = [] #var selection_area: Area2D @@ -54,10 +60,11 @@ signal attack_value_changed(value: int) var speed_base: float = 2.0 signal components_changed -@export var components: Array[TowerComponent] = []#: - #set(value): - #components = value - #components_changed.emit() +@export var components: Array[TowerComponent] = [] + + +func _init(): + scale = Vector2(Client.current_stage.map.tile_set.tile_size) / Vector2(16, 16) func _ready(): @@ -70,15 +77,10 @@ func _ready(): %HUD.visible = false + redraw_components() components_changed.connect(func(): selection_group_id = get_group_id() ) - - #for component in [ - #preload("res://Towers/Components/FrostComponent.gd").new(), - #preload("res://Towers/Components/BurnComponent.gd").new(), - #]: - #add_component(component) func _draw(): @@ -87,7 +89,7 @@ func _draw(): if is_hovered: if Client.state is StateDefault: draw_circle( - Client.current_stage.map.tile_set.tile_size, + Vector2(Client.current_stage.map.tile_set.tile_size) / scale, 8 + attack_range, Color(1, 1, 1, 0.5), false, @@ -97,6 +99,15 @@ func _draw(): if is_selected: modulate = Color(1.5, 1.5, 1.5) + + if is_highlighted: + var sprite_size = $Sprite2D.get_rect().size + draw_rect( + Rect2($Sprite2D.position, sprite_size), + Color(1, 1, 1, 1.0), + false, + 2.0 / get_viewport().get_camera_2d().zoom.x + ) func _process(_delta: float) -> void: @@ -150,8 +161,6 @@ func _on_selectable_area_select(event: InputEvent) -> void: Client.multi_select(3) - - func add_component(component: TowerComponent): components.append(component) var sprite = component.sprite @@ -169,10 +178,14 @@ func remove_component(component_name: String): components_changed.emit() func redraw_components(): + for node in %Components.get_children(): + node.modulate = Color(1.0, 1.0, 1.0, 0.5) + for idx in range(components.size()): var component = components[idx] var sprite = $ComponentsAnchor.get_node(NodePath(component.name)) sprite.position.y = (idx + 1) * -16 + %Components.get_node(component.name).modulate = Color(1.0, 1.0, 1.0, 1.0) func is_melee_range(): @@ -209,7 +222,7 @@ func get_region(): return Rect2( collision_shape.position, - shape.size + shape.size * scale ) @@ -223,20 +236,21 @@ func get_group_id() -> String: for component in components: string += component.name - return str(components.size()) + string.md5_text() + return string.md5_text() func _on_tree_exiting() -> void: is_selected = false -func _on_h_box_container_gui_input(event: InputEvent) -> void: +func _on_h_box_container_gui_input(event: InputEvent) -> void: # TODO: money cost + # TODO: upgradeable if event.is_action_pressed("select"): get_viewport().set_input_as_handled() var hud: HUD = Client.current_stage.get_node("HUD") var towers = hud.selection_groups[hud.selected_group].duplicate() - for tower in towers: + for tower: Tower in towers: var found = false for idx in range(tower.components.size()): var component = tower.components[idx] @@ -257,7 +271,7 @@ func _on_h_box_container_2_gui_input(event: InputEvent) -> void: var hud: HUD = Client.current_stage.get_node("HUD") var towers = hud.selection_groups[hud.selected_group].duplicate() - for tower in towers: + for tower: Tower in towers: var found = false for idx in range(tower.components.size()): var component = tower.components[idx] @@ -273,11 +287,12 @@ func _on_h_box_container_2_gui_input(event: InputEvent) -> void: 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() + + if Client.player.money < (attack_range / 8.0) * 10 * towers.size(): + return + for tower: Tower in towers: tower.attack_range += 8 tower.attack_value_changed.emit((attack_range / 8.0) - 1) @@ -290,11 +305,12 @@ func _on_button_1_pressed() -> void: 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() + + if Client.player.money < attack_power * 10 * towers.size(): + return + for tower: Tower in towers: tower.attack_power += 1 tower.attack_value_changed.emit(attack_power - 1) @@ -306,11 +322,12 @@ func _on_button_2_pressed() -> void: 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() + + if Client.player.money < attack_speed * 10 * towers.size(): + return + for tower: Tower in towers: tower.attack_speed += 1 tower.attack_value_changed.emit(attack_speed - 1) diff --git a/Towers/Tower.tscn b/Towers/Tower.tscn index 3c5241b..792c41a 100644 --- a/Towers/Tower.tscn +++ b/Towers/Tower.tscn @@ -32,7 +32,6 @@ properties/4/spawn = true properties/4/replication_mode = 0 [node name="Tower" type="StaticBody2D"] -y_sort_enabled = true collision_layer = 4 collision_mask = 5 input_pickable = true @@ -45,7 +44,7 @@ scale = Vector2(1.0625, 1.0625) texture = ExtResource("1_mrep8") centered = false region_enabled = true -region_rect = Rect2(400, 432, 32, 48) +region_rect = Rect2(400, 439, 32, 41) [node name="CollisionShape2D" type="CollisionShape2D" parent="."] position = Vector2(16, 16) @@ -103,31 +102,31 @@ text = "+Speed" unique_name_in_owner = true layout_mode = 2 -[node name="HBoxContainer" type="HBoxContainer" parent="HUD/VBoxContainer/Components"] +[node name="Frost" type="HBoxContainer" parent="HUD/VBoxContainer/Components"] layout_mode = 2 mouse_default_cursor_shape = 2 -[node name="TextureRect" type="TextureRect" parent="HUD/VBoxContainer/Components/HBoxContainer"] +[node name="TextureRect" type="TextureRect" parent="HUD/VBoxContainer/Components/Frost"] custom_minimum_size = Vector2(32, 0) layout_mode = 2 texture = ExtResource("4_ccrqc") stretch_mode = 5 -[node name="Label" type="Label" parent="HUD/VBoxContainer/Components/HBoxContainer"] +[node name="Label" type="Label" parent="HUD/VBoxContainer/Components/Frost"] layout_mode = 2 text = "Frost" -[node name="HBoxContainer2" type="HBoxContainer" parent="HUD/VBoxContainer/Components"] +[node name="Burn" type="HBoxContainer" parent="HUD/VBoxContainer/Components"] layout_mode = 2 mouse_default_cursor_shape = 2 -[node name="TextureRect" type="TextureRect" parent="HUD/VBoxContainer/Components/HBoxContainer2"] +[node name="TextureRect" type="TextureRect" parent="HUD/VBoxContainer/Components/Burn"] custom_minimum_size = Vector2(32, 0) layout_mode = 2 texture = ExtResource("5_y7tf5") stretch_mode = 5 -[node name="Label" type="Label" parent="HUD/VBoxContainer/Components/HBoxContainer2"] +[node name="Label" type="Label" parent="HUD/VBoxContainer/Components/Burn"] layout_mode = 2 text = "Burn" @@ -144,5 +143,5 @@ replication_config = SubResource("SceneReplicationConfig_spp26") [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"] +[connection signal="gui_input" from="HUD/VBoxContainer/Components/Frost" to="." method="_on_h_box_container_gui_input"] +[connection signal="gui_input" from="HUD/VBoxContainer/Components/Burn" to="." method="_on_h_box_container_2_gui_input"] -- cgit v1.2.3