summaryrefslogtreecommitdiffstats
path: root/top.gd
diff options
context:
space:
mode:
authorJan Tuomi <jan@jantuomi.fi>2025-11-19 21:33:12 +0200
committerJan Tuomi <jan@jantuomi.fi>2025-11-20 23:08:30 +0200
commit74494315303723b6cdac5198d9fc90f334ced778 (patch)
treef044924bde75be5701200f3bc795b7ea02be8ac3 /top.gd
parentcb1655c3e3958845ec6b2b6ab634149cede152a8 (diff)
Improve transitions
Diffstat (limited to 'top.gd')
-rw-r--r--top.gd33
1 files changed, 24 insertions, 9 deletions
diff --git a/top.gd b/top.gd
index 63335c4..54a8baf 100644
--- a/top.gd
+++ b/top.gd
@@ -5,10 +5,8 @@ extends Node2D
var save_state_path = "user://save_state.cfg"
var save_state = ConfigFile.new()
-## Should objects like the Player react to input, and enemies move
-var objects_active = true
-
var _transition_room: Node
+var _transition_door_name: Variant # String or null
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
@@ -23,20 +21,23 @@ func _ready() -> void:
save_state.set_value("items", "test_item", true)
save_state.save(save_state_path)
print(OS.get_data_dir())
+
+func is_transitioning() -> bool:
+ return _transition_room != null
-func transition_to_room(room_name: String):
+func transition_to_room(room_path: String, door_name: Variant):
# Do not transition if there is already a transition in process
if _transition_room != null:
- print_debug("Tried to transition to ", room_name, " but a transition was already in process")
+ #print_debug("Tried to transition to ", room_name, " but a transition was already in process")
return
# Start animation
# The animation calls _change_room at a specific time
$TransitionCanvas/AnimationPlayer.play("room_trans_start")
- objects_active = false
- var room = ResourceLoader.load("res://room_" + room_name + ".tscn")
+ var room = ResourceLoader.load(room_path)
_transition_room = room.instantiate()
+ _transition_door_name = door_name
func _transition_start():
print_debug("_transition_start")
@@ -50,17 +51,31 @@ func _transition_start():
var next_room: Node = _transition_room
next_room.name = "active_room"
- next_room.connect("ready", _on_room_changed)
+ #next_room.connect("ready", _on_room_changed)
+ next_room.connect("tree_entered", _on_room_changed)
+ next_room.process_mode = Node.PROCESS_MODE_PAUSABLE
add_child(next_room)
func _on_room_changed():
print_debug("_on_room_changed")
+ var room = get_node("active_room")
+ var player: Player = room.find_child("Player")
+ if _transition_door_name:
+ var door: Door = room.find_child(_transition_door_name)
+ player.position = door.position
+ player.set_forced_input(door.exit_towards)
+
$TransitionCanvas/AnimationPlayer.play("room_trans_end")
func _transition_end():
print_debug("_transition_end")
- objects_active = true
_transition_room = null
+ _transition_door_name = null
+
+ var room = get_node("active_room")
+ var player: Player = room.find_child("Player")
+ if player:
+ player.set_forced_input(null)
func save():
save_state.save("user://save_state.cfg")