summaryrefslogtreecommitdiff
path: root/Stages/Wintermaul/wintermaul.gd
diff options
context:
space:
mode:
Diffstat (limited to 'Stages/Wintermaul/wintermaul.gd')
-rw-r--r--Stages/Wintermaul/wintermaul.gd52
1 files changed, 34 insertions, 18 deletions
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")