✨ Player name
This commit is contained in:
		
							
								
								
									
										8
									
								
								.idea/.idea.CodingLand/.idea/workspace.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										8
									
								
								.idea/.idea.CodingLand/.idea/workspace.xml
									
									
									
										generated
									
									
									
								
							@@ -5,9 +5,15 @@
 | 
				
			|||||||
  </component>
 | 
					  </component>
 | 
				
			||||||
  <component name="ChangeListManager">
 | 
					  <component name="ChangeListManager">
 | 
				
			||||||
    <list default="true" id="c7bd02c7-bbb4-431f-81ca-d2f8b7b09b37" name="Changes" comment="">
 | 
					    <list default="true" id="c7bd02c7-bbb4-431f-81ca-d2f8b7b09b37" name="Changes" comment="">
 | 
				
			||||||
 | 
					      <change afterPath="$PROJECT_DIR$/Scenes/UI/LaunchScreen.tscn" afterDir="false" />
 | 
				
			||||||
      <change beforePath="$PROJECT_DIR$/.idea/.idea.CodingLand/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.CodingLand/.idea/workspace.xml" afterDir="false" />
 | 
					      <change beforePath="$PROJECT_DIR$/.idea/.idea.CodingLand/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.CodingLand/.idea/workspace.xml" afterDir="false" />
 | 
				
			||||||
      <change beforePath="$PROJECT_DIR$/Scenes/Player.tscn" beforeDir="false" afterPath="$PROJECT_DIR$/Scenes/Player.tscn" afterDir="false" />
 | 
					      <change beforePath="$PROJECT_DIR$/Scenes/Player.tscn" beforeDir="false" afterPath="$PROJECT_DIR$/Scenes/Player.tscn" afterDir="false" />
 | 
				
			||||||
 | 
					      <change beforePath="$PROJECT_DIR$/Scenes/Root.tscn" beforeDir="false" afterPath="$PROJECT_DIR$/Scenes/Root.tscn" afterDir="false" />
 | 
				
			||||||
 | 
					      <change beforePath="$PROJECT_DIR$/Scenes/UI/StartScreen.tscn" beforeDir="false" />
 | 
				
			||||||
 | 
					      <change beforePath="$PROJECT_DIR$/Scripts/Launcher.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Scripts/Launcher.cs" afterDir="false" />
 | 
				
			||||||
 | 
					      <change beforePath="$PROJECT_DIR$/Scripts/Logic/World.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Scripts/Logic/World.cs" afterDir="false" />
 | 
				
			||||||
      <change beforePath="$PROJECT_DIR$/Scripts/Player.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Scripts/Player.cs" afterDir="false" />
 | 
					      <change beforePath="$PROJECT_DIR$/Scripts/Player.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Scripts/Player.cs" afterDir="false" />
 | 
				
			||||||
 | 
					      <change beforePath="$PROJECT_DIR$/Scripts/UI/StartScreen.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Scripts/UI/LaunchScreen.cs" afterDir="false" />
 | 
				
			||||||
    </list>
 | 
					    </list>
 | 
				
			||||||
    <option name="SHOW_DIALOG" value="false" />
 | 
					    <option name="SHOW_DIALOG" value="false" />
 | 
				
			||||||
    <option name="HIGHLIGHT_CONFLICTS" value="true" />
 | 
					    <option name="HIGHLIGHT_CONFLICTS" value="true" />
 | 
				
			||||||
@@ -110,7 +116,7 @@
 | 
				
			|||||||
      <workItem from="1722846222698" duration="9239000" />
 | 
					      <workItem from="1722846222698" duration="9239000" />
 | 
				
			||||||
      <workItem from="1722855558149" duration="11578000" />
 | 
					      <workItem from="1722855558149" duration="11578000" />
 | 
				
			||||||
      <workItem from="1723040712804" duration="74000" />
 | 
					      <workItem from="1723040712804" duration="74000" />
 | 
				
			||||||
      <workItem from="1723040934916" duration="9355000" />
 | 
					      <workItem from="1723040934916" duration="11438000" />
 | 
				
			||||||
    </task>
 | 
					    </task>
 | 
				
			||||||
    <task id="LOCAL-00001" summary=":sparkles: Usable multiplayer">
 | 
					    <task id="LOCAL-00001" summary=":sparkles: Usable multiplayer">
 | 
				
			||||||
      <option name="closed" value="true" />
 | 
					      <option name="closed" value="true" />
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,7 +7,7 @@
 | 
				
			|||||||
[ext_resource type="Script" path="res://Scripts/Effects/CameraShake.cs" id="4_fwngj"]
 | 
					[ext_resource type="Script" path="res://Scripts/Effects/CameraShake.cs" id="4_fwngj"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_68yf8"]
 | 
					[sub_resource type="CircleShape2D" id="CircleShape2D_68yf8"]
 | 
				
			||||||
radius = 20.48
 | 
					radius = 25.6
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[sub_resource type="FastNoiseLite" id="FastNoiseLite_cfnx7"]
 | 
					[sub_resource type="FastNoiseLite" id="FastNoiseLite_cfnx7"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -21,6 +21,27 @@ properties/1/replication_mode = 1
 | 
				
			|||||||
properties/2/path = NodePath("RotationCentre:rotation")
 | 
					properties/2/path = NodePath("RotationCentre:rotation")
 | 
				
			||||||
properties/2/spawn = true
 | 
					properties/2/spawn = true
 | 
				
			||||||
properties/2/replication_mode = 1
 | 
					properties/2/replication_mode = 1
 | 
				
			||||||
 | 
					properties/3/path = NodePath(".:PlayerName")
 | 
				
			||||||
 | 
					properties/3/spawn = true
 | 
				
			||||||
 | 
					properties/3/replication_mode = 1
 | 
				
			||||||
 | 
					properties/4/path = NodePath(".:Health")
 | 
				
			||||||
 | 
					properties/4/spawn = true
 | 
				
			||||||
 | 
					properties/4/replication_mode = 1
 | 
				
			||||||
 | 
					properties/5/path = NodePath(".:MaxHealth")
 | 
				
			||||||
 | 
					properties/5/spawn = true
 | 
				
			||||||
 | 
					properties/5/replication_mode = 1
 | 
				
			||||||
 | 
					properties/6/path = NodePath(".:ActionPoints")
 | 
				
			||||||
 | 
					properties/6/spawn = true
 | 
				
			||||||
 | 
					properties/6/replication_mode = 1
 | 
				
			||||||
 | 
					properties/7/path = NodePath(".:MaxActionPoints")
 | 
				
			||||||
 | 
					properties/7/spawn = true
 | 
				
			||||||
 | 
					properties/7/replication_mode = 1
 | 
				
			||||||
 | 
					properties/8/path = NodePath(".:AmmoAmount")
 | 
				
			||||||
 | 
					properties/8/spawn = true
 | 
				
			||||||
 | 
					properties/8/replication_mode = 1
 | 
				
			||||||
 | 
					properties/9/path = NodePath(".:MaxAmmoAmount")
 | 
				
			||||||
 | 
					properties/9/spawn = true
 | 
				
			||||||
 | 
					properties/9/replication_mode = 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_hojn2"]
 | 
					[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_hojn2"]
 | 
				
			||||||
properties/0/path = NodePath("InputSynchronizer:IsDashing")
 | 
					properties/0/path = NodePath("InputSynchronizer:IsDashing")
 | 
				
			||||||
@@ -36,22 +57,22 @@ PlayerCamera = NodePath("Camera2D")
 | 
				
			|||||||
PlayerInput = NodePath("InputSynchronizer")
 | 
					PlayerInput = NodePath("InputSynchronizer")
 | 
				
			||||||
BulletScene = ExtResource("2_nmop0")
 | 
					BulletScene = ExtResource("2_nmop0")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[node name="HUD" type="VBoxContainer" parent="."]
 | 
					[node name="Overlay" type="VBoxContainer" parent="."]
 | 
				
			||||||
offset_left = -90.0
 | 
					offset_left = -90.0
 | 
				
			||||||
offset_top = -80.0
 | 
					offset_top = -86.0
 | 
				
			||||||
offset_right = 90.0
 | 
					offset_right = 90.0
 | 
				
			||||||
offset_bottom = -20.0
 | 
					offset_bottom = -26.0
 | 
				
			||||||
theme_override_constants/separation = 4
 | 
					theme_override_constants/separation = 4
 | 
				
			||||||
alignment = 1
 | 
					alignment = 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[node name="NameTag" type="Label" parent="HUD"]
 | 
					[node name="NameTag" type="Label" parent="Overlay"]
 | 
				
			||||||
layout_mode = 2
 | 
					layout_mode = 2
 | 
				
			||||||
text = "Player"
 | 
					text = "Player"
 | 
				
			||||||
horizontal_alignment = 1
 | 
					horizontal_alignment = 1
 | 
				
			||||||
vertical_alignment = 1
 | 
					vertical_alignment = 1
 | 
				
			||||||
clip_text = true
 | 
					clip_text = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[node name="HealthBar" type="ProgressBar" parent="HUD"]
 | 
					[node name="HealthBar" type="ProgressBar" parent="Overlay"]
 | 
				
			||||||
custom_minimum_size = Vector2(2.08165e-12, 8)
 | 
					custom_minimum_size = Vector2(2.08165e-12, 8)
 | 
				
			||||||
layout_mode = 2
 | 
					layout_mode = 2
 | 
				
			||||||
rounded = true
 | 
					rounded = true
 | 
				
			||||||
@@ -63,7 +84,7 @@ show_percentage = false
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
[node name="Sprite2D" type="Sprite2D" parent="RotationCentre"]
 | 
					[node name="Sprite2D" type="Sprite2D" parent="RotationCentre"]
 | 
				
			||||||
position = Vector2(2.08165e-12, 2.08165e-12)
 | 
					position = Vector2(2.08165e-12, 2.08165e-12)
 | 
				
			||||||
scale = Vector2(0.04, 0.04)
 | 
					scale = Vector2(0.05, 0.05)
 | 
				
			||||||
texture = ExtResource("1_cqpqa")
 | 
					texture = ExtResource("1_cqpqa")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[node name="Muzzle" type="Marker2D" parent="RotationCentre"]
 | 
					[node name="Muzzle" type="Marker2D" parent="RotationCentre"]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,13 +1,13 @@
 | 
				
			|||||||
[gd_scene load_steps=5 format=3 uid="uid://bjhmjrldq4lkt"]
 | 
					[gd_scene load_steps=5 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://b3gx0bl43lku3" path="res://Scenes/Player.tscn" id="1_vby0g"]
 | 
				
			||||||
[ext_resource type="PackedScene" uid="uid://bvll23f5ibd4v" path="res://Scenes/UI/StartScreen.tscn" id="2_7o53i"]
 | 
					[ext_resource type="PackedScene" uid="uid://bvll23f5ibd4v" path="res://Scenes/UI/LaunchScreen.tscn" id="2_7o53i"]
 | 
				
			||||||
[ext_resource type="Script" path="res://Scripts/Launcher.cs" id="2_u5cms"]
 | 
					[ext_resource type="Script" path="res://Scripts/Launcher.cs" id="2_u5cms"]
 | 
				
			||||||
[ext_resource type="Script" path="res://Scripts/Logic/World.cs" id="3_xwguj"]
 | 
					[ext_resource type="Script" path="res://Scripts/Logic/World.cs" id="3_xwguj"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[node name="Node" type="Node"]
 | 
					[node name="Node" type="Node"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[node name="StartScreen" parent="." node_paths=PackedStringArray("Launcher") instance=ExtResource("2_7o53i")]
 | 
					[node name="LaunchScreen" parent="." node_paths=PackedStringArray("Launcher") instance=ExtResource("2_7o53i")]
 | 
				
			||||||
Launcher = NodePath("../LauncherNode")
 | 
					Launcher = NodePath("../LauncherNode")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[node name="LauncherNode" type="Node" parent="." node_paths=PackedStringArray("World")]
 | 
					[node name="LauncherNode" type="Node" parent="." node_paths=PackedStringArray("World")]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,8 +1,8 @@
 | 
				
			|||||||
[gd_scene load_steps=2 format=3 uid="uid://bvll23f5ibd4v"]
 | 
					[gd_scene load_steps=2 format=3 uid="uid://bvll23f5ibd4v"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[ext_resource type="Script" path="res://Scripts/UI/StartScreen.cs" id="1_f8by8"]
 | 
					[ext_resource type="Script" path="res://Scripts/UI/LaunchScreen.cs" id="1_hiet3"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[node name="StartScreen" type="Control" node_paths=PackedStringArray("ServerPortInput", "ServerAddrInput", "StartAsSingleButton", "StartAsServerButton", "StartAsClientButton")]
 | 
					[node name="LaunchScreen" type="Control" node_paths=PackedStringArray("PlayerNameInput", "ServerPortInput", "ServerAddrInput", "StartAsServerButton", "StartAsClientButton")]
 | 
				
			||||||
process_mode = 3
 | 
					process_mode = 3
 | 
				
			||||||
layout_mode = 3
 | 
					layout_mode = 3
 | 
				
			||||||
anchors_preset = 15
 | 
					anchors_preset = 15
 | 
				
			||||||
@@ -10,10 +10,10 @@ anchor_right = 1.0
 | 
				
			|||||||
anchor_bottom = 1.0
 | 
					anchor_bottom = 1.0
 | 
				
			||||||
grow_horizontal = 2
 | 
					grow_horizontal = 2
 | 
				
			||||||
grow_vertical = 2
 | 
					grow_vertical = 2
 | 
				
			||||||
script = ExtResource("1_f8by8")
 | 
					script = ExtResource("1_hiet3")
 | 
				
			||||||
 | 
					PlayerNameInput = NodePath("CenterContainer/VBoxContainer/NameEdit")
 | 
				
			||||||
ServerPortInput = NodePath("CenterContainer/VBoxContainer/PortEdit")
 | 
					ServerPortInput = NodePath("CenterContainer/VBoxContainer/PortEdit")
 | 
				
			||||||
ServerAddrInput = NodePath("CenterContainer/VBoxContainer/AddrEdit")
 | 
					ServerAddrInput = NodePath("CenterContainer/VBoxContainer/AddrEdit")
 | 
				
			||||||
StartAsSingleButton = NodePath("CenterContainer/VBoxContainer/PlayAloneButton")
 | 
					 | 
				
			||||||
StartAsServerButton = NodePath("CenterContainer/VBoxContainer/MultiplayerActions/HostButton")
 | 
					StartAsServerButton = NodePath("CenterContainer/VBoxContainer/MultiplayerActions/HostButton")
 | 
				
			||||||
StartAsClientButton = NodePath("CenterContainer/VBoxContainer/MultiplayerActions/ConnectButton")
 | 
					StartAsClientButton = NodePath("CenterContainer/VBoxContainer/MultiplayerActions/ConnectButton")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -25,18 +25,13 @@ offset_bottom = 648.0
 | 
				
			|||||||
[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer"]
 | 
					[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer"]
 | 
				
			||||||
layout_mode = 2
 | 
					layout_mode = 2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[node name="SinglePlayerTitle" type="Label" parent="CenterContainer/VBoxContainer"]
 | 
					[node name="NameEdit" type="LineEdit" parent="CenterContainer/VBoxContainer"]
 | 
				
			||||||
layout_mode = 2
 | 
					layout_mode = 2
 | 
				
			||||||
text = "Singleplayer"
 | 
					placeholder_text = "Player name"
 | 
				
			||||||
horizontal_alignment = 1
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
[node name="PlayAloneButton" type="Button" parent="CenterContainer/VBoxContainer"]
 | 
					 | 
				
			||||||
layout_mode = 2
 | 
					 | 
				
			||||||
text = "Play Alone"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
[node name="MultiplayerTitle" type="Label" parent="CenterContainer/VBoxContainer"]
 | 
					[node name="MultiplayerTitle" type="Label" parent="CenterContainer/VBoxContainer"]
 | 
				
			||||||
layout_mode = 2
 | 
					layout_mode = 2
 | 
				
			||||||
text = "Mutiplayer"
 | 
					text = "Play the Game"
 | 
				
			||||||
horizontal_alignment = 1
 | 
					horizontal_alignment = 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[node name="PortEdit" type="LineEdit" parent="CenterContainer/VBoxContainer"]
 | 
					[node name="PortEdit" type="LineEdit" parent="CenterContainer/VBoxContainer"]
 | 
				
			||||||
@@ -30,13 +30,13 @@ public partial class Launcher : Node
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public void StartAsSingle()
 | 
						public void StartAsSingle(string currentPlayerName = null)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		GameUnfreeze();
 | 
							GameUnfreeze();
 | 
				
			||||||
		World.StartGame();
 | 
							World.StartGame(currentPlayerName);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public bool StartAsServer(int port)
 | 
						public bool StartAsServer(int port, string currentPlayerName = null)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		var peer = new ENetMultiplayerPeer();
 | 
							var peer = new ENetMultiplayerPeer();
 | 
				
			||||||
		peer.CreateServer(port);
 | 
							peer.CreateServer(port);
 | 
				
			||||||
@@ -51,12 +51,12 @@ public partial class Launcher : Node
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		Multiplayer.MultiplayerPeer = peer;
 | 
							Multiplayer.MultiplayerPeer = peer;
 | 
				
			||||||
		GameUnfreeze();
 | 
							GameUnfreeze();
 | 
				
			||||||
		World.StartGame();
 | 
							World.StartGame(currentPlayerName);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return true;
 | 
							return true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public bool StartAsClient(string addr, int port)
 | 
						public bool StartAsClient(string addr, int port, string currentPlayerName = null)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if (string.IsNullOrEmpty(addr)) return false;
 | 
							if (string.IsNullOrEmpty(addr)) return false;
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
@@ -74,7 +74,7 @@ public partial class Launcher : Node
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
		Multiplayer.MultiplayerPeer = peer;
 | 
							Multiplayer.MultiplayerPeer = peer;
 | 
				
			||||||
		GameUnfreeze();
 | 
							GameUnfreeze();
 | 
				
			||||||
		World.StartGame();
 | 
							World.StartGame(currentPlayerName);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		return true;
 | 
							return true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,7 +6,7 @@ public partial class World : Node2D
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    [Export] public PackedScene PlayerScene;
 | 
					    [Export] public PackedScene PlayerScene;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void StartGame()
 | 
					    public void StartGame(string currentPlayerName = null)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (!Multiplayer.IsServer())
 | 
					        if (!Multiplayer.IsServer())
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
@@ -21,7 +21,7 @@ public partial class World : Node2D
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // Add this client as a player if client isn't a dedicated server
 | 
					        // Add this client as a player if client isn't a dedicated server
 | 
				
			||||||
        if (!OS.HasFeature("dedicated_server"))
 | 
					        if (!OS.HasFeature("dedicated_server"))
 | 
				
			||||||
            AddPlayer(1);
 | 
					            AddPlayer(1, currentPlayerName);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public override void _ExitTree()
 | 
					    public override void _ExitTree()
 | 
				
			||||||
@@ -44,13 +44,14 @@ public partial class World : Node2D
 | 
				
			|||||||
    private void RemovePlayer_Adaptor(long id)
 | 
					    private void RemovePlayer_Adaptor(long id)
 | 
				
			||||||
        => RemovePlayer((int)id);
 | 
					        => RemovePlayer((int)id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void AddPlayer(int id)
 | 
					    private void AddPlayer(int id, string name = null)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        var player = PlayerScene.Instantiate<AceField.Scripts.Player>();
 | 
					        var player = PlayerScene.Instantiate<Player>();
 | 
				
			||||||
        player.SetPlayerId(id);
 | 
					        player.PlayerId = id;
 | 
				
			||||||
        var position = Vector2.FromAngle(GD.Randf() * 2 * Mathf.Pi);
 | 
					        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(position.X * 5f * GD.Randf(), position.Y * 5f * GD.Randf());
 | 
				
			||||||
        player.Name = BuildPlayerName(id);
 | 
					        player.Name = BuildPlayerName(id);
 | 
				
			||||||
 | 
					        player.PlayerName = name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        AddChild(player, true);
 | 
					        AddChild(player, true);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -63,4 +64,17 @@ public partial class World : Node2D
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        GetNode(name).QueueFree();
 | 
					        GetNode(name).QueueFree();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public Player GetCurrentPlayer()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        foreach(var child in GetChildren())
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if (child is Player { IsCurrentPlayer: true } player)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                return player;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -6,132 +6,130 @@ namespace AceField.Scripts;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
public partial class Player : CharacterBody2D
 | 
					public partial class Player : CharacterBody2D
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    private int _currentPlayerId = 1;
 | 
						private int _currentPlayerId = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [Export] public float MaxSpeed = 400f;
 | 
						[Export] public float MaxSpeed = 400f;
 | 
				
			||||||
    [Export] public float Acceleration = 500f;
 | 
						[Export] public float Acceleration = 500f;
 | 
				
			||||||
    [Export] public float Deceleration = 500f;
 | 
						[Export] public float Deceleration = 500f;
 | 
				
			||||||
    [Export] public float RotationSpeed = 5f;
 | 
						[Export] public float RotationSpeed = 5f;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [Export] public int Reach = 5;
 | 
						[Export] public int Reach = 5;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [Export] public double Health = 100;
 | 
						[Export] public double Health = 100;
 | 
				
			||||||
    [Export] public double MaxHealth = 100;
 | 
						[Export] public double MaxHealth = 100;
 | 
				
			||||||
    [Export] public double ActionPoints = 20;
 | 
						[Export] public double ActionPoints = 20;
 | 
				
			||||||
    [Export] public double MaxActionPoints = 20;
 | 
						[Export] public double MaxActionPoints = 20;
 | 
				
			||||||
 | 
						[Export] public double AmmoAmount = 30;
 | 
				
			||||||
 | 
						[Export] public double MaxAmmoAmount = 30;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [Export] public Camera2D PlayerCamera;
 | 
						[Export] public Camera2D PlayerCamera;
 | 
				
			||||||
    [Export] public PlayerInput PlayerInput;
 | 
						[Export] public PlayerInput PlayerInput;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [Export] public float PlayerDashAcceleration = 2f;
 | 
						[Export] public float PlayerDashAcceleration = 2f;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [Export] public PackedScene BulletScene;
 | 
						[Export] public PackedScene BulletScene;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [Export] public string PlayerName;
 | 
						[Export] public string PlayerName;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [Export]
 | 
						[Export]
 | 
				
			||||||
    public int PlayerId
 | 
						public int PlayerId
 | 
				
			||||||
    {
 | 
						{
 | 
				
			||||||
        get => _currentPlayerId;
 | 
							get => _currentPlayerId;
 | 
				
			||||||
        set
 | 
							set
 | 
				
			||||||
        {
 | 
							{
 | 
				
			||||||
            _currentPlayerId = value;
 | 
								_currentPlayerId = value;
 | 
				
			||||||
            PlayerInput.SetMultiplayerAuthority(value);
 | 
								PlayerInput.SetMultiplayerAuthority(value);
 | 
				
			||||||
        }
 | 
							}
 | 
				
			||||||
    }
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void SetPlayerId(int id)
 | 
						public bool IsCurrentPlayer => _currentPlayerId == Multiplayer.GetUniqueId();
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        PlayerId = id;
 | 
					 | 
				
			||||||
        PlayerInput.SetMultiplayerAuthority(id);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public override void _Ready()
 | 
						public override void _Ready()
 | 
				
			||||||
    {
 | 
						{
 | 
				
			||||||
        Health = MaxHealth;
 | 
							Health = MaxHealth;
 | 
				
			||||||
        ActionPoints = MaxActionPoints;
 | 
							ActionPoints = MaxActionPoints;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (PlayerId == Multiplayer.GetUniqueId())
 | 
							if (PlayerId == Multiplayer.GetUniqueId())
 | 
				
			||||||
            PlayerCamera.Enabled = true;
 | 
								PlayerCamera.Enabled = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        PlayerName = $"Player#{PlayerId}"; // TODO Remove mock data
 | 
							PlayerName ??= $"Player#{PlayerId}"; 
 | 
				
			||||||
        GetNode<Label>("HUD/NameTag").Text = PlayerName;
 | 
							GetNode<Label>("Overlay/NameTag").Text = PlayerName;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        GetNode<ProgressBar>("HUD/HealthBar").Value = Health / MaxHealth * 100;
 | 
							GetNode<ProgressBar>("Overlay/HealthBar").Value = Health / MaxHealth * 100;
 | 
				
			||||||
    }
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public override void _Process(double delta)
 | 
						public override void _Process(double delta)
 | 
				
			||||||
    {
 | 
						{
 | 
				
			||||||
        if (PlayerInput.IsShooting)
 | 
							if (PlayerInput.IsShooting)
 | 
				
			||||||
        {
 | 
							{
 | 
				
			||||||
            Rpc(nameof(Shoot));
 | 
								Rpc(nameof(Shoot));
 | 
				
			||||||
            PlayerInput.IsShooting = false;
 | 
								PlayerInput.IsShooting = false;
 | 
				
			||||||
        }
 | 
							}
 | 
				
			||||||
    }
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public override void _PhysicsProcess(double delta)
 | 
						public override void _PhysicsProcess(double delta)
 | 
				
			||||||
    {
 | 
						{
 | 
				
			||||||
        var input = PlayerInput.MovementDirection;
 | 
							var input = PlayerInput.MovementDirection;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (input != Vector2.Zero)
 | 
							if (input != Vector2.Zero)
 | 
				
			||||||
        {
 | 
							{
 | 
				
			||||||
            input = input.Normalized();
 | 
								input = input.Normalized();
 | 
				
			||||||
            Velocity = Velocity.MoveToward(input * MaxSpeed, Acceleration * (float)delta);
 | 
								Velocity = Velocity.MoveToward(input * MaxSpeed, Acceleration * (float)delta);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var centre = GetNode<Node2D>("RotationCentre");
 | 
								var centre = GetNode<Node2D>("RotationCentre");
 | 
				
			||||||
            var finalRotation = input.Angle() + Mathf.Pi / 2;
 | 
								var finalRotation = input.Angle() + Mathf.Pi / 2;
 | 
				
			||||||
            centre.Rotation = Mathf.LerpAngle(centre.Rotation, finalRotation, RotationSpeed * (float)delta);
 | 
								centre.Rotation = Mathf.LerpAngle(centre.Rotation, finalRotation, RotationSpeed * (float)delta);
 | 
				
			||||||
        }
 | 
							}
 | 
				
			||||||
        else
 | 
							else
 | 
				
			||||||
        {
 | 
							{
 | 
				
			||||||
            Velocity = Velocity.MoveToward(Vector2.Zero, Deceleration * (float)delta);
 | 
								Velocity = Velocity.MoveToward(Vector2.Zero, Deceleration * (float)delta);
 | 
				
			||||||
        }
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        var dashCountdown = GetNode<Timer>("DashCountdown");
 | 
							var dashCountdown = GetNode<Timer>("DashCountdown");
 | 
				
			||||||
        if (PlayerInput.IsDashing && dashCountdown.IsStopped())
 | 
							if (PlayerInput.IsDashing && dashCountdown.IsStopped())
 | 
				
			||||||
        {
 | 
							{
 | 
				
			||||||
            PlayerInput.IsDashing = false;
 | 
								PlayerInput.IsDashing = false;
 | 
				
			||||||
            Velocity *= PlayerDashAcceleration;
 | 
								Velocity *= PlayerDashAcceleration;
 | 
				
			||||||
            dashCountdown.Start();
 | 
								dashCountdown.Start();
 | 
				
			||||||
        }
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Position += Velocity * (float)delta;
 | 
							Position += Velocity * (float)delta;
 | 
				
			||||||
        MoveAndSlide();
 | 
							MoveAndSlide();
 | 
				
			||||||
    }
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void TakeDamage(double damage)
 | 
						public void TakeDamage(double damage)
 | 
				
			||||||
    {
 | 
						{
 | 
				
			||||||
        Rpc(nameof(GotDamage), damage);
 | 
							Rpc(nameof(GotDamage), damage);
 | 
				
			||||||
    }
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [Rpc(MultiplayerApi.RpcMode.AnyPeer, CallLocal = true)]
 | 
						[Rpc(MultiplayerApi.RpcMode.AnyPeer, CallLocal = true)]
 | 
				
			||||||
    private void GotDamage(double damage)
 | 
						private void GotDamage(double damage)
 | 
				
			||||||
    {
 | 
						{
 | 
				
			||||||
        var protection = GetNode<Timer>("ProtectionCountdown");
 | 
							var protection = GetNode<Timer>("ProtectionCountdown");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (protection.IsStopped())
 | 
							if (protection.IsStopped())
 | 
				
			||||||
        {
 | 
							{
 | 
				
			||||||
            Health -= damage;
 | 
								Health -= damage;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var tween = CreateTween();
 | 
								var tween = CreateTween();
 | 
				
			||||||
            var bar = GetNode<ProgressBar>("HUD/HealthBar");
 | 
								var bar = GetNode<ProgressBar>("Overlay/HealthBar");
 | 
				
			||||||
            tween.TweenProperty(bar, "value", Health / MaxHealth * 100, 0.3);
 | 
								tween.TweenProperty(bar, "value", Health / MaxHealth * 100, 0.3);
 | 
				
			||||||
            
 | 
					 | 
				
			||||||
            protection.Start();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        var shakableCamera = GetNode<CameraShake>("Camera2D");
 | 
								protection.Start();
 | 
				
			||||||
        shakableCamera.AddTrauma(0.5f);
 | 
							}
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [Rpc(MultiplayerApi.RpcMode.AnyPeer, CallLocal = true)]
 | 
							var shakableCamera = GetNode<CameraShake>("Camera2D");
 | 
				
			||||||
    private void Shoot()
 | 
							shakableCamera.AddTrauma(0.5f);
 | 
				
			||||||
    {
 | 
						}
 | 
				
			||||||
        var marker = GetNode<Marker2D>("RotationCentre/Muzzle");
 | 
					 | 
				
			||||||
        var projectile = BulletScene.Instantiate<Bullet>();
 | 
					 | 
				
			||||||
        projectile.Transform = marker.GlobalTransform;
 | 
					 | 
				
			||||||
        projectile.PlayerId = PlayerId;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        GetParent().AddChild(projectile);
 | 
						[Rpc(MultiplayerApi.RpcMode.AnyPeer, CallLocal = true)]
 | 
				
			||||||
    }
 | 
						private void Shoot()
 | 
				
			||||||
}
 | 
						{
 | 
				
			||||||
 | 
							var marker = GetNode<Marker2D>("RotationCentre/Muzzle");
 | 
				
			||||||
 | 
							var projectile = BulletScene.Instantiate<Bullet>();
 | 
				
			||||||
 | 
							projectile.Transform = marker.GlobalTransform;
 | 
				
			||||||
 | 
							projectile.PlayerId = PlayerId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							GetParent().AddChild(projectile);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,16 +2,16 @@ using Godot;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace AceField.Scripts.UI;
 | 
					namespace AceField.Scripts.UI;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public partial class StartScreen : Control
 | 
					public partial class LaunchScreen : Control
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	[Export] public int DefaultServerPort = 4343;
 | 
						[Export] public int DefaultServerPort = 4343;
 | 
				
			||||||
	[Export] public string DefaultServerAddr = "127.0.0.1";
 | 
						[Export] public string DefaultServerAddr = "127.0.0.1";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	[Export] public Launcher Launcher;
 | 
						[Export] public Launcher Launcher;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						[Export] public LineEdit PlayerNameInput;
 | 
				
			||||||
	[Export] public LineEdit ServerPortInput;
 | 
						[Export] public LineEdit ServerPortInput;
 | 
				
			||||||
	[Export] public LineEdit ServerAddrInput;
 | 
						[Export] public LineEdit ServerAddrInput;
 | 
				
			||||||
	[Export] public Button StartAsSingleButton;
 | 
					 | 
				
			||||||
	[Export] public Button StartAsServerButton;
 | 
						[Export] public Button StartAsServerButton;
 | 
				
			||||||
	[Export] public Button StartAsClientButton;
 | 
						[Export] public Button StartAsClientButton;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -42,11 +42,6 @@ public partial class StartScreen : Control
 | 
				
			|||||||
		ServerPortInput.Text = DefaultServerPort.ToString();
 | 
							ServerPortInput.Text = DefaultServerPort.ToString();
 | 
				
			||||||
		ServerAddrInput.Text = DefaultServerAddr;
 | 
							ServerAddrInput.Text = DefaultServerAddr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		StartAsSingleButton.Pressed += () =>
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			Launcher.StartAsSingle();
 | 
					 | 
				
			||||||
			Hide();
 | 
					 | 
				
			||||||
		};
 | 
					 | 
				
			||||||
		StartAsServerButton.Pressed += () =>
 | 
							StartAsServerButton.Pressed += () =>
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			if (!DoValidation())
 | 
								if (!DoValidation())
 | 
				
			||||||
@@ -56,8 +51,9 @@ public partial class StartScreen : Control
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			var port = ServerPortInput.Text;
 | 
								var port = ServerPortInput.Text;
 | 
				
			||||||
			var result = Launcher.StartAsServer(int.Parse(port));
 | 
								var name = string.IsNullOrEmpty(PlayerNameInput.Text) ? null : PlayerNameInput.Text;
 | 
				
			||||||
			
 | 
								var result = Launcher.StartAsServer(int.Parse(port), currentPlayerName: name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (result)
 | 
								if (result)
 | 
				
			||||||
				Hide();
 | 
									Hide();
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
@@ -71,7 +67,8 @@ public partial class StartScreen : Control
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			var addr = ServerAddrInput.Text;
 | 
								var addr = ServerAddrInput.Text;
 | 
				
			||||||
			var port = ServerPortInput.Text;
 | 
								var port = ServerPortInput.Text;
 | 
				
			||||||
			var result = Launcher.StartAsClient(addr, int.Parse(port));
 | 
								var name = string.IsNullOrEmpty(PlayerNameInput.Text) ? null : PlayerNameInput.Text;
 | 
				
			||||||
 | 
								var result = Launcher.StartAsClient(addr, int.Parse(port), currentPlayerName: name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (result)
 | 
								if (result)
 | 
				
			||||||
				Hide();
 | 
									Hide();
 | 
				
			||||||
		Reference in New Issue
	
	Block a user