summaryrefslogtreecommitdiff
path: root/Stages
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 /Stages
parente82990eeafdf0be5d42d8aaa9b7fb6091e0d8435 (diff)
next commit
Diffstat (limited to 'Stages')
-rw-r--r--Stages/Stage.gd18
-rw-r--r--Stages/Wintermaul/HUD.gd50
-rw-r--r--Stages/Wintermaul/HUD.tscn256
-rw-r--r--Stages/Wintermaul/Wintermaul.tscn2
-rw-r--r--Stages/Wintermaul/wintermaul.gd52
5 files changed, 236 insertions, 142 deletions
diff --git a/Stages/Stage.gd b/Stages/Stage.gd
index cdffca9..a3608ee 100644
--- a/Stages/Stage.gd
+++ b/Stages/Stage.gd
@@ -4,6 +4,7 @@ extends Node
signal path_grid_changed
+static var maps: Array[TileMapLayer]
static var map: TileMapLayer
static var path_grid: AStarGrid2D
static var last_solid_set_points: Array[Vector2]
@@ -14,7 +15,8 @@ func _init() -> void:
func _ready() -> void:
- map = get_node("%Map")
+ maps = [get_node("%Map")]
+ map = maps[0]
path_grid = AStarGrid2D.new()
path_grid.region = map.get_used_rect()
@@ -26,10 +28,12 @@ func _ready() -> void:
assert(get_node("%StateManager"), "StateManager missing")
assert(get_node("%StateManager").get_children().size() > 0, "StateManager has no States")
- for cell in map.get_used_cells():
- var tile_data = map.get_cell_tile_data(cell)
- if tile_data.get_collision_polygons_count(0) > 0:
- path_grid.set_point_solid(cell, true)
+ @warning_ignore("shadowed_variable")
+ for map in maps:
+ for cell in map.get_used_cells():
+ var tile_data = map.get_cell_tile_data(cell)
+ if tile_data.get_collision_polygons_count(0) > 0:
+ path_grid.set_point_solid(cell, true)
func place_tower(_remote_data: Dictionary) -> void:
@@ -81,8 +85,8 @@ func _spawn_unit(parent: Node2D, unit: Unit):
parent.add_child(unit, true)
-func transform_players(script: Script):
- for player in Network.get_node("%Players").get_children():
+func set_player_script(script: Script):
+ for player in Network.get_players():
var previous_values := {}
var property_list = player.get_script().get_script_property_list().filter(func(item):
return item.type != 0
diff --git a/Stages/Wintermaul/HUD.gd b/Stages/Wintermaul/HUD.gd
index b6722ae..6eeb7da 100644
--- a/Stages/Wintermaul/HUD.gd
+++ b/Stages/Wintermaul/HUD.gd
@@ -2,9 +2,9 @@ class_name HUD
extends CanvasLayer
+@onready var time: Label = %Time
@onready var money: Label = %Money
@onready var income: Label = %Income
-@onready var tower: Label = %Tower
@onready var spawn_box: Control = %SpawnBox
@onready var team_top: PanelContainer = %TeamTop
@onready var team_bottom: PanelContainer = %TeamBottom
@@ -27,9 +27,53 @@ func _ready():
Client.stage_state_changed.connect(func(state: State):
if state is StateBuild:
- $TowerConfigurationsContainer.visible = true
+ %TowerConfigurationsContainer.visible = true
else:
- $TowerConfigurationsContainer.visible = false
+ %TowerConfigurationsContainer.visible = false
+ )
+
+ # TODO: fix multi select
+ %SelectionContainer.visible = false
+ %SelectionData.get_child(0).queue_free()
+ %MultiSelectionContainer.visible = false
+ Client.placed_tower.connect(func(tower: Tower):
+ tower.selected.connect(func():
+ var hud_data = tower.get_hud()
+ hud_data.name = tower.name
+
+ var groups = {"md5:1": [], "md5_2": []}
+ var selected_group = "md5"
+ # TODO: build groups from current component configurations matches. md5 of property values?
+ # TODO: do in tower.gd at select?
+
+ if Tower.selected_towers.size() == 1:
+ %SelectionContainer.visible = true
+ %MultiSelectionContainer.visible = false
+
+ %SelectionData.add_child(hud_data)
+ %MultiSelectionList.add_child(hud_data.duplicate())
+ elif Tower.selected_towers.size() > 1:
+ %SelectionContainer.visible = false
+ %MultiSelectionContainer.visible = true
+
+ %MultiSelectionList.add_child(hud_data)
+ )
+ tower.deselected.connect(func():
+ if Tower.selected_towers.size() == 0:
+ %SelectionContainer.visible = false
+ %MultiSelectionContainer.visible = false
+
+ for child in %SelectionData.get_children():
+ child.queue_free()
+ for child in %MultiSelectionList.get_children():
+ child.queue_free()
+ elif Tower.selected_towers.size() == 1:
+ %MultiSelectionContainer.visible = false
+ %SelectionContainer.visible = true
+ elif Tower.selected_towers.size() > 1:
+ # only remove deselected tower from list
+ %MultiSelectionList.get_node(NodePath(tower.name)).queue_free()
+ )
)
diff --git a/Stages/Wintermaul/HUD.tscn b/Stages/Wintermaul/HUD.tscn
index cb14d33..024910f 100644
--- a/Stages/Wintermaul/HUD.tscn
+++ b/Stages/Wintermaul/HUD.tscn
@@ -133,6 +133,11 @@ theme_override_constants/margin_right = 8
[node name="HBoxContainer" type="HBoxContainer" parent="Panel/VBoxContainer/Container/MarginContainer"]
layout_mode = 2
+[node name="Time" type="Label" parent="Panel/VBoxContainer/Container/MarginContainer/HBoxContainer"]
+unique_name_in_owner = true
+layout_mode = 2
+text = "0"
+
[node name="Money" type="Label" parent="Panel/VBoxContainer/Container/MarginContainer/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
@@ -147,34 +152,150 @@ text = "0"
custom_minimum_size = Vector2(0, 1)
layout_mode = 2
-[node name="SpawnBox" type="PanelContainer" parent="."]
-unique_name_in_owner = true
-anchors_preset = 3
+[node name="VBoxContainer" type="VBoxContainer" parent="."]
+anchors_preset = 1
anchor_left = 1.0
-anchor_top = 1.0
anchor_right = 1.0
-anchor_bottom = 1.0
-offset_left = -148.0
-offset_top = -116.0
+offset_left = -288.0
+offset_top = 41.0
offset_right = -4.0
-offset_bottom = -4.0
+offset_bottom = 131.0
grow_horizontal = 0
+mouse_filter = 0
+
+[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
+layout_mode = 2
+mouse_filter = 0
+
+[node name="LivesTop" type="Label" parent="VBoxContainer/HBoxContainer"]
+unique_name_in_owner = true
+layout_mode = 2
+size_flags_horizontal = 0
+text = "Lives"
+
+[node name="TeamTop" parent="VBoxContainer/HBoxContainer" instance=ExtResource("16_mq4um")]
+unique_name_in_owner = true
+layout_mode = 2
+size_flags_horizontal = 3
+
+[node name="HBoxContainer2" type="HBoxContainer" parent="VBoxContainer"]
+layout_mode = 2
+mouse_filter = 0
+
+[node name="LivesBottom" type="Label" parent="VBoxContainer/HBoxContainer2"]
+unique_name_in_owner = true
+layout_mode = 2
+size_flags_horizontal = 0
+text = "Lives"
+
+[node name="TeamBottom" parent="VBoxContainer/HBoxContainer2" instance=ExtResource("16_mq4um")]
+unique_name_in_owner = true
+layout_mode = 2
+size_flags_horizontal = 3
+
+[node name="MarginContainer" type="MarginContainer" parent="."]
+anchors_preset = 12
+anchor_top = 1.0
+anchor_right = 1.0
+anchor_bottom = 1.0
+offset_top = -120.0
+grow_horizontal = 2
grow_vertical = 0
+theme_override_constants/margin_left = 4
+theme_override_constants/margin_top = 4
+theme_override_constants/margin_right = 4
+theme_override_constants/margin_bottom = 4
+
+[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer"]
+layout_mode = 2
+
+[node name="TowerConfigurationsContainer" type="PanelContainer" parent="MarginContainer/HBoxContainer"]
+unique_name_in_owner = true
+layout_mode = 2
+size_flags_horizontal = 3
+size_flags_stretch_ratio = 100.0
+mouse_filter = 1
+
+[node name="MarginContainer" type="MarginContainer" parent="MarginContainer/HBoxContainer/TowerConfigurationsContainer"]
+layout_mode = 2
+theme_override_constants/margin_left = 8
+theme_override_constants/margin_top = 8
+theme_override_constants/margin_right = 8
+theme_override_constants/margin_bottom = 8
+
+[node name="ScrollContainer" type="ScrollContainer" parent="MarginContainer/HBoxContainer/TowerConfigurationsContainer/MarginContainer"]
+layout_mode = 2
+vertical_scroll_mode = 0
+
+[node name="TowerConfigurations" type="HBoxContainer" parent="MarginContainer/HBoxContainer/TowerConfigurationsContainer/MarginContainer/ScrollContainer"]
+layout_mode = 2
+size_flags_horizontal = 3
+size_flags_vertical = 3
+
+[node name="TextureRect" parent="MarginContainer/HBoxContainer/TowerConfigurationsContainer/MarginContainer/ScrollContainer/TowerConfigurations" instance=ExtResource("17_1c5dq")]
+layout_mode = 2
+
+[node name="MultiSelectionContainer" type="PanelContainer" parent="MarginContainer/HBoxContainer"]
+unique_name_in_owner = true
+custom_minimum_size = Vector2(200, 0)
+layout_mode = 2
+size_flags_horizontal = 6
+size_flags_stretch_ratio = 2.0
+
+[node name="MarginContainer" type="MarginContainer" parent="MarginContainer/HBoxContainer/MultiSelectionContainer"]
+layout_mode = 2
+theme_override_constants/margin_left = 4
+theme_override_constants/margin_top = 4
+theme_override_constants/margin_right = 4
+theme_override_constants/margin_bottom = 4
+
+[node name="MultiSelectionList" type="HFlowContainer" parent="MarginContainer/HBoxContainer/MultiSelectionContainer/MarginContainer"]
+unique_name_in_owner = true
+layout_mode = 2
+last_wrap_alignment = 1
+
+[node name="SelectionContainer" type="PanelContainer" parent="MarginContainer/HBoxContainer"]
+unique_name_in_owner = true
+custom_minimum_size = Vector2(200, 0)
+layout_mode = 2
+size_flags_horizontal = 6
+size_flags_stretch_ratio = 2.0
+
+[node name="SelectionData" type="MarginContainer" parent="MarginContainer/HBoxContainer/SelectionContainer"]
+unique_name_in_owner = true
+layout_mode = 2
+theme_override_constants/margin_left = 4
+theme_override_constants/margin_top = 4
+theme_override_constants/margin_right = 4
+theme_override_constants/margin_bottom = 4
+
+[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/HBoxContainer/SelectionContainer/SelectionData"]
+layout_mode = 2
+
+[node name="Label" type="Label" parent="MarginContainer/HBoxContainer/SelectionContainer/SelectionData/VBoxContainer"]
+layout_mode = 2
+text = "T"
+
+[node name="SpawnBox" type="PanelContainer" parent="MarginContainer/HBoxContainer"]
+unique_name_in_owner = true
+layout_mode = 2
+size_flags_horizontal = 10
+size_flags_stretch_ratio = 0.0
-[node name="MarginContainer" type="MarginContainer" parent="SpawnBox"]
+[node name="MarginContainer" type="MarginContainer" parent="MarginContainer/HBoxContainer/SpawnBox"]
layout_mode = 2
theme_override_constants/margin_left = 8
theme_override_constants/margin_top = 8
theme_override_constants/margin_right = 8
theme_override_constants/margin_bottom = 8
-[node name="GridContainer" type="GridContainer" parent="SpawnBox/MarginContainer"]
+[node name="GridContainer" type="GridContainer" parent="MarginContainer/HBoxContainer/SpawnBox/MarginContainer"]
layout_mode = 2
theme_override_constants/h_separation = 0
theme_override_constants/v_separation = 0
columns = 4
-[node name="SpawnButton" parent="SpawnBox/MarginContainer/GridContainer" instance=ExtResource("3_7eaea")]
+[node name="SpawnButton" parent="MarginContainer/HBoxContainer/SpawnBox/MarginContainer/GridContainer" instance=ExtResource("3_7eaea")]
layout_mode = 2
theme = ExtResource("5_121ry")
texture_normal = ExtResource("4_w7sef")
@@ -182,166 +303,75 @@ texture_pressed = ExtResource("5_xcxr8")
texture_hover = ExtResource("6_4go2d")
texture = ExtResource("7_ba5tw")
-[node name="SpawnButton2" parent="SpawnBox/MarginContainer/GridContainer" instance=ExtResource("3_7eaea")]
+[node name="SpawnButton2" parent="MarginContainer/HBoxContainer/SpawnBox/MarginContainer/GridContainer" instance=ExtResource("3_7eaea")]
layout_mode = 2
shortcut = SubResource("Shortcut_i6rmj")
texture_normal = ExtResource("8_wmbg8")
texture_hover = ExtResource("6_4go2d")
texture = ExtResource("9_nmd8t")
-[node name="SpawnButton3" parent="SpawnBox/MarginContainer/GridContainer" instance=ExtResource("3_7eaea")]
+[node name="SpawnButton3" parent="MarginContainer/HBoxContainer/SpawnBox/MarginContainer/GridContainer" instance=ExtResource("3_7eaea")]
layout_mode = 2
texture_normal = ExtResource("10_daowa")
texture_pressed = ExtResource("5_xcxr8")
texture_hover = ExtResource("6_4go2d")
texture = ExtResource("11_yxcwt")
-[node name="SpawnButton4" parent="SpawnBox/MarginContainer/GridContainer" instance=ExtResource("3_7eaea")]
+[node name="SpawnButton4" parent="MarginContainer/HBoxContainer/SpawnBox/MarginContainer/GridContainer" instance=ExtResource("3_7eaea")]
layout_mode = 2
texture_normal = ExtResource("12_20egp")
texture_pressed = ExtResource("5_xcxr8")
texture_hover = ExtResource("6_4go2d")
texture = ExtResource("13_iq5a7")
-[node name="SpawnButton5" parent="SpawnBox/MarginContainer/GridContainer" instance=ExtResource("3_7eaea")]
+[node name="SpawnButton5" parent="MarginContainer/HBoxContainer/SpawnBox/MarginContainer/GridContainer" instance=ExtResource("3_7eaea")]
layout_mode = 2
texture_normal = ExtResource("14_t3qlu")
texture_pressed = ExtResource("5_xcxr8")
texture_hover = ExtResource("6_4go2d")
-[node name="SpawnButton6" parent="SpawnBox/MarginContainer/GridContainer" instance=ExtResource("3_7eaea")]
+[node name="SpawnButton6" parent="MarginContainer/HBoxContainer/SpawnBox/MarginContainer/GridContainer" instance=ExtResource("3_7eaea")]
layout_mode = 2
texture_normal = ExtResource("14_t3qlu")
texture_pressed = ExtResource("5_xcxr8")
texture_hover = ExtResource("6_4go2d")
-[node name="SpawnButton7" parent="SpawnBox/MarginContainer/GridContainer" instance=ExtResource("3_7eaea")]
+[node name="SpawnButton7" parent="MarginContainer/HBoxContainer/SpawnBox/MarginContainer/GridContainer" instance=ExtResource("3_7eaea")]
layout_mode = 2
texture_normal = ExtResource("14_t3qlu")
texture_pressed = ExtResource("5_xcxr8")
texture_hover = ExtResource("6_4go2d")
-[node name="SpawnButton8" parent="SpawnBox/MarginContainer/GridContainer" instance=ExtResource("3_7eaea")]
+[node name="SpawnButton8" parent="MarginContainer/HBoxContainer/SpawnBox/MarginContainer/GridContainer" instance=ExtResource("3_7eaea")]
layout_mode = 2
texture_normal = ExtResource("14_t3qlu")
texture_pressed = ExtResource("5_xcxr8")
texture_hover = ExtResource("6_4go2d")
-[node name="SpawnButton9" parent="SpawnBox/MarginContainer/GridContainer" instance=ExtResource("3_7eaea")]
+[node name="SpawnButton9" parent="MarginContainer/HBoxContainer/SpawnBox/MarginContainer/GridContainer" instance=ExtResource("3_7eaea")]
layout_mode = 2
texture_normal = ExtResource("14_t3qlu")
texture_pressed = ExtResource("5_xcxr8")
texture_hover = ExtResource("6_4go2d")
-[node name="SpawnButton10" parent="SpawnBox/MarginContainer/GridContainer" instance=ExtResource("3_7eaea")]
+[node name="SpawnButton10" parent="MarginContainer/HBoxContainer/SpawnBox/MarginContainer/GridContainer" instance=ExtResource("3_7eaea")]
layout_mode = 2
texture_normal = ExtResource("14_t3qlu")
texture_pressed = ExtResource("5_xcxr8")
texture_hover = ExtResource("6_4go2d")
-[node name="SpawnButton11" parent="SpawnBox/MarginContainer/GridContainer" instance=ExtResource("3_7eaea")]
+[node name="SpawnButton11" parent="MarginContainer/HBoxContainer/SpawnBox/MarginContainer/GridContainer" instance=ExtResource("3_7eaea")]
layout_mode = 2
texture_normal = ExtResource("14_t3qlu")
texture_pressed = ExtResource("5_xcxr8")
texture_hover = ExtResource("6_4go2d")
-[node name="SpawnButton12" parent="SpawnBox/MarginContainer/GridContainer" instance=ExtResource("3_7eaea")]
+[node name="SpawnButton12" parent="MarginContainer/HBoxContainer/SpawnBox/MarginContainer/GridContainer" instance=ExtResource("3_7eaea")]
layout_mode = 2
texture_normal = ExtResource("14_t3qlu")
texture_pressed = ExtResource("5_xcxr8")
texture_hover = ExtResource("6_4go2d")
-[node name="VBoxContainer" type="VBoxContainer" parent="."]
-anchors_preset = 1
-anchor_left = 1.0
-anchor_right = 1.0
-offset_left = -256.0
-offset_top = 41.0
-offset_right = -4.0
-offset_bottom = 131.0
-grow_horizontal = 0
-mouse_filter = 0
-
-[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
-layout_mode = 2
-mouse_filter = 0
-
-[node name="LivesTop" type="Label" parent="VBoxContainer/HBoxContainer"]
-unique_name_in_owner = true
-layout_mode = 2
-size_flags_horizontal = 0
-text = "Lives"
-
-[node name="TeamTop" parent="VBoxContainer/HBoxContainer" instance=ExtResource("16_mq4um")]
-unique_name_in_owner = true
-layout_mode = 2
-size_flags_horizontal = 3
-
-[node name="HBoxContainer2" type="HBoxContainer" parent="VBoxContainer"]
-layout_mode = 2
-mouse_filter = 0
-
-[node name="LivesBottom" type="Label" parent="VBoxContainer/HBoxContainer2"]
-unique_name_in_owner = true
-layout_mode = 2
-size_flags_horizontal = 0
-text = "Lives"
-
-[node name="TeamBottom" parent="VBoxContainer/HBoxContainer2" instance=ExtResource("16_mq4um")]
-unique_name_in_owner = true
-layout_mode = 2
-size_flags_horizontal = 3
-
-[node name="CenterContainer" type="CenterContainer" parent="."]
-anchors_preset = 12
-anchor_top = 1.0
-anchor_right = 1.0
-anchor_bottom = 1.0
-offset_top = -23.0
-grow_horizontal = 2
-grow_vertical = 0
-
-[node name="Tower" type="Label" parent="CenterContainer"]
-unique_name_in_owner = true
-layout_mode = 2
-
-[node name="TowerConfigurationsContainer" type="MarginContainer" parent="."]
-visible = false
-anchors_preset = 12
-anchor_top = 1.0
-anchor_right = 1.0
-anchor_bottom = 1.0
-offset_top = -120.0
-offset_right = -152.0
-grow_horizontal = 2
-grow_vertical = 0
-theme_override_constants/margin_left = 4
-theme_override_constants/margin_top = 4
-theme_override_constants/margin_right = 4
-theme_override_constants/margin_bottom = 4
-
-[node name="PanelContainer" type="PanelContainer" parent="TowerConfigurationsContainer"]
-layout_mode = 2
-
-[node name="MarginContainer" type="MarginContainer" parent="TowerConfigurationsContainer/PanelContainer"]
-layout_mode = 2
-theme_override_constants/margin_left = 8
-theme_override_constants/margin_top = 8
-theme_override_constants/margin_right = 8
-theme_override_constants/margin_bottom = 8
-
-[node name="ScrollContainer" type="ScrollContainer" parent="TowerConfigurationsContainer/PanelContainer/MarginContainer"]
-layout_mode = 2
-vertical_scroll_mode = 0
-
-[node name="TowerConfigurations" type="HBoxContainer" parent="TowerConfigurationsContainer/PanelContainer/MarginContainer/ScrollContainer"]
-layout_mode = 2
-size_flags_horizontal = 3
-size_flags_vertical = 3
-
-[node name="TextureRect" parent="TowerConfigurationsContainer/PanelContainer/MarginContainer/ScrollContainer/TowerConfigurations" instance=ExtResource("17_1c5dq")]
-layout_mode = 2
-
[connection signal="gui_input" from="Panel/VBoxContainer/Container/GridContainer/MarginContainer/HBoxContainer/BuildModeButton" to="." method="_on_build_mode_button_gui_input"]
[connection signal="gui_input" from="Panel/VBoxContainer/Container/GridContainer/MarginContainer2/HBoxContainer2/SpawnerBoxButton" to="." method="_on_spawner_box_button_gui_input"]
[connection signal="gui_input" from="Panel/VBoxContainer/Container/GridContainer/MarginContainer3/HBoxContainer2/PlayerListButton" to="." method="_on_player_list_button_gui_input"]
diff --git a/Stages/Wintermaul/Wintermaul.tscn b/Stages/Wintermaul/Wintermaul.tscn
index 1fe8b26..6cf2d05 100644
--- a/Stages/Wintermaul/Wintermaul.tscn
+++ b/Stages/Wintermaul/Wintermaul.tscn
@@ -138,6 +138,6 @@ position = Vector2(2200, 1192)
shape = SubResource("RectangleShape2D_cwpxx")
[node name="IncomeTimer" type="Timer" parent="."]
-wait_time = 15.0
+one_shot = true
[connection signal="timeout" from="IncomeTimer" to="." method="_on_income_timer_timeout"]
diff --git a/Stages/Wintermaul/wintermaul.gd b/Stages/Wintermaul/wintermaul.gd
index 680f692..b638c97 100644
--- a/Stages/Wintermaul/wintermaul.gd
+++ b/Stages/Wintermaul/wintermaul.gd
@@ -16,11 +16,13 @@ class Team extends Resource:
var teams := Teams.new()
+var income_frequency := 15.0
+
func _init():
super._init()
- transform_players(preload("res://Stages/Wintermaul/player.gd"))
+ set_player_script(preload("res://Stages/Wintermaul/player.gd"))
teams.top.lives = 10
teams.bottom.lives = 10
@@ -33,8 +35,8 @@ func _ready():
if multiplayer.is_server():
for player in Network.get_players():
Network.update_player.rpc(player.id, {
- "money": 5,
- "income": 1,
+ "money": 50,
+ "income": 5,
})
# set camera limits
@@ -58,36 +60,43 @@ func _ready():
%HUD.get_node("%TeamTop").players = teams.top.players
%HUD.get_node("%TeamBottom").players = teams.bottom.players
- # start timer on server
- if multiplayer.is_server():
- $IncomeTimer.start()
+ # initialize timer and start
+ $IncomeTimer.wait_time = income_frequency
+ $IncomeTimer.start()
# initialize lives display
update_lives("top", 0)
update_lives("bottom", 0)
+func _process(_delta: float) -> void:
+ %HUD.time.text = "Time: %.0fs" % clamp($IncomeTimer.time_left + 0.5, 0, $IncomeTimer.wait_time)
+
+
@rpc("any_peer", "call_local")
func place_tower(remote_data: Dictionary):
var data: Tower.NetworkData = dict_to_inst(remote_data)
var tower = Tower.from_network_data(data)
- Network.get_player(tower.owner_id).towers[tower.global_position] = tower
+ var player = Network.get_player(tower.owner_id)
+ player.towers[tower.global_position] = tower
if multiplayer.is_server():
- var player = Network.get_player(tower.owner_id)
- Network.update_player.rpc(player.id, {"money": -1})
+ Network.update_player.rpc(player.id, {"money": -5})
_place_tower(%Towers, tower)
+ Client.placed_tower.emit(tower)
+
@rpc("any_peer", "call_local")
func spawn_unit(remote_data: Dictionary):
var data: Unit.NetworkData = dict_to_inst(remote_data)
var unit := Unit.from_network_data(data)
+ var player = Network.get_player(unit.owner_id)
+ player.units.append(unit)
+
if multiplayer.is_server():
- var player = Network.get_player(unit.owner_id)
-
unit.reached_goal.connect(func():
var team = get_team(player)
if team == teams.top:
@@ -97,7 +106,7 @@ func spawn_unit(remote_data: Dictionary):
)
Network.update_player.rpc(player.id, {
- "money": -1,
+ "money": -5,
"income": 1,
})
@@ -105,14 +114,14 @@ func spawn_unit(remote_data: Dictionary):
func can_place_tower():
- if Client.player.money < 1:
+ if Client.player.money < 5:
print("Not enough money to build tower")
return false
return true
func can_spawn_unit():
- if Client.player.money < 1:
+ if Client.player.money < 5:
print("Not enough money to spawn unit")
return false
@@ -156,10 +165,17 @@ func get_builder_collision_masks():
func _on_income_timer_timeout() -> void:
- for player in Network.get_players():
- Network.update_player.rpc(player.id, {
- "money": player.income,
- })
+ if multiplayer.is_server():
+ for player in Network.get_players():
+ Network.update_player.rpc(player.id, {
+ "money": player.income,
+ })
+ reset_timer.rpc()
+
+@rpc("authority", "call_local")
+func reset_timer():
+ $IncomeTimer.wait_time = income_frequency
+ $IncomeTimer.start()
@rpc("authority", "call_local")