-
Notifications
You must be signed in to change notification settings - Fork 0
/
World.gd
40 lines (30 loc) · 1.13 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
extends Node
var MainInstances = ResourceLoader.MainInstances
onready var currentLevel = $Level_00
func _ready():
VisualServer.set_default_clear_color(Color.black)
Music.list_play()
if SaverAndLoader.is_loading:
SaverAndLoader.load_game()
SaverAndLoader.is_loading = false
MainInstances.Player.connect("hit_door", self, "_on_Player_hit_door")
func change_levels(door):
var offset = currentLevel.position
currentLevel.queue_free()
var NewLevel = load(door.new_level_path)
var newLevel = NewLevel.instance()
add_child(newLevel)
var newDoor = get_door_with_connection(door, door.connection)
var exit_position = newDoor.position - offset
newLevel.position = door.position - exit_position
func get_door_with_connection(notDoor, connection):
var doors = get_tree().get_nodes_in_group("Door")
for door in doors:
if door.connection == connection and door != notDoor:
return door
return null
func _on_Player_hit_door(door):
call_deferred("change_levels", door)
func _on_Player_player_died():
yield(get_tree().create_timer(1.0), "timeout")
get_tree().change_scene("res://Metroidvania Resources/Menus/GameOverMenu.tscn")