extends Node2D var idx = 0 var timer = 0 var HUD = CanvasLayer.new() var LabelTimer = preload("res://UI/HUD/Timer.tscn").instantiate() var LevelMap = preload("res://UI/HUD/LevelMap.tscn").instantiate() var CancelButton = preload("res://UI/HUD/CancelButton.tscn").instantiate() func _ready(): self.set_hud() var character = load("res://Characters/" + Network.player.character + ".tscn").instantiate() self.set_player(character) func _process(delta): self.timer += delta self.LabelTimer.text = "%.2fs" % self.timer func _input(event): if event is InputEventKey and event.keycode == KEY_ESCAPE: Global.open_menu() func set_hud(): self.LabelTimer.position.x = 3 self.LevelMap.position.x = get_viewport_rect().end.x - self.LevelMap.size.x self.CancelButton.position.x = get_viewport_rect().end.x - self.CancelButton.size.x self.CancelButton.position.y = get_viewport_rect().end.y - self.CancelButton.size.y self.HUD.add_child(self.LabelTimer) self.HUD.add_child(self.LevelMap) self.HUD.add_child(self.CancelButton) self.add_child(self.HUD) func set_player(character: CharacterBody2D): character.position.x = $Character.position.x character.position.y = $Character.position.y for child in $Character.get_children(): if not child is Camera2D: $Character.remove_child(child) $Character.replace_by(character) func respawn_player(): var instance_level = Global.get_instance_level(self.idx) instance_level.timer = self.timer # timer continues playing Global.change_scene_to_instance(instance_level) func end_level(): Global.end_level(self) func cancel_level(): Global.cancel_level()