Skip to content

Commit

Permalink
Merge pull request #63 from gmuGADIG/Transition-areas
Browse files Browse the repository at this point in the history
Transition areas
  • Loading branch information
Justin1L8 authored Sep 29, 2024
2 parents 6dd561c + bb96027 commit 96ff68d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions player/player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ size = Vector2(128, 128)

[node name="Player" type="CharacterBody2D" groups=["Player"]]
z_index = 1
position = Vector2(320, 169)
collision_layer = 2
collision_mask = 41
motion_mode = 1
Expand Down
18 changes: 18 additions & 0 deletions world/transition_trigger/transition_trigger.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class_name transition_scene extends Area2D

var _player: Player
## The scene that you want to transition to, make sure to use the UID.
@export var scene: String

func _ready() -> void:
# wait a single frame in case our _ready was called before the player's
await get_tree().process_frame
_player = Player.instance
#make sure there is a scene and a player
assert(scene != "n", "The scene to transition to is not assigned!")
assert(_player != null, "No player exists in the scene!")

func _on_body_entered(body: Node2D) -> void:
var player := body as Player
if player != null:
SceneTransition.change_scene(load(scene))
15 changes: 15 additions & 0 deletions world/transition_trigger/transition_trigger.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[gd_scene load_steps=3 format=3 uid="uid://bwo5q4wroaigc"]

[ext_resource type="Script" path="res://world/transition_trigger/transition_trigger.gd" id="1_xpvta"]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_3rema"]

[node name="TransitionScene" type="Area2D"]
collision_layer = 0
collision_mask = 2
script = ExtResource("1_xpvta")

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_3rema")

[connection signal="body_entered" from="." to="." method="_on_body_entered"]

0 comments on commit 96ff68d

Please sign in to comment.