From a580e2ef7cca007a5ee857ea745c395e08763855 Mon Sep 17 00:00:00 2001 From: unfa Date: Sat, 11 Sep 2021 15:23:02 +0200 Subject: [PATCH] Respawn delay 5 seconds --- Game/Assets/Characters/Player.gd | 4 +-- Game/Main.gd | 60 ++++++++++++++++++++------------ 2 files changed, 40 insertions(+), 24 deletions(-) diff --git a/Game/Assets/Characters/Player.gd b/Game/Assets/Characters/Player.gd index dfa17eb..5a3c3d9 100644 --- a/Game/Assets/Characters/Player.gd +++ b/Game/Assets/Characters/Player.gd @@ -131,7 +131,7 @@ func _input(event) -> void: if not input_active: return - assert(is_network_authority() == true, "input_active is true, even though the node is not network_authority") + #assert(is_network_authority() == true, "input_active is true, even though the node is not network_authority") if Input.is_action_just_pressed("view_zoom"): # tween.remove_all() @@ -165,7 +165,7 @@ func _process(delta): if not input_active: return - assert(is_network_authority() == true, "input_active is true, even though the node is not network_authority") + #assert(is_network_authority() == true, "input_active is true, even though the node is not network_authority") if view_zoom_direction and view_zoom < view_zoom_target: view_zoom = min(view_zoom_target, view_zoom + delta * 4) diff --git a/Game/Main.gd b/Game/Main.gd index d6161fd..7159edf 100644 --- a/Game/Main.gd +++ b/Game/Main.gd @@ -72,13 +72,30 @@ class PlayerInfo: self.score = info['score'] #func generate(): +var uptime = 0 # seconds +const respawn_delay = 5 # seconds +var spawn_queue = {} + func _process(delta): + uptime += delta + $Label.text = "player_list: \n" for i in player_list.players.keys(): if player_list.players[i]: $Label.text += str(i) + " = " + str(player_list.get(i).serialize()) + "\n" else: $Label.text += str(i) + " = ???" + + # poll respawn queue + + $Label.text += "\n\nspawn_queue: \n" + $Label.text += str(spawn_queue) + + for i in spawn_queue.keys(): + if spawn_queue[i] <= uptime: + var is_local = true if i == get_tree().multiplayer.get_network_unique_id() else false + create_player(i, is_local, true) + spawn_queue.erase(i) class PlayerList: var players = {} @@ -111,23 +128,25 @@ class PlayerList: var focus = GameFocus.MENU : set(new_focus): - match new_focus: - 0: - Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) - gui.show() - if local_player: - local_player.input_active = false - 1: - Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) - gui.hide() - if local_player: - local_player.input_active = true - 2: - if local_player: - local_player.input_active = false - 3: - if local_player: - local_player.input_active = true + if local_player != null: + assert(local_player != null, "local_player is not null but it is null, WTF?!") + match new_focus: + 0: + Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) + gui.show() + if local_player: + local_player.input_active = false + 1: + Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) + gui.hide() + if local_player: + local_player.input_active = true + 2: + if local_player: + local_player.input_active = false + 3: + if local_player: + local_player.input_active = true focus = new_focus @@ -195,11 +214,8 @@ func push_local_player_info(): # assert(player_node != null, "Attempting to delete a player node that does not exist") player_node.name = str(player_node.name) + "_dead" # avoids name collision when instancing another player scene player_node.queue_free() - - #player.queue_free() - var is_local = true if pid == local_player.get_network_authority() else false - - create_player(pid, is_local, true) + + spawn_queue[pid] = uptime + respawn_delay func create_player(pid: int, is_local:= false, respawn:= false) -> void: var new_player