diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-07-19 14:18:21 +0200 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-07-19 14:18:21 +0200 |
commit | 7ce3593119b399196d71c88e3d1cab08ff38bb80 (patch) | |
tree | cb0abec447ee9d053836b3eefb9a3947f4a2cb6c /Levels/Level.gd | |
parent | 7e579ced0b51f98b2c14a0c868bf428c12d4790b (diff) |
Diffstat (limited to 'Levels/Level.gd')
-rw-r--r-- | Levels/Level.gd | 50 |
1 files changed, 26 insertions, 24 deletions
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) |