diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-10-27 15:52:48 +0100 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-10-27 15:52:48 +0100 |
commit | 15a1d2a66e48324e1d560dc13b776627820f3999 (patch) | |
tree | 4c062545a4c1a750293b52d5c11258f9b4218a2a /Towers/Tower.gd | |
parent | a495681453c97578cc4a408d6919c6879524a603 (diff) |
next commit
Diffstat (limited to 'Towers/Tower.gd')
-rw-r--r-- | Towers/Tower.gd | 75 |
1 files changed, 46 insertions, 29 deletions
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) |