2024-12-27 21:00:07 +01:00
|
|
|
extends Node
|
|
|
|
|
|
|
|
|
|
var CURRENT_LEVEL: Node3D = null
|
|
|
|
|
var CURRENT_PLAYER: CharacterBody3D = null
|
2024-12-29 03:07:59 +01:00
|
|
|
var combined_signal : Observable
|
|
|
|
|
var prop = ReactiveProperty.new(42)
|
|
|
|
|
|
|
|
|
|
signal TestSignal
|
2024-12-27 21:00:07 +01:00
|
|
|
|
|
|
|
|
func _ready() -> void:
|
2024-12-29 03:07:59 +01:00
|
|
|
var lvl: Resource = load("res://assets/levels/level1.tscn")
|
|
|
|
|
var player: Resource = load("res://assets/characters/player.tscn")
|
2024-12-27 21:00:07 +01:00
|
|
|
CURRENT_LEVEL = lvl.instantiate()
|
|
|
|
|
CURRENT_PLAYER = player.instantiate()
|
|
|
|
|
CURRENT_PLAYER.transform.origin = Vector3(0, 1, 0)
|
|
|
|
|
add_child(CURRENT_LEVEL)
|
|
|
|
|
CURRENT_LEVEL.add_child(CURRENT_PLAYER)
|
2024-12-29 03:07:59 +01:00
|
|
|
combined_signal = GDRx.from_signal(Messagebus.CHANGE_SCENE)\
|
|
|
|
|
.first()\
|
|
|
|
|
.debounce(1)
|
|
|
|
|
combined_signal.subscribe(transition_to).dispose_with(self)
|
|
|
|
|
#prop.subscribe(func(i): print(">> ", i))
|
|
|
|
|
|
|
|
|
|
func transition_to(scene: PackedScene):
|
|
|
|
|
print(">>>>>>>"+str(scene))
|
|
|
|
|
CURRENT_LEVEL.remove_child(CURRENT_PLAYER)
|
|
|
|
|
remove_child(CURRENT_LEVEL)
|
|
|
|
|
var lvl = load(scene.resource_path)
|
|
|
|
|
var new_level = lvl.instantiate()
|
|
|
|
|
new_level.add_child(CURRENT_PLAYER)
|
|
|
|
|
CURRENT_PLAYER.transform.origin = Vector3(0, 1, 0)
|
|
|
|
|
CURRENT_PLAYER.set_owner(new_level)
|
|
|
|
|
add_child(new_level)
|
|
|
|
|
print("Transitioned to "+str(scene))
|
|
|
|
|
CURRENT_LEVEL = new_level
|
2024-12-27 21:00:07 +01:00
|
|
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
|
|
|
if (CURRENT_PLAYER.global_position.y) < -5:
|
|
|
|
|
CURRENT_PLAYER.translate(Vector3.UP*10)
|
|
|
|
|
# TODO: blah blah
|
|
|
|
|
|