✨ End game
This commit is contained in:
		@@ -1,4 +1,4 @@
 | 
			
		||||
[gd_scene load_steps=11 format=3 uid="uid://bjhmjrldq4lkt"]
 | 
			
		||||
[gd_scene load_steps=12 format=3 uid="uid://bjhmjrldq4lkt"]
 | 
			
		||||
 | 
			
		||||
[ext_resource type="PackedScene" uid="uid://b3gx0bl43lku3" path="res://Scenes/Player.tscn" id="1_vby0g"]
 | 
			
		||||
[ext_resource type="PackedScene" uid="uid://dk8x2aeq1eevf" path="res://Scenes/UI/BootScreen.tscn" id="2_7aede"]
 | 
			
		||||
@@ -6,6 +6,7 @@
 | 
			
		||||
[ext_resource type="Script" path="res://Scripts/Launcher.cs" id="2_u5cms"]
 | 
			
		||||
[ext_resource type="Script" path="res://Scripts/Logic/Scoreboard.cs" id="3_as2wg"]
 | 
			
		||||
[ext_resource type="Script" path="res://Scripts/Logic/World.cs" id="3_xwguj"]
 | 
			
		||||
[ext_resource type="PackedScene" uid="uid://cnf80yioktsvj" path="res://Scenes/UI/GameOverScreen.tscn" id="5_441wx"]
 | 
			
		||||
[ext_resource type="PackedScene" uid="uid://bb704b0kpwwkr" path="res://Scenes/UI/PlayerDiedScreen.tscn" id="5_pimes"]
 | 
			
		||||
[ext_resource type="PackedScene" uid="uid://c7w5sgq0bshk0" path="res://Scenes/UI/HUD.tscn" id="5_qvun1"]
 | 
			
		||||
[ext_resource type="PackedScene" uid="uid://dfoy57v3q4of5" path="res://Scenes/UI/Leaderboard.tscn" id="7_j24m7"]
 | 
			
		||||
@@ -17,6 +18,9 @@ properties/0/replication_mode = 1
 | 
			
		||||
properties/1/path = NodePath(".:RoundTimeLeft")
 | 
			
		||||
properties/1/spawn = true
 | 
			
		||||
properties/1/replication_mode = 1
 | 
			
		||||
properties/2/path = NodePath(".:RoundCount")
 | 
			
		||||
properties/2/spawn = true
 | 
			
		||||
properties/2/replication_mode = 1
 | 
			
		||||
 | 
			
		||||
[node name="Node" type="Node"]
 | 
			
		||||
 | 
			
		||||
@@ -38,7 +42,16 @@ script = ExtResource("3_as2wg")
 | 
			
		||||
 | 
			
		||||
[node name="OverlayLayer" type="CanvasLayer" parent="."]
 | 
			
		||||
 | 
			
		||||
[node name="PlayerDiedScreen" parent="OverlayLayer" instance=ExtResource("5_pimes")]
 | 
			
		||||
visible = false
 | 
			
		||||
 | 
			
		||||
[node name="GameOverScreen" parent="OverlayLayer" node_paths=PackedStringArray("Scoreboard") instance=ExtResource("5_441wx")]
 | 
			
		||||
process_mode = 3
 | 
			
		||||
visible = false
 | 
			
		||||
Scoreboard = NodePath("../../ScoreboardNode")
 | 
			
		||||
 | 
			
		||||
[node name="Leaderboard" parent="OverlayLayer" node_paths=PackedStringArray("Scoreboard") instance=ExtResource("7_j24m7")]
 | 
			
		||||
process_mode = 3
 | 
			
		||||
visible = false
 | 
			
		||||
Scoreboard = NodePath("../../ScoreboardNode")
 | 
			
		||||
 | 
			
		||||
@@ -46,14 +59,10 @@ Scoreboard = NodePath("../../ScoreboardNode")
 | 
			
		||||
visible = false
 | 
			
		||||
World = NodePath("../../World")
 | 
			
		||||
 | 
			
		||||
[node name="PlayerDiedScreen" parent="OverlayLayer" instance=ExtResource("5_pimes")]
 | 
			
		||||
visible = false
 | 
			
		||||
 | 
			
		||||
[node name="World" type="Node2D" parent="." node_paths=PackedStringArray("Scoreboard")]
 | 
			
		||||
script = ExtResource("3_xwguj")
 | 
			
		||||
Scoreboard = NodePath("../ScoreboardNode")
 | 
			
		||||
