summaryrefslogtreecommitdiff
path: root/Levels/Level.gd
blob: 34463b65467125c4e1bf828f56c04598003ae3c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
extends Node2D


var idx = 0

var HUD = CanvasLayer.new()

var timer = 0
var LabelTimer = preload("res://UI/HUD/Timer.tscn").instance()
var LevelMap = preload("res://UI/HUD/LevelMap.tscn").instance()


func _ready():
	self.HUD.add_child(self.LabelTimer)
	self.HUD.add_child(self.LevelMap)
	self.add_child(self.HUD)
	
	var character = load("res://Characters/" + Network.player.character + ".tscn").instance()
	self.set_player(character)


func _process(delta):
	self.timer += delta
	self.LabelTimer.text = "%.2fs" % self.timer


func set_player(character: KinematicBody2D):
	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()