From 395c25b1fbe51f42decf402f97e51eabcc8c0a77 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sun, 18 Jun 2023 16:43:22 +0200 Subject: Godot v3 -> v4 --- Levels/Level.gd | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'Levels/Level.gd') diff --git a/Levels/Level.gd b/Levels/Level.gd index 2e623e5..d7ea0c9 100644 --- a/Levels/Level.gd +++ b/Levels/Level.gd @@ -5,18 +5,15 @@ var idx = 0 var timer = 0 var HUD = CanvasLayer.new() -var LabelTimer = preload("res://UI/HUD/Timer.tscn").instance() -var LevelMap = preload("res://UI/HUD/LevelMap.tscn").instance() -var CancelButton = preload("res://UI/HUD/CancelButton.tscn").instance() +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.HUD.add_child(self.LabelTimer) - self.HUD.add_child(self.LevelMap) - self.HUD.add_child(self.CancelButton) - self.add_child(self.HUD) + self.set_hud() - var character = load("res://Characters/" + Network.player.character + ".tscn").instance() + var character = load("res://Characters/" + Network.player.character + ".tscn").instantiate() self.set_player(character) @@ -26,11 +23,25 @@ func _process(delta): func _input(event): - if event is InputEventKey and event.scancode == KEY_ESCAPE: + if event is InputEventKey and event.keycode == KEY_ESCAPE: Global.open_menu() -func set_player(character: KinematicBody2D): +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(): -- cgit v1.2.3