-
Notifications
You must be signed in to change notification settings - Fork 16
/
world.gd
53 lines (42 loc) · 1.44 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
extends Node2D
@export var next_level: PackedScene
var level_time = 0.0
var start_level_msec = 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 is PackedScene:
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
start_in.visible = true
LevelTransition.fade_from_black()
animation_player.play("countdown")
await animation_player.animation_finished
get_tree().paused = false
start_in.visible = false
start_level_msec = Time.get_ticks_msec()
func _process(delta):
level_time = Time.get_ticks_msec() - start_level_msec
level_time_label.text = str(level_time / 1000.0)
func retry():
await LevelTransition.fade_to_black()
get_tree().paused = false
get_tree().change_scene_to_file(scene_file_path)
func go_to_next_level():
if not next_level is PackedScene: return
await LevelTransition.fade_to_black()
get_tree().paused = false
get_tree().change_scene_to_packed(next_level)
func show_level_completed():
level_completed.show()
level_completed.retry_button.grab_focus()
get_tree().paused = true
func _on_level_completed_retry():
retry()
func _on_level_completed_next_level():
go_to_next_level()