-
Notifications
You must be signed in to change notification settings - Fork 0
/
world.gd
58 lines (41 loc) · 1.53 KB
/
world.gd
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
48
49
50
51
52
53
54
55
56
57
58
extends Node2D
@export var next_level: PackedScene
var level_time = 0.0
var start_level_time = 0.0
@onready var level_completed = $CanvasLayer/LevelCompleted
@onready var start_in = %StartIn
@onready var start_in_label = %StartInLabel
@onready var animation_player = $AnimationPlayer
@onready var level_time_label = %LevelTimeLabel
func _ready():
if not next_level:
level_completed.next_level_button.text = "Victory Screen"
next_level = load("res://victory_screen.tscn")
Events.level_completed.connect(show_level_completed)
get_tree().paused = true
LevelTransition.fade_from_black()
animation_player.play("countdown")
await animation_player.animation_finished
get_tree().paused = false
start_level_time = Time.get_ticks_msec()
func _process(_delta):
level_time = Time.get_ticks_msec() - start_level_time
level_time_label.text = str(level_time / 1000.0)
func show_level_completed():
level_completed.show()
var level_name = get_tree().current_scene.name
HighScores.add_time(level_name, level_time)
level_completed.set_times(level_time, HighScores.get_best_time(level_name))
level_time_label.visible = false
level_completed.next_level_button.grab_focus()
get_tree().paused = true
func _on_level_completed_next_level():
if next_level:
await LevelTransition.fade_to_black()
get_tree().change_scene_to_packed(next_level)
get_tree().paused = false
func _on_level_completed_restart():
print("signal received")
await LevelTransition.fade_to_black()
get_tree().paused = false
get_tree().change_scene_to_file(scene_file_path)