Add WinEffect class and game win functionality; implement win and game over scenes
This commit is contained in:
46
Scenes/game_over.tscn
Normal file
46
Scenes/game_over.tscn
Normal file
@@ -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
|
45
Scenes/win_screen.tscn
Normal file
45
Scenes/win_screen.tscn
Normal file
@@ -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
|
13
Scripts/Core/Effects/WinEffect.cs
Normal file
13
Scripts/Core/Effects/WinEffect.cs
Normal file
@@ -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();
|
||||
}
|
||||
}
|
1
Scripts/Core/Effects/WinEffect.cs.uid
Normal file
1
Scripts/Core/Effects/WinEffect.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://77fa2htfghwy
|
@@ -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<string, MiracleDefinition> LoadAllMiracles()
|
||||
|
@@ -14,6 +14,9 @@ public partial class GameBus : Node
|
||||
public List<TierDefinition> FollowerTiers { get; private set; }
|
||||
public List<TierDefinition> HutTiers { get; private set; }
|
||||
|
||||
private PackedScene _gameOverScene = GD.Load<PackedScene>("res://Scenes/game_over.tscn");
|
||||
private PackedScene _winScene = GD.Load<PackedScene>("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<Buff> BuffRemoved;
|
||||
public event Action PopulationVisualsUpdated;
|
||||
public event Action<string> 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<double> listener) => _gameState.Subscribe(stat, listener);
|
||||
public void UnsubscribeFromStat(Stat stat, Action<double> 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user