Skip to content

Commit 18e8aae

Browse files
authored
Merge pull request #372 from Maaack/adds-simpler-win-lose-manager
Adds simpler win lose manager
2 parents 16dc9c9 + 88362ec commit 18e8aae

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

addons/maaacks_game_template/docs/GameSceneSetup.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ In that case, the following nodes can be safely removed:
3232
* LevelManager
3333
* LevelLoadingScreen
3434

35-
The single level scene can then be added directly to the `SubViewport`, another container, or the root node.
35+
The single level scene can then be added directly to the `SubViewport`, another container, or the root node.
36+
37+
To manage the win and lose screens and transitioning to other scenes, add a `Node` and attach the `win_lose_manager.gd` script. Inspect the node to attach the win / lose screens and paths. The `game_won()` or `game_lost()` will then need to be called when gameplay conditions are met.
3638

3739
## Background Music
3840
`BackgroundMusicPlayer`'s are `AudioStreamPlayer`'s with `autoplay` set to `true` and `audio_bus` set to "Music". These will automatically be recognized by the `ProjectMusicController` with the default settings, and allow for blending between tracks.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
extends Node
2+
3+
## Path to a main menu scene.
4+
@export_file("*.tscn") var main_menu_scene : String
5+
## Optional path to an ending scene.
6+
@export_file("*.tscn") var ending_scene : String
7+
## Optional screen to be shown after the game is won.
8+
@export var game_won_scene : PackedScene
9+
## Optional screen to be shown after the game is lost.
10+
@export var game_lost_scene : PackedScene
11+
12+
func _try_connecting_signal_to_node(node : Node, signal_name : String, callable : Callable) -> void:
13+
if node.has_signal(signal_name) and not node.is_connected(signal_name, callable):
14+
node.connect(signal_name, callable)
15+
16+
func _load_main_menu() -> void:
17+
SceneLoader.load_scene(main_menu_scene)
18+
19+
func _load_ending() -> void:
20+
if ending_scene:
21+
SceneLoader.load_scene(ending_scene)
22+
else:
23+
_load_main_menu()
24+
25+
func _load_lose_screen_or_reload() -> void:
26+
if game_lost_scene:
27+
var instance = game_lost_scene.instantiate()
28+
get_tree().current_scene.add_child(instance)
29+
_try_connecting_signal_to_node(instance, &"restart_pressed", _reload_level)
30+
_try_connecting_signal_to_node(instance, &"main_menu_pressed", _load_main_menu)
31+
else:
32+
_reload_level()
33+
34+
func _reload_level() -> void:
35+
SceneLoader.reload_current_scene()
36+
37+
func _load_win_screen_or_ending() -> void:
38+
if game_won_scene:
39+
var instance = game_won_scene.instantiate()
40+
get_tree().current_scene.add_child(instance)
41+
_try_connecting_signal_to_node(instance, &"continue_pressed", _load_ending)
42+
_try_connecting_signal_to_node(instance, &"restart_pressed", _reload_level)
43+
_try_connecting_signal_to_node(instance, &"main_menu_pressed", _load_main_menu)
44+
else:
45+
_load_ending()
46+
47+
func game_lost() -> void:
48+
_load_lose_screen_or_reload()
49+
50+
func game_won() -> void:
51+
_load_win_screen_or_ending()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://bmlwpkrav3q56

0 commit comments

Comments
 (0)