Fix game over
This commit is contained in:
@@ -6,7 +6,7 @@ using System.Linq;
|
||||
public partial class GameManager : Node
|
||||
{
|
||||
[Signal]
|
||||
public delegate void OnGameOverEventHandler();
|
||||
public delegate void OnPlayerGameOverEventHandler();
|
||||
[Signal]
|
||||
public delegate void ReselectCharacterEventHandler(Player player);
|
||||
|
||||
@@ -17,6 +17,8 @@ public partial class GameManager : Node
|
||||
|
||||
private int _levelIndex;
|
||||
|
||||
public bool IsGameOverScreenOn = false;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
var main = GetTree().Root.GetNode<Main>("/root/Main");
|
||||
@@ -84,6 +86,9 @@ public partial class GameManager : Node
|
||||
|
||||
if (!player.CharactersExited.Any() && !player.CharactersLeftOnStage.Any())
|
||||
SetGameOver(player, true);
|
||||
|
||||
if (Players.All(x => !x.CharactersLeftOnStage.Any()) && Players.Any(x => x.CharactersExited.Any()))
|
||||
OnLevelClear();
|
||||
}
|
||||
|
||||
public void RemoveCharacterAndAddToExit(Player player)
|
||||
@@ -103,10 +108,22 @@ public partial class GameManager : Node
|
||||
{
|
||||
player.GameOver = isGameOver;
|
||||
if (isGameOver)
|
||||
EmitSignal(SignalName.OnGameOver);
|
||||
EmitSignal(SignalName.OnPlayerGameOver);
|
||||
GD.Print($"Game over for {player.Name}");
|
||||
}
|
||||
|
||||
public void ReloadGameScene()
|
||||
{
|
||||
GD.Print("Reloading scene");
|
||||
var players = GetTree().Root.GetChildren().OfType<Player>();
|
||||
foreach (var player in players)
|
||||
player.QueueFree();
|
||||
var levels = GetTree().Root.GetChildren().OfType<Level>();
|
||||
foreach (var level in levels)
|
||||
level.QueueFree();
|
||||
GetTree().ReloadCurrentScene();
|
||||
}
|
||||
|
||||
public void OnLevelClear()
|
||||
{
|
||||
foreach (var player in Players)
|
||||
@@ -114,9 +131,12 @@ public partial class GameManager : Node
|
||||
player.CharactersLeftOnStage.AddRange(player.CharactersExited);
|
||||
player.CharactersExited.Clear();
|
||||
player.CharacterIndex = 0;
|
||||
GetTree().Root.RemoveChild(player.SelectedCharacter);
|
||||
}
|
||||
|
||||
var playerCharacters = GetTree().GetNodesInGroup("Player");
|
||||
foreach (var character in playerCharacters)
|
||||
character.GetParent().RemoveChild(character);
|
||||
|
||||
var projectiles = GetTree().Root.GetChildren().OfType<Projectile>();
|
||||
foreach (var projectile in projectiles)
|
||||
projectile.QueueFree();
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://cxj6yeddshy16"]
|
||||
[gd_scene load_steps=13 format=3 uid="uid://cxj6yeddshy16"]
|
||||
|
||||
[ext_resource type="Script" path="res://GameLogic/GameManager.cs" id="1_ya2kt"]
|
||||
[ext_resource type="PackedScene" uid="uid://b57xus5rqasy8" path="res://Player/Base/Player2.tscn" id="3_y1wkr"]
|
||||
[ext_resource type="PackedScene" uid="uid://xcmspevaqcrc" path="res://Player/Base/Player1.tscn" id="4_3fl70"]
|
||||
[ext_resource type="PackedScene" uid="uid://dq1gtd55p04do" path="res://UI/StageGUI.tscn" id="4_xi0i5"]
|
||||
[ext_resource type="Script" path="res://UI/StageGUI.cs" id="4_8bo7m"]
|
||||
[ext_resource type="Script" path="res://UI/GameOverService.cs" id="5_3te1o"]
|
||||
[ext_resource type="Texture2D" uid="uid://d18xmfbg47qpi" path="res://Textures/Portraits/blank-background.png" id="5_ecqoa"]
|
||||
[ext_resource type="Script" path="res://UI/CharacterSelectUpdateService.cs" id="6_8tbm6"]
|
||||
[ext_resource type="Texture2D" uid="uid://dveeywi80ux2l" path="res://UI/Game_Over.jpg" id="6_hq16y"]
|
||||
[ext_resource type="Texture2D" uid="uid://c3eubpygfvc3l" path="res://Textures/Portraits/cap-bg-char.png" id="7_jroqd"]
|
||||
[ext_resource type="Texture2D" uid="uid://1pgw8he4k5va" path="res://Textures/Portraits/pisces-bg-char.png" id="8_pvs36"]
|
||||
[ext_resource type="Texture2D" uid="uid://bacwvejc4hcou" path="res://Textures/Portraits/sag-bg-char.png" id="9_1jise"]
|
||||
[ext_resource type="Texture2D" uid="uid://o7uu4efxf36e" path="res://Textures/Portraits/scorpio-bg-char.png" id="10_mqkvb"]
|
||||
|
||||
[node name="GameManager" type="Node3D"]
|
||||
script = ExtResource("1_ya2kt")
|
||||
@@ -24,8 +32,6 @@ shadow_normal_bias = 0.0
|
||||
directional_shadow_mode = 0
|
||||
sky_mode = 1
|
||||
|
||||
[node name="StageGUI" parent="." instance=ExtResource("4_xi0i5")]
|
||||
|
||||
[node name="DirectionalLight3D2" type="DirectionalLight3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 0.993572, 0.113203, 0, -0.113203, 0.993572, 0, 6.22805, 0)
|
||||
shadow_enabled = true
|
||||
@@ -34,5 +40,207 @@ shadow_normal_bias = 0.0
|
||||
directional_shadow_mode = 0
|
||||
sky_mode = 1
|
||||
|
||||
[node name="StageGUI" type="Control" parent="."]
|
||||
process_mode = 3
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("4_8bo7m")
|
||||
metadata/_edit_horizontal_guides_ = [-342.0]
|
||||
|
||||
[node name="SidebarLeft" type="TextureRect" parent="StageGUI"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 4
|
||||
anchor_top = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_top = -540.0
|
||||
offset_right = 420.0
|
||||
offset_bottom = 540.0
|
||||
grow_vertical = 2
|
||||
texture = ExtResource("5_ecqoa")
|
||||
|
||||
[node name="SidebarRight" type="TextureRect" parent="StageGUI"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 6
|
||||
anchor_left = 1.0
|
||||
anchor_top = 0.5
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -420.0
|
||||
offset_top = -540.0
|
||||
offset_bottom = 540.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 2
|
||||
texture = ExtResource("5_ecqoa")
|
||||
|
||||
[node name="CharacterSelect" type="Control" parent="StageGUI"]
|
||||
process_mode = 3
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("6_8tbm6")
|
||||
|
||||
[node name="P1" type="Control" parent="StageGUI/CharacterSelect"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 4
|
||||
anchor_top = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_top = -20.0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 20.0
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="CapBG" type="TextureRect" parent="StageGUI/CharacterSelect/P1"]
|
||||
visible = false
|
||||
layout_mode = 1
|
||||
anchors_preset = 4
|
||||
anchor_top = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_top = -540.0
|
||||
offset_right = 420.0
|
||||
offset_bottom = 540.0
|
||||
grow_vertical = 2
|
||||
texture = ExtResource("7_jroqd")
|
||||
stretch_mode = 2
|
||||
|
||||
[node name="PiscesBG" type="TextureRect" parent="StageGUI/CharacterSelect/P1"]
|
||||
visible = false
|
||||
layout_mode = 1
|
||||
anchors_preset = 4
|
||||
anchor_top = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_top = -540.0
|
||||
offset_right = 420.0
|
||||
offset_bottom = 540.0
|
||||
grow_vertical = 2
|
||||
texture = ExtResource("8_pvs36")
|
||||
stretch_mode = 2
|
||||
|
||||
[node name="SagBG" type="TextureRect" parent="StageGUI/CharacterSelect/P1"]
|
||||
visible = false
|
||||
layout_mode = 1
|
||||
anchors_preset = 4
|
||||
anchor_top = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_top = -540.0
|
||||
offset_right = 420.0
|
||||
offset_bottom = 540.0
|
||||
grow_vertical = 2
|
||||
texture = ExtResource("9_1jise")
|
||||
stretch_mode = 2
|
||||
|
||||
[node name="ScorpioBG" type="TextureRect" parent="StageGUI/CharacterSelect/P1"]
|
||||
visible = false
|
||||
layout_mode = 1
|
||||
anchors_preset = 4
|
||||
anchor_top = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_top = -540.0
|
||||
offset_right = 420.0
|
||||
offset_bottom = 540.0
|
||||
grow_vertical = 2
|
||||
texture = ExtResource("10_mqkvb")
|
||||
stretch_mode = 2
|
||||
|
||||
[node name="P2" type="Control" parent="StageGUI/CharacterSelect"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 6
|
||||
anchor_left = 1.0
|
||||
anchor_top = 0.5
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -40.0
|
||||
offset_top = -20.0
|
||||
offset_bottom = 20.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="CapBG" type="TextureRect" parent="StageGUI/CharacterSelect/P2"]
|
||||
visible = false
|
||||
layout_mode = 1
|
||||
anchors_preset = 6
|
||||
anchor_left = 1.0
|
||||
anchor_top = 0.5
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -420.0
|
||||
offset_top = -540.0
|
||||
offset_bottom = 540.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 2
|
||||
texture = ExtResource("7_jroqd")
|
||||
|
||||
[node name="PiscesBG" type="TextureRect" parent="StageGUI/CharacterSelect/P2"]
|
||||
visible = false
|
||||
layout_mode = 1
|
||||
anchors_preset = 6
|
||||
anchor_left = 1.0
|
||||
anchor_top = 0.5
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -420.0
|
||||
offset_top = -540.0
|
||||
offset_bottom = 540.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 2
|
||||
texture = ExtResource("8_pvs36")
|
||||
|
||||
[node name="SagBG" type="TextureRect" parent="StageGUI/CharacterSelect/P2"]
|
||||
visible = false
|
||||
layout_mode = 1
|
||||
anchors_preset = 6
|
||||
anchor_left = 1.0
|
||||
anchor_top = 0.5
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -420.0
|
||||
offset_top = -540.0
|
||||
offset_bottom = 540.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 2
|
||||
texture = ExtResource("9_1jise")
|
||||
|
||||
[node name="ScorpioBG" type="TextureRect" parent="StageGUI/CharacterSelect/P2"]
|
||||
visible = false
|
||||
layout_mode = 1
|
||||
anchors_preset = 6
|
||||
anchor_left = 1.0
|
||||
anchor_top = 0.5
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -420.0
|
||||
offset_top = -540.0
|
||||
offset_bottom = 540.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 2
|
||||
texture = ExtResource("10_mqkvb")
|
||||
|
||||
[node name="GameOver" type="Control" parent="."]
|
||||
visible = false
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
script = ExtResource("5_3te1o")
|
||||
|
||||
[node name="GameOverScreen" type="TextureRect" parent="GameOver"]
|
||||
layout_mode = 0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
texture = ExtResource("6_hq16y")
|
||||
|
||||
[connection signal="ReselectCharacter" from="." to="StageGUI" method="OnCharacterSelect"]
|
||||
[connection signal="CapricornSelected" from="StageGUI" to="StageGUI/CharacterSelect" method="OnCapricornSelected"]
|
||||
[connection signal="OnCharacterSelectionMade" from="StageGUI" to="." method="OnCharacterSelected"]
|
||||
[connection signal="OnGameOver" from="StageGUI" to="GameOver" method="OnGameOver"]
|
||||
[connection signal="OnPlayerGameOver" from="StageGUI" to="StageGUI/CharacterSelect" method="OnPlayerGameOver"]
|
||||
[connection signal="PiscesSelected" from="StageGUI" to="StageGUI/CharacterSelect" method="OnPiscesSelected"]
|
||||
[connection signal="SagittariusSelected" from="StageGUI" to="StageGUI/CharacterSelect" method="OnSagittariusSelected"]
|
||||
[connection signal="ScorpioSelected" from="StageGUI" to="StageGUI/CharacterSelect" method="OnScorpioSelected"]
|
||||
[connection signal="ReloadGame" from="GameOver" to="." method="ReloadGameScene"]
|
||||
|
||||
Reference in New Issue
Block a user