Files
Princesse-Lactose-Godot/game.gd
Thomas Lavocat 3c6d18f746 princesse/état: copie de l'état entre niveaux
La princesse récupère son état d'un niveau à l'autre. De cette manière,
on ne perd pas les fromages.
2023-05-10 20:53:27 +02:00

49 lines
1.5 KiB
GDScript

class_name Game extends Node
var current_scene : Node
var level0 = preload("res://levels/level_0.tscn")
var level1 = preload("res://levels/level_1.tscn")
var scene_name = "level_0"
var current_scence
var prev_scene
var last_spawn_point = null
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
go_to(scene_name, null)
func reload_current_scene() -> void:
go_to(scene_name, last_spawn_point)
func enter_door(destination : String, other_side_position : Vector2):
call_deferred("go_to", destination, other_side_position)
func go_to(destination : String, spawn_point):
var old_princesse :Princess
if current_scence:
old_princesse = current_scence.find_child("Princesse")
remove_child(current_scence)
if destination == "level_1":
current_scence = level1.instantiate()
scene_name = "level_1"
elif destination == "level_0":
current_scence = level0.instantiate()
scene_name = "level_0"
current_scence.connect("reload_me", reload_current_scene, ConnectFlags.CONNECT_ONE_SHOT)
var doors :Node = current_scence.find_child("Doors")
if doors:
for door in doors.get_children():
door.connect("door_openned", enter_door, ConnectFlags.CONNECT_ONE_SHOT)
add_child(current_scence)
if spawn_point:
var princesse :Princess = current_scence.find_child("Princesse")
princesse.position = spawn_point
last_spawn_point = spawn_point
if old_princesse:
princesse.copy_from(old_princesse)