2024-07-23 15:49:31 +00:00
|
|
|
extends Node2D
|
|
|
|
|
2024-07-25 12:08:44 +00:00
|
|
|
|
|
|
|
|
2024-07-23 15:49:31 +00:00
|
|
|
@export var InitialPlayer :PackedScene
|
|
|
|
@export var InitialMap :PackedScene
|
|
|
|
|
|
|
|
@onready var current_scene = $CurrentScene
|
2024-07-29 16:35:23 +00:00
|
|
|
@onready var next_scene = $NextScene
|
2024-07-23 15:49:31 +00:00
|
|
|
#@onready var scene_transition = $ScreenTransition/AnimationPlayer
|
2024-07-29 13:25:36 +00:00
|
|
|
var player:Object
|
2024-07-23 15:49:31 +00:00
|
|
|
|
2024-07-29 13:25:36 +00:00
|
|
|
func transition_to_scene(new_scene: PackedScene, spawn_location = Transform2D.IDENTITY, spawn_direction = 1):
|
2024-07-23 15:49:31 +00:00
|
|
|
#screen_transition.play('FadeToBlack')
|
2024-07-29 13:25:36 +00:00
|
|
|
if (new_scene):
|
2024-07-29 16:35:23 +00:00
|
|
|
if (current_scene.get_child_count() == 0 ):
|
|
|
|
current_scene.add_child(new_scene.instantiate())
|
|
|
|
else:
|
|
|
|
next_scene.add_child(new_scene.instantiate())
|
2024-07-29 13:25:36 +00:00
|
|
|
else:
|
|
|
|
printerr("No New Scene")
|
2024-07-23 15:49:31 +00:00
|
|
|
|
|
|
|
#region Spawn Player
|
|
|
|
if (player):
|
2024-07-29 16:35:23 +00:00
|
|
|
player.reparent(next_scene.get_child(0))
|
2024-07-23 19:50:52 +00:00
|
|
|
player.teleport(spawn_location, spawn_direction)
|
2024-07-23 15:49:31 +00:00
|
|
|
else:
|
|
|
|
player = $CurrentScene.find_child("player",true)
|
|
|
|
if (player):
|
2024-07-23 19:50:52 +00:00
|
|
|
player.teleport(spawn_location, spawn_direction)
|
2024-07-25 12:08:44 +00:00
|
|
|
else: #Spawn the player if there is none
|
2024-07-23 15:49:31 +00:00
|
|
|
if (InitialPlayer):
|
|
|
|
player = InitialPlayer.instantiate()
|
|
|
|
player.set_name("player")
|
2024-07-26 09:51:34 +00:00
|
|
|
current_scene.get_child(0).add_child(player)
|
2024-07-23 15:49:31 +00:00
|
|
|
else:
|
|
|
|
printerr("No Initial player found")
|
|
|
|
#endregion
|
2024-07-29 16:35:23 +00:00
|
|
|
match spawn_direction:
|
|
|
|
0:
|
|
|
|
$AnimationPlayer.play("travel_left")
|
|
|
|
1:
|
|
|
|
$AnimationPlayer.play_backwards("travel_left")
|
|
|
|
2:
|
|
|
|
$AnimationPlayer.play_backwards("travel_down")
|
|
|
|
3:
|
|
|
|
$AnimationPlayer.play("travel_down")
|
2024-07-23 15:49:31 +00:00
|
|
|
|
|
|
|
func _on_ready():
|
|
|
|
transition_to_scene(InitialMap,Vector2(0,0),1)
|
2024-07-25 14:36:40 +00:00
|
|
|
|
2024-07-29 16:35:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _on_animation_player_animation_finished(anim_name):
|
|
|
|
print("anim finished")
|
|
|
|
current_scene.get_child(0).queue_free()
|
|
|
|
next_scene.get_child(0).reparent(current_scene)
|
|
|
|
next_scene.get_child(0).queue_free()
|