Added respawn logic ... and with it also a complete rehaul of how managing scene instances work to make it work

This commit is contained in:
Martin committed 2026-03-01 15:40:56 +01:00
1 parent 51ee5029e9
commit 6d8e8e3734
14 files changed
+194 -36

No files matched your search

+61
View File
@@ -0,0 +1,61 @@
extends Node
# Main menu & game spawning
@onready
var mainMenuScene = preload("res://main_menu.tscn")
var mainMenuSceneInstance: Node
@onready
var gameScene = preload("res://molecular/molecular_stage.tscn")
var gameSceneInstance: Node
@onready
var respawnScene = preload("res://respawn_menu.tscn")
var respawnSceneInstance: Node
# Currently active scene (instance)
var currentSceneInstance:Node
# UI effects
var fadeEffect: CanvasLayer
func _ready() -> void:
# Instantiate effects
fadeEffect = $UI/Fade
fadeEffect.visible = false
# Create game (main menu)
print("Creating Main menu...")
mainMenuSceneInstance = mainMenuScene.instantiate()
currentSceneInstance = mainMenuSceneInstance
add_child(currentSceneInstance)
# Link MainMenu button to start_game
print("Linking Play button...")
mainMenuSceneInstance.get_node("PlayButton").connect("pressed", start_game)
func start_game() -> void:
print("Starting game...")
# Instatiate
currentSceneInstance.queue_free()
gameSceneInstance = gameScene.instantiate()
currentSceneInstance = gameSceneInstance
add_child(currentSceneInstance)
# Populate GameManager with game scene
GameManager.foodManager = gameSceneInstance.get_node("FoodManager")
func go_to_respawn_scene() -> void:
fadeEffect.visible = true
await fadeEffect.fade(1.0, 1.5).finished
print("Switching to Respawn scene.")
currentSceneInstance.queue_free()
respawnSceneInstance = respawnScene.instantiate()
respawnSceneInstance.get_node("RespawnButton").connect("pressed", start_game)
currentSceneInstance = respawnSceneInstance
add_child(currentSceneInstance)
await fadeEffect.fade(0.0, 1.5).finished
fadeEffect.visible = false
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.