summaryrefslogtreecommitdiff
path: root/Towers/Tower.gd
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-10-20 12:09:48 +0200
committerDaniel Weipert <git@mail.dweipert.de>2024-10-20 12:09:48 +0200
commit6db6465d1b938ec494cd66c9984bff5cc14bde11 (patch)
tree9533b364e3e40ff813ef263ab05bd69ac31f8777 /Towers/Tower.gd
parente82990eeafdf0be5d42d8aaa9b7fb6091e0d8435 (diff)
next commit
Diffstat (limited to 'Towers/Tower.gd')
-rw-r--r--Towers/Tower.gd68
1 files changed, 32 insertions, 36 deletions
diff --git a/Towers/Tower.gd b/Towers/Tower.gd
index 30af802..7eb8bf6 100644
--- a/Towers/Tower.gd
+++ b/Towers/Tower.gd
@@ -13,13 +13,12 @@ var is_selected = false :
if value:
if not Tower.selected_towers.has(self):
Tower.selected_towers.append(self)
- selected.emit()
+ selected.emit()
else:
Tower.selected_towers.erase(self)
deselected.emit()
is_selected = value
queue_redraw()
- toggle_ui()
var is_hovered = false :
set(value):
@@ -51,7 +50,10 @@ func _ready():
$Range/CollisionShape2D.shape.radius = attack_range
$ShootCooldown.wait_time = attack_speed
- toggle_ui()
+ %Data.text = "Range: %s - Power: %s - Speed: %s" % [
+ attack_range, attack_power, attack_speed
+ ]
+
#for component in [
#preload("res://Towers/Components/FrostComponent.gd").new(),
@@ -61,16 +63,9 @@ func _ready():
func _draw():
- if is_selected:
- draw_circle(
- Client.current_stage.map.tile_set.tile_size,
- 8 + attack_range,
- Color(1, 1, 1, 0.75),
- false,
- 1.0
- )
- modulate = Color(1.5, 1.5, 1.5)
- elif is_hovered:
+ modulate = Color(1, 1, 1)
+
+ if is_hovered:
if Client.state is StateDefault:
draw_circle(
Client.current_stage.map.tile_set.tile_size,
@@ -80,8 +75,9 @@ func _draw():
1.0
)
modulate = Color(1.25, 1.25, 1.25)
- else:
- modulate = Color(1, 1, 1)
+
+ if is_selected:
+ modulate = Color(1.5, 1.5, 1.5)
func _process(_delta: float) -> void:
@@ -126,16 +122,13 @@ func _on_selectable_area_select(event: InputEvent) -> void:
return
if Client.state is StateDefault:
- Client.select_tower(self)
-
- if event.is_double_click():
- var selection_area = preload("res://Game/Selection/MultiSelectArea.tscn").instantiate()
- selection_area.set_collision_mask_value(3, true)
- selection_area.select.connect(func(nodes):
- for node in nodes:
- Client.select_tower(node)
- )
- get_tree().current_scene.add_child(selection_area)
+ if Input.is_action_pressed("select_multiple") and is_selected:
+ is_selected = false
+ else:
+ Client.select_tower(self)
+
+ if event.is_double_click():
+ Client.multi_select(3)
@@ -182,8 +175,8 @@ func shoot():
target.set_hp(target.hp - 1)
-func toggle_ui():
- $HUD.visible = is_selected
+func get_hud():
+ return %HUD.get_child(0).duplicate()
func get_region():
@@ -200,15 +193,6 @@ func _on_tree_exiting() -> void:
is_selected = false
-func get_rpc_properties() -> Dictionary:
- return {
- "name": null,
- "global_position": null,
- "owner_id": null,
- "attack_range": null,
- }
-
-
func _on_h_box_container_gui_input(event: InputEvent) -> void:
if event.is_action_pressed("select"):
get_viewport().set_input_as_handled()
@@ -251,6 +235,10 @@ class NetworkData extends Resource:
var name: String
var owner_id: int
var position: Vector2
+
+ var attack_range: int
+ var attack_power: int
+ var attack_speed: int
var components: Array
var sprite_modulate: Color
@@ -262,6 +250,10 @@ func to_network_data() -> NetworkData:
data.name = name
data.owner_id = owner_id
data.position = global_position
+
+ data.attack_range = attack_range
+ data.attack_power = attack_power
+ data.attack_speed = attack_speed
data.components = components.map(func(item: TowerComponent):
return item.name
)
@@ -289,4 +281,8 @@ static func from_network_data(data: NetworkData) -> Tower:
tower.owner_id = data.owner_id
tower.global_position = data.position
+ tower.attack_range = data.attack_range
+ tower.attack_power = data.attack_power
+ tower.attack_speed = data.attack_speed
+
return tower