PlayerScene = ExtResource("1_vby0g")
 | 
			
		||||
RoundDuration = 10.0
 | 
			
		||||
 | 
			
		||||
[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."]
 | 
			
		||||
root_path = NodePath("../World")
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										50
									
								
								Scenes/UI/GameOverScreen.tscn
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								Scenes/UI/GameOverScreen.tscn
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,50 @@
 | 
			
		||||
[gd_scene load_steps=2 format=3 uid="uid://cnf80yioktsvj"]
 | 
			
		||||
 | 
			
		||||
[ext_resource type="Script" path="res://Scripts/UI/GameOverScreen.cs" id="1_j12ja"]
 | 
			
		||||
 | 
			
		||||
[node name="GameOverScreen" type="Control"]
 | 
			
		||||
layout_mode = 3
 | 
			
		||||
anchors_preset = 15
 | 
			
		||||
anchor_right = 1.0
 | 
			
		||||
anchor_bottom = 1.0
 | 
			
		||||
grow_horizontal = 2
 | 
			
		||||
grow_vertical = 2
 | 
			
		||||
script = ExtResource("1_j12ja")
 | 
			
		||||
 | 
			
		||||
[node name="CenterContainer" type="CenterContainer" parent="."]
 | 
			
		||||
offset_right = 1152.0
 | 
			
		||||
offset_bottom = 648.0
 | 
			
		||||
 | 
			
		||||
[node name="Panel" type="Panel" parent="CenterContainer"]
 | 
			
		||||
custom_minimum_size = Vector2(340, 180)
 | 
			
		||||
layout_mode = 2
 | 
			
		||||
 | 
			
		||||
[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer/Panel"]
 | 
			
		||||
layout_mode = 1
 | 
			
		||||
anchors_preset = 8
 | 
			
		||||
anchor_left = 0.5
 | 
			
		||||
anchor_top = 0.5
 | 
			
		||||
anchor_right = 0.5
 | 
			
		||||
anchor_bottom = 0.5
 | 
			
		||||
offset_left = -129.5
 | 
			
		||||
offset_top = -46.5
 | 
			
		||||
offset_right = 129.5
 | 
			
		||||
offset_bottom = 46.5
 | 
			
		||||
grow_horizontal = 2
 | 
			
		||||
grow_vertical = 2
 | 
			
		||||
 | 
			
		||||
[node name="Title" type="Label" parent="CenterContainer/Panel/VBoxContainer"]
 | 
			
		||||
layout_mode = 2
 | 
			
		||||
theme_override_font_sizes/font_size = 28
 | 
			
		||||
text = "Game over"
 | 
			
		||||
horizontal_alignment = 1
 | 
			
		||||
 | 
			
		||||
[node name="Caption" type="Label" parent="CenterContainer/Panel/VBoxContainer"]
 | 
			
		||||
layout_mode = 2
 | 
			
		||||
text = "You're in the 1st place"
 | 
			
		||||
horizontal_alignment = 1
 | 
			
		||||
 | 
			
		||||
[node name="Caption2" type="Label" parent="CenterContainer/Panel/VBoxContainer"]
 | 
			
		||||
layout_mode = 2
 | 
			
		||||
text = "Hold Tab key to view leaderboard"
 | 
			
		||||
horizontal_alignment = 1
 | 
			
		||||
@@ -13,16 +13,31 @@ layout_mode = 0
 | 
			
		||||
offset_right = 1152.0
 | 
			
		||||
offset_bottom = 648.0
 | 
			
		||||
 | 
			
		||||
[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer"]
 | 
			
		||||
[node name="Panel" type="Panel" parent="CenterContainer"]
 | 
			
		||||
custom_minimum_size = Vector2(340, 120)
 | 
			
		||||
layout_mode = 2
 | 
			
		||||
 | 
			
		||||
[node name="Title" type="Label" parent="CenterContainer/VBoxContainer"]
 | 
			
		||||
[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer/Panel"]
 | 
			
		||||
layout_mode = 1
 | 
			
		||||
anchors_preset = 8
 | 
			
		||||
anchor_left = 0.5
 | 
			
		||||
anchor_top = 0.5
 | 
			
		||||
anchor_right = 0.5
 | 
			
		||||
anchor_bottom = 0.5
 | 
			
		||||
offset_left = -92.0
 | 
			
		||||
offset_top = -33.0
 | 
			
		||||
offset_right = 92.0
 | 
			
		||||
offset_bottom = 33.0
 | 
			
		||||
grow_horizontal = 2
 | 
			
		||||
grow_vertical = 2
 | 
			
		||||
 | 
			
		||||
[node name="Title" type="Label" parent="CenterContainer/Panel/VBoxContainer"]
 | 
			
		||||
layout_mode = 2
 | 
			
		||||
theme_override_font_sizes/font_size = 28
 | 
			
		||||
text = "You died"
 | 
			
		||||
horizontal_alignment = 1
 | 
			
		||||
 | 
			
		||||
[node name="Caption" type="Label" parent="CenterContainer/VBoxContainer"]
 | 
			
		||||
[node name="Caption" type="Label" parent="CenterContainer/Panel/VBoxContainer"]
 | 
			
		||||
layout_mode = 2
 | 
			
		||||
text = "Respawn in Next Round"
 | 
			
		||||
horizontal_alignment = 1
 | 
			
		||||
 
 | 
			
		||||
@@ -81,8 +81,7 @@ public partial class World : Node2D
 | 
			
		||||
	{
 | 
			
		||||
		var player = PlayerScene.Instantiate<Player>();
 | 
			
		||||
		player.PlayerId = id;
 | 
			
		||||
		var position = Vector2.FromAngle(GD.Randf() * 2 * Mathf.Pi);
 | 
			
		||||
		player.Position = new Vector2(position.X * 5f * GD.Randf(), position.Y * 5f * GD.Randf());
 | 
			
		||||
		player.Position = new Vector2(GD.RandRange(-100, 100), GD.RandRange(-100, 100));
 | 
			
		||||
		player.Name = BuildPlayerName(id);
 | 
			
		||||
		player.PlayerDied += (killerId) =>
 | 
			
		||||
		{
 | 
			
		||||
@@ -109,7 +108,7 @@ public partial class World : Node2D
 | 
			
		||||
	{
 | 
			
		||||
		if (RoundCount >= RoundTotalCount)
 | 
			
		||||
		{
 | 
			
		||||
			// TODO End this game
 | 
			
		||||
			Rpc(nameof(EndGame));
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
@@ -129,10 +128,8 @@ public partial class World : Node2D
 | 
			
		||||
		foreach (var child in GetChildren())
 | 
			
		||||
		{
 | 
			
		||||
			if (child is Player { IsCurrentPlayer: true } player)
 | 
			
		||||
			{
 | 
			
		||||
				return player;
 | 
			
		||||
		}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return null;
 | 
			
		||||
	}
 | 
			
		||||
@@ -147,4 +144,12 @@ public partial class World : Node2D
 | 
			
		||||
 | 
			
		||||
		return null;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	[Rpc(MultiplayerApi.RpcMode.AnyPeer, CallLocal = true)]
 | 
			
		||||
	private void EndGame()
 | 
			
		||||
	{
 | 
			
		||||
		GetParent().GetNode<Control>("OverlayLayer/Hud").Hide();
 | 
			
		||||
		GetParent().GetNode<Control>("OverlayLayer/GameOverScreen").Show();
 | 
			
		||||
		GetTree().Paused = true;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -24,7 +24,7 @@ public partial class BootScreen : Control
 | 
			
		||||
		var count = Multiplayer.GetPeers().Length;
 | 
			
		||||
		PlayerCountLabel.Text = $"{(count + 1):00}/{16}";
 | 
			
		||||
 | 
			
		||||
		StartGameButton.Disabled = !Multiplayer.IsServer();
 | 
			
		||||
		StartGameButton.Disabled = !Multiplayer.IsServer() || Multiplayer.GetPeers().Length == 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	[Rpc(MultiplayerApi.RpcMode.AnyPeer, CallLocal = true)]
 | 
			
		||||
@@ -32,7 +32,6 @@ public partial class BootScreen : Control
 | 
			
		||||
	{
 | 
			
		||||
		EmitSignal(SignalName.StartGame);
 | 
			
		||||
		var name = string.IsNullOrEmpty(PlayerNameInput.Text) ? null : PlayerNameInput.Text;
 | 
			
		||||
		// TODO Fix this I don't know why the first round player's name won't fully apply
 | 
			
		||||
		World.Scoreboard.SetName(Multiplayer.GetUniqueId(), name ?? $"Player#{Multiplayer.GetUniqueId()}");
 | 
			
		||||
		World.StartGame(currentPlayerName: name);
 | 
			
		||||
		Hide();
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										29
									
								
								Scripts/UI/GameOverScreen.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								Scripts/UI/GameOverScreen.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using AceField.Scripts.Logic;
 | 
			
		||||
using Godot;
 | 
			
		||||
 | 
			
		||||
namespace AceField.Scripts.UI;
 | 
			
		||||
 | 
			
		||||
public partial class GameOverScreen : Control
 | 
			
		||||
{
 | 
			
		||||
	[Export] public Scoreboard Scoreboard;
 | 
			
		||||
 | 
			
		||||
	public override void _Process(double delta)
 | 
			
		||||
	{
 | 
			
		||||
		if (!Visible) return;
 | 
			
		||||
 | 
			
		||||
		var data = Scoreboard.GetData(Multiplayer.GetUniqueId());
 | 
			
		||||
		if (data == null) return;
 | 
			
		||||
 | 
			
		||||
		var place = 1;
 | 
			
		||||
		var list = Scoreboard.Players.ToList();
 | 
			
		||||
		list.Sort((a, b) => b.Value.Score.CompareTo(a.Value.Score));
 | 
			
		||||
		foreach (var item in list)
 | 
			
		||||
		{
 | 
			
		||||
			if (Multiplayer.GetUniqueId() == item.Key) break;
 | 
			
		||||
			place++;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		GetNode<Label>("CenterContainer/Panel/VBoxContainer/Caption").Text = $"You're in the {place} place";
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -22,7 +22,7 @@ public partial class HUD : Control
 | 
			
		||||
		roundBar.Value = World.RoundProgress * 100;
 | 
			
		||||
 | 
			
		||||
		var roundLabel = GetNode<Label>("BottomBox/HBox/RoundLabel");
 | 
			
		||||
		roundLabel.Text = $"Round {World.RoundCount}";
 | 
			
		||||
		roundLabel.Text = $"Round {World.RoundCount:00}/{World.RoundTotalCount:00}";
 | 
			
		||||
		
 | 
			
		||||
		var player = World.GetCurrentPlayer();
 | 
			
		||||
		if (player == null) return;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,3 +1,4 @@
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using AceField.Scripts.Logic;
 | 
			
		||||
using Godot;
 | 
			
		||||
 | 
			
		||||
@@ -12,6 +13,7 @@ public partial class Leaderboard : Control
 | 
			
		||||
		Visible = Input.IsActionPressed("ui_leaderboard");
 | 
			
		||||
 | 
			
		||||
		if (!Visible) return;
 | 
			
		||||
		if (Scoreboard.Players.Count == 1) return;
 | 
			
		||||
 | 
			
		||||
		if (GetNode<Control>("List").GetChildCount() != Scoreboard.Players.Count)
 | 
			
		||||
		{
 | 
			
		||||
@@ -21,16 +23,17 @@ public partial class Leaderboard : Control
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		var place = 1;
 | 
			
		||||
		foreach (var node in GetNode<Control>("List").GetChildren())
 | 
			
		||||
		var data = Scoreboard.Players.ToList();
 | 
			
		||||
		data.Sort((a, b) => b.Value.Score.CompareTo(a.Value.Score));
 | 
			
		||||
		foreach (var item in data)
 | 
			
		||||
		{
 | 
			
		||||
			if (node is not LeaderboardRecord record) continue;
 | 
			
		||||
			var record = GetNode<Control>("List").GetNode<LeaderboardRecord>($"Record_{place}");
 | 
			
		||||
 | 
			
		||||
			var data = Scoreboard.GetData(record.PlayerId);
 | 
			
		||||
			if (data == null) continue;
 | 
			
		||||
			record!.PlayerId = item.Key;
 | 
			
		||||
 | 
			
		||||
			record.Place = place;
 | 
			
		||||
			record.Score = data.Score;
 | 
			
		||||
			record.PlayerName = data.Name;
 | 
			
		||||
			record.Score = item.Value.Score;
 | 
			
		||||
			record.PlayerName = item.Value.Name;
 | 
			
		||||
 | 
			
		||||
			place++;
 | 
			
		||||
		}
 | 
			
		||||
@@ -56,6 +59,7 @@ public partial class Leaderboard : Control
 | 
			
		||||
			instance.Score = record.Value.Score;
 | 
			
		||||
			instance.PlayerId = record.Key;
 | 
			
		||||
			instance.CustomMinimumSize = new Vector2(0, 80);
 | 
			
		||||
			instance.Name = $"Record_{place}";
 | 
			
		||||
			GetNode("List").AddChild(instance);
 | 
			
		||||
			place++;
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user