From ce8fd41a93b40c785c5796802ef50c5c04214350 Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Sat, 23 Aug 2025 17:59:57 +0200 Subject: [PATCH] Add WinEffect class and game win functionality; implement win and game over scenes --- Scenes/game_over.tscn | 46 +++++++++++++++++++++++++++ Scenes/win_screen.tscn | 45 ++++++++++++++++++++++++++ Scripts/Core/Effects/WinEffect.cs | 13 ++++++++ Scripts/Core/Effects/WinEffect.cs.uid | 1 + Scripts/Core/MiracleLoader.cs | 3 +- Scripts/Singletons/GameBus.cs | 27 ++++++++++++++-- 6 files changed, 132 insertions(+), 3 deletions(-) create mode 100644 Scenes/game_over.tscn create mode 100644 Scenes/win_screen.tscn create mode 100644 Scripts/Core/Effects/WinEffect.cs create mode 100644 Scripts/Core/Effects/WinEffect.cs.uid diff --git a/Scenes/game_over.tscn b/Scenes/game_over.tscn new file mode 100644 index 0000000..a75859b --- /dev/null +++ b/Scenes/game_over.tscn @@ -0,0 +1,46 @@ +[gd_scene load_steps=4 format=3 uid="uid://kcla4knp80mq"] + +[ext_resource type="Script" uid="uid://cbdokimy0qarg" path="res://Scripts/MainMenu.cs" id="1_8fo1c"] +[ext_resource type="PackedScene" uid="uid://cmhvni5njpmee" path="res://Scenes/main_menu.tscn" id="2_ek8ke"] + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_i2yjh"] +bg_color = Color(0, 0, 0, 1) + +[node name="Game Over" type="CanvasLayer" node_paths=PackedStringArray("_startButton")] +script = ExtResource("1_8fo1c") +_gameScene = ExtResource("2_ek8ke") +_startButton = NodePath("CenterContainer/VBoxContainer/Quit") + +[node name="Panel" type="Panel" parent="."] +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 2 +theme_override_styles/panel = SubResource("StyleBoxFlat_i2yjh") + +[node name="CenterContainer" type="CenterContainer" parent="."] +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer"] +layout_mode = 2 + +[node name="RichTextLabel" type="RichTextLabel" parent="CenterContainer/VBoxContainer"] +custom_minimum_size = Vector2(640, 360) +layout_mode = 2 +bbcode_enabled = true +text = "By your hand, this creation has been [color=#B22222][b]unmade[/b][/color]. +Your followers, who offered you their very souls, have [color=#B22222][b]perished[/b][/color]. +You have [color=#B22222][b]failed[/b][/color] your sacred charge. You are an [color=#B22222][b]abomination[/b][/color] to your brethren." +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="Quit" type="Button" parent="CenterContainer/VBoxContainer"] +layout_mode = 2 +text = "Quit" +flat = true diff --git a/Scenes/win_screen.tscn b/Scenes/win_screen.tscn new file mode 100644 index 0000000..f32cbf7 --- /dev/null +++ b/Scenes/win_screen.tscn @@ -0,0 +1,45 @@ +[gd_scene load_steps=4 format=3 uid="uid://dtuyx1f5fa8sy"] + +[ext_resource type="Script" uid="uid://cbdokimy0qarg" path="res://Scripts/MainMenu.cs" id="1_a00f1"] +[ext_resource type="PackedScene" uid="uid://cmhvni5njpmee" path="res://Scenes/main_menu.tscn" id="2_awi1s"] + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_i2yjh"] +bg_color = Color(0, 0, 0, 1) + +[node name="Game Over" type="CanvasLayer" node_paths=PackedStringArray("_startButton")] +script = ExtResource("1_a00f1") +_gameScene = ExtResource("2_awi1s") +_startButton = NodePath("CenterContainer/VBoxContainer/Quit") + +[node name="Panel" type="Panel" parent="."] +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_styles/panel = SubResource("StyleBoxFlat_i2yjh") + +[node name="CenterContainer" type="CenterContainer" parent="."] +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer"] +layout_mode = 2 + +[node name="RichTextLabel" type="RichTextLabel" parent="CenterContainer/VBoxContainer"] +custom_minimum_size = Vector2(640, 360) +layout_mode = 2 +bbcode_enabled = true +text = "Through Your divine guidance, your followers have [color=gold][b]ascended to the stars[/b][/color]. +They now traverse the cosmos, settling new worlds in Your name and spreading word of Your glory. +[color=gold][b]Congratulations[/b][/color], you have proven yourself a [color=gold][b]True God[/b][/color], a creator, not a parasite." +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="Quit" type="Button" parent="CenterContainer/VBoxContainer"] +layout_mode = 2 +text = "Quit" +flat = true diff --git a/Scripts/Core/Effects/WinEffect.cs b/Scripts/Core/Effects/WinEffect.cs new file mode 100644 index 0000000..c60e038 --- /dev/null +++ b/Scripts/Core/Effects/WinEffect.cs @@ -0,0 +1,13 @@ +using Godot; +using ParasiticGod.Scripts.Singletons; + +namespace ParasiticGod.Scripts.Core.Effects; + +[GlobalClass] +public partial class WinEffect : Effect +{ + public override void Execute(GameState gameState) + { + GameBus.Instance.NotifyGameIsWon(); + } +} \ No newline at end of file diff --git a/Scripts/Core/Effects/WinEffect.cs.uid b/Scripts/Core/Effects/WinEffect.cs.uid new file mode 100644 index 0000000..66757e1 --- /dev/null +++ b/Scripts/Core/Effects/WinEffect.cs.uid @@ -0,0 +1 @@ +uid://77fa2htfghwy diff --git a/Scripts/Core/MiracleLoader.cs b/Scripts/Core/MiracleLoader.cs index 9579fba..dbc974a 100644 --- a/Scripts/Core/MiracleLoader.cs +++ b/Scripts/Core/MiracleLoader.cs @@ -15,7 +15,8 @@ public static class MiracleLoader { "ConvertResource", typeof(ConvertResourceEffect) }, { "ModifyStat", typeof(ModifyStatEffect) }, { "UnlockMiracle", typeof(UnlockMiracleEffect) }, - { "DestroySelf", typeof(DestroySelfEffect) } + { "DestroySelf", typeof(DestroySelfEffect) }, + { "Win", typeof(WinEffect)} }; public static System.Collections.Generic.Dictionary LoadAllMiracles() diff --git a/Scripts/Singletons/GameBus.cs b/Scripts/Singletons/GameBus.cs index ce995a2..9e80d6d 100644 --- a/Scripts/Singletons/GameBus.cs +++ b/Scripts/Singletons/GameBus.cs @@ -14,6 +14,9 @@ public partial class GameBus : Node public List FollowerTiers { get; private set; } public List HutTiers { get; private set; } + private PackedScene _gameOverScene = GD.Load("res://Scenes/game_over.tscn"); + private PackedScene _winScene = GD.Load("res://Scenes/win_screen.tscn"); + private readonly GameState _gameState = new(); private readonly GameLogic _gameLogic = new(); @@ -25,6 +28,7 @@ public partial class GameBus : Node public event Action BuffRemoved; public event Action PopulationVisualsUpdated; public event Action AgeAdvanced; + public event Action GameWon; public override void _EnterTree() { @@ -32,11 +36,14 @@ public partial class GameBus : Node AllMiracles = MiracleLoader.LoadAllMiracles(); FollowerTiers = TierLoader.LoadTiers("res://Mods/Tiers/follower_tiers.json", "user://Mods/Tiers/follower_tiers.json"); HutTiers = TierLoader.LoadTiers("res://Mods/Tiers/hut_tiers.json","user://Mods/Tiers/hut_tiers.json"); + + GameWon += OnGameWon; } public override void _ExitTree() { Instance = null; + GameWon -= OnGameWon; } public override void _Ready() @@ -51,8 +58,8 @@ public partial class GameBus : Node if (_gameState.Get(Stat.Corruption) >= 100) { - GD.Print("The world has died!"); - GetTree().Quit(); // For now + GetTree().ChangeSceneToPacked(_gameOverScene); + _gameState.Set(Stat.Corruption, 0); } } @@ -110,6 +117,11 @@ public partial class GameBus : Node BuffRemoved?.Invoke(buff); } + public void NotifyGameIsWon() + { + GameWon?.Invoke(); + } + public void SubscribeToStat(Stat stat, Action listener) => _gameState.Subscribe(stat, listener); public void UnsubscribeFromStat(Stat stat, Action listener) => _gameState.Unsubscribe(stat, listener); @@ -117,4 +129,15 @@ public partial class GameBus : Node [ConsoleCommand("set_stat", "Sets the value of a specified stat.")] private void SetStatCommand(Stat stat, double value) => _gameState.Set(stat, value); + + [ConsoleCommand("game_over")] + private void GameOverCommand() => GetTree().ChangeSceneToPacked(_gameOverScene); + + [ConsoleCommand("win_game")] + private void WinGameCommand() => GetTree().ChangeSceneToPacked(_winScene); + + private void OnGameWon() + { + GetTree().ChangeSceneToPacked(_winScene); + } } \ No newline at end of file