portes: autoriser plusieurs portes

Maintenant une porte spécifie le spawn point de l'autre côté à
destination. Ca permet à un niveau d'avoir plusieurs points de sorties
et d'arrivée.
Quand la princesse meurt, elle respawn au point d'arrivée dans la carte
la dernière fois.

Pour l'instant c'est un peu pénible d'aller écire les bonnes coordonnées
dans chaque portes, je vais peut être finir par faire un truc
automatique.
This commit is contained in:
Thomas Lavocat
2023-05-03 18:10:36 +02:00
parent 99ae21ed87
commit 74228eca7d
5 changed files with 71 additions and 16 deletions

16
game.gd
View File

@@ -8,18 +8,19 @@ var level1 = preload("res://levels/level_1.tscn")
var scene_name = "level_0" var scene_name = "level_0"
var current_scence var current_scence
var prev_scene var prev_scene
var last_spawn_point = null
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready() -> void: func _ready() -> void:
go_to(scene_name) go_to(scene_name, null)
func reload_current_scene() -> void: func reload_current_scene() -> void:
go_to(scene_name) go_to(scene_name, last_spawn_point)
func enter_door(destination): func enter_door(destination : String, other_side_position : Vector2):
call_deferred("go_to", destination) call_deferred("go_to", destination, other_side_position)
func go_to(destination): func go_to(destination : String, spawn_point):
if current_scence: if current_scence:
remove_child(current_scence) remove_child(current_scence)
@@ -36,3 +37,8 @@ func go_to(destination):
for door in doors.get_children(): for door in doors.get_children():
door.connect("door_openned", enter_door, ConnectFlags.CONNECT_ONE_SHOT) door.connect("door_openned", enter_door, ConnectFlags.CONNECT_ONE_SHOT)
add_child(current_scence) add_child(current_scence)
if spawn_point:
var princesse :Princess = current_scence.find_child("Princesse")
princesse.position = spawn_point
last_spawn_point = spawn_point

View File

@@ -1,10 +1,12 @@
extends Area2D extends Area2D
@export var destination := "" @export var destination : String = ""
signal door_openned(where) @export var other_side_position : Vector2 = Vector2(0, 0)
signal door_openned(where : String, position : Vector2)
var openned = false var openned = false
func _on_body_entered(body: Node2D) -> void: func _on_body_entered(body: Node2D) -> void:
if not openned: if not openned:
openned = true openned = true
door_openned.emit(destination) door_openned.emit(destination, other_side_position)

View File

@@ -1322,6 +1322,35 @@ texture = ExtResource("2_n1x7g")
6:5/0/physics_layer_1/linear_velocity = Vector2(0, 0) 6:5/0/physics_layer_1/linear_velocity = Vector2(0, 0)
6:5/0/physics_layer_1/angular_velocity = 0.0 6:5/0/physics_layer_1/angular_velocity = 0.0
6:5/0/physics_layer_1/polygon_0/points = PackedVector2Array(-8, 0, -7, 0, -7, 2, -5, 2, -5, 1, -3, 1, -3, 2, -2, 2, -2, 3, 2, 3, 2, 1, 3, 1, 3, -1, 4, -1, 4, -2, 5, -2, 5, -1, 6, -1, 6, 1, 7, 1, 7, 7, 8, 7, 8, 8, -8, 8) 6:5/0/physics_layer_1/polygon_0/points = PackedVector2Array(-8, 0, -7, 0, -7, 2, -5, 2, -5, 1, -3, 1, -3, 2, -2, 2, -2, 3, 2, 3, 2, 1, 3, 1, 3, -1, 4, -1, 4, -2, 5, -2, 5, -1, 6, -1, 6, 1, 7, 1, 7, 7, 8, 7, 8, 8, -8, 8)
9:5/0 = 0
9:5/0/physics_layer_0/linear_velocity = Vector2(0, 0)
9:5/0/physics_layer_0/angular_velocity = 0.0
9:5/0/physics_layer_1/linear_velocity = Vector2(0, 0)
9:5/0/physics_layer_1/angular_velocity = 0.0
9:5/0/physics_layer_1/polygon_0/points = PackedVector2Array(-5, 8, -0.5, -1, 4, 8)
10:5/0 = 0
10:5/0/physics_layer_0/linear_velocity = Vector2(0, 0)
10:5/0/physics_layer_0/angular_velocity = 0.0
10:5/0/physics_layer_1/linear_velocity = Vector2(0, 0)
10:5/0/physics_layer_1/angular_velocity = 0.0
10:5/0/physics_layer_1/polygon_0/points = PackedVector2Array(4, -8, -0.5, 1, -5, -8)
11:5/0 = 0
11:5/0/physics_layer_0/linear_velocity = Vector2(0, 0)
11:5/0/physics_layer_0/angular_velocity = 0.0
11:5/0/physics_layer_1/linear_velocity = Vector2(0, 0)
11:5/0/physics_layer_1/angular_velocity = 0.0
11:5/0/physics_layer_1/polygon_0/points = PackedVector2Array(-8, -5, 1, -0.5, -8, 4)
12:5/0 = 0
12:5/0/physics_layer_0/linear_velocity = Vector2(0, 0)
12:5/0/physics_layer_0/angular_velocity = 0.0
12:5/0/physics_layer_1/linear_velocity = Vector2(0, 0)
12:5/0/physics_layer_1/angular_velocity = 0.0
12:5/0/physics_layer_1/polygon_0/points = PackedVector2Array(8, 4, -1, -0.5, 8, -5)
13:5/0 = 0
13:5/0/physics_layer_0/linear_velocity = Vector2(0, 0)
13:5/0/physics_layer_0/angular_velocity = 0.0
13:5/0/physics_layer_1/linear_velocity = Vector2(0, 0)
13:5/0/physics_layer_1/angular_velocity = 0.0
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_ojbk6"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_ojbk6"]
resource_name = "sans_collision_pour_background" resource_name = "sans_collision_pour_background"

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long