summaryrefslogtreecommitdiff
path: root/Levels
diff options
context:
space:
mode:
Diffstat (limited to 'Levels')
-rw-r--r--Levels/Level.gd50
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)