From 7ce3593119b399196d71c88e3d1cab08ff38bb80 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Fri, 19 Jul 2024 14:18:21 +0200 Subject: cleanup and begin lobby rework --- Levels/Level.gd | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) (limited to 'Levels') diff --git a/Levels/Level.gd b/Levels/Level.gd index 40c75ff..9998a4e 100644 --- a/Levels/Level.gd +++ b/Levels/Level.gd @@ -19,30 +19,7 @@ func _ready(): character = load("res://Characters/" + Network.player.character + ".tscn").instantiate() self.set_player(character) - Network.connect("player_changed", func(id): - var remote_player = Network.players[id] - - var node_name = "%s_%s_%s" % [remote_player.name, remote_player.character, id] - var puppet = null - if self.has_node(node_name): - puppet = self.get_node(node_name) - - if remote_player.current_level != self.idx: - if puppet: - puppet.queue_free() - return - - if not puppet: - puppet = load("res://Characters/" + remote_player.character + ".tscn").instantiate() - puppet.process_mode = PROCESS_MODE_DISABLED - self.add_child(puppet) - puppet.name = node_name - puppet.modulate = Color(1.0, 1.0, 1.0, 0.5) - else: - puppet.position = remote_player.position - puppet.get_node("Sprite2D").play(remote_player.animation) - puppet.get_node("Sprite2D").flip_h = remote_player.animation_flip_h - ) + Network.connect("player_changed", Callable(self, 'update_puppet')) if has_node("ParallaxBackground"): $ParallaxBackground/ParallaxLayer.motion_mirroring.x = ( @@ -94,6 +71,31 @@ func respawn_player(): Global.change_scene_to_instance(instance_level) +func update_puppet(id: int): + var remote_player = Network.players[id] + + var node_name = "%s_%s_%s" % [remote_player.name, remote_player.character, id] + var puppet = null + if self.has_node(node_name): + puppet = self.get_node(node_name) + + if remote_player.current_level != self.idx: + if puppet: + puppet.queue_free() + return + + if not puppet: + puppet = load("res://Characters/" + remote_player.character + ".tscn").instantiate() + puppet.process_mode = PROCESS_MODE_DISABLED + self.add_child(puppet) + puppet.name = node_name + puppet.modulate = Color(1.0, 1.0, 1.0, 0.5) + else: + puppet.position = remote_player.position + puppet.get_node("Sprite2D").play(remote_player.animation) + puppet.get_node("Sprite2D").flip_h = remote_player.animation_flip_h + + func end_level(): Global.end_level(self) -- cgit v1.2.3