✨ Name & Health bar
This commit is contained in:
		
							
								
								
									
										10
									
								
								.idea/.idea.CodingLand/.idea/workspace.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										10
									
								
								.idea/.idea.CodingLand/.idea/workspace.xml
									
									
									
										generated
									
									
									
								
							@@ -5,16 +5,10 @@
 | 
			
		||||
  </component>
 | 
			
		||||
  <component name="ChangeListManager">
 | 
			
		||||
    <list default="true" id="c7bd02c7-bbb4-431f-81ca-d2f8b7b09b37" name="Changes" comment="">
 | 
			
		||||
      <change afterPath="$PROJECT_DIR$/Scenes/Bullet.tscn" afterDir="false" />
 | 
			
		||||
      <change afterPath="$PROJECT_DIR$/Scripts/Bullet.cs" afterDir="false" />
 | 
			
		||||
      <change afterPath="$PROJECT_DIR$/Scripts/Effects/CameraShake.cs" afterDir="false" />
 | 
			
		||||
      <change afterPath="$PROJECT_DIR$/Sprites/Projectiles.png" afterDir="false" />
 | 
			
		||||
      <change afterPath="$PROJECT_DIR$/Sprites/Projectiles.png.import" 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$/Scripts/Logic/PlayerInput.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Scripts/Logic/PlayerInput.cs" afterDir="false" />
 | 
			
		||||
      <change beforePath="$PROJECT_DIR$/Scripts/Effects/CameraShake.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Scripts/Effects/CameraShake.cs" afterDir="false" />
 | 
			
		||||
      <change beforePath="$PROJECT_DIR$/Scripts/Player.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Scripts/Player.cs" afterDir="false" />
 | 
			
		||||
      <change beforePath="$PROJECT_DIR$/project.godot" beforeDir="false" afterPath="$PROJECT_DIR$/project.godot" afterDir="false" />
 | 
			
		||||
    </list>
 | 
			
		||||
    <option name="SHOW_DIALOG" value="false" />
 | 
			
		||||
    <option name="HIGHLIGHT_CONFLICTS" value="true" />
 | 
			
		||||
@@ -116,7 +110,7 @@
 | 
			
		||||
      <workItem from="1722846222698" duration="9239000" />
 | 
			
		||||
      <workItem from="1722855558149" duration="11578000" />
 | 
			
		||||
      <workItem from="1723040712804" duration="74000" />
 | 
			
		||||
      <workItem from="1723040934916" duration="6034000" />
 | 
			
		||||
      <workItem from="1723040934916" duration="7673000" />
 | 
			
		||||
    </task>
 | 
			
		||||
    <task id="LOCAL-00001" summary=":sparkles: Usable multiplayer">
 | 
			
		||||
      <option name="closed" value="true" />
 | 
			
		||||
 
 | 
			
		||||
@@ -33,11 +33,38 @@ PlayerCamera = NodePath("Camera2D")
 | 
			
		||||
PlayerInput = NodePath("InputSynchronizer")
 | 
			
		||||
BulletScene = ExtResource("2_nmop0")
 | 
			
		||||
 | 
			
		||||
[node name="Sprite2D" type="Sprite2D" parent="."]
 | 
			
		||||
[node name="HUD" type="VBoxContainer" parent="."]
 | 
			
		||||
offset_left = -70.0
 | 
			
		||||
offset_top = -80.0
 | 
			
		||||
offset_right = 70.0
 | 
			
		||||
offset_bottom = -20.0
 | 
			
		||||
theme_override_constants/separation = 6
 | 
			
		||||
alignment = 1
 | 
			
		||||
 | 
			
		||||
[node name="NameTag" type="Label" parent="HUD"]
 | 
			
		||||
layout_mode = 2
 | 
			
		||||
text = "Player"
 | 
			
		||||
horizontal_alignment = 1
 | 
			
		||||
vertical_alignment = 1
 | 
			
		||||
clip_text = true
 | 
			
		||||
 | 
			
		||||
[node name="HealthBar" type="ProgressBar" parent="HUD"]
 | 
			
		||||
layout_mode = 2
 | 
			
		||||
rounded = true
 | 
			
		||||
allow_greater = true
 | 
			
		||||
allow_lesser = true
 | 
			
		||||
show_percentage = false
 | 
			
		||||
 | 
			
		||||
[node name="RotationCentre" type="Node2D" parent="."]
 | 
			
		||||
 | 
			
		||||
[node name="Sprite2D" type="Sprite2D" parent="RotationCentre"]
 | 
			
		||||
position = Vector2(2.08165e-12, 2.08165e-12)
 | 
			
		||||
scale = Vector2(0.04, 0.04)
 | 
			
		||||
texture = ExtResource("1_cqpqa")
 | 
			
		||||
 | 
			
		||||
[node name="Muzzle" type="Marker2D" parent="RotationCentre"]
 | 
			
		||||
position = Vector2(2.08165e-12, -20)
 | 
			
		||||
 | 
			
		||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
 | 
			
		||||
shape = SubResource("CircleShape2D_68yf8")
 | 
			
		||||
 | 
			
		||||
@@ -49,9 +76,6 @@ rotation_smoothing_enabled = true
 | 
			
		||||
script = ExtResource("4_fwngj")
 | 
			
		||||
Noise = SubResource("FastNoiseLite_cfnx7")
 | 
			
		||||
 | 
			
		||||
[node name="Muzzle" type="Marker2D" parent="."]
 | 
			
		||||
position = Vector2(2.08165e-12, -20)
 | 
			
		||||
 | 
			
		||||
[node name="DashCountdown" type="Timer" parent="."]
 | 
			
		||||
one_shot = true
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -50,9 +50,4 @@ public partial class CameraShake : Camera2D
 | 
			
		||||
    {
 | 
			
		||||
        _trauma = Mathf.Min(_trauma + amount, 1.0f);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public void SetTrauma(float amount)
 | 
			
		||||
    {
 | 
			
		||||
        _trauma = Mathf.Min(amount, 1.0f);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -27,6 +27,8 @@ public partial class Player : CharacterBody2D
 | 
			
		||||
 | 
			
		||||
    [Export] public PackedScene BulletScene;
 | 
			
		||||
 | 
			
		||||
    [Export] public string PlayerName;
 | 
			
		||||
 | 
			
		||||
    [Export]
 | 
			
		||||
    public int PlayerId
 | 
			
		||||
    {
 | 
			
		||||
@@ -51,6 +53,11 @@ public partial class Player : CharacterBody2D
 | 
			
		||||
 | 
			
		||||
        if (PlayerId == Multiplayer.GetUniqueId())
 | 
			
		||||
            PlayerCamera.Enabled = true;
 | 
			
		||||
 | 
			
		||||
        PlayerName = $"Player#{PlayerId}"; // TODO Remove mock data
 | 
			
		||||
        GetNode<Label>("HUD/NameTag").Text = PlayerName;
 | 
			
		||||
 | 
			
		||||
        GetNode<ProgressBar>("HUD/HealthBar").Value = Health / MaxHealth * 100;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public override void _Process(double delta)
 | 
			
		||||
@@ -71,8 +78,9 @@ public partial class Player : CharacterBody2D
 | 
			
		||||
            input = input.Normalized();
 | 
			
		||||
            Velocity = Velocity.MoveToward(input * MaxSpeed, Acceleration * (float)delta);
 | 
			
		||||
 | 
			
		||||
            var centre = GetNode<Node2D>("RotationCentre");
 | 
			
		||||
            var finalRotation = input.Angle() + Mathf.Pi / 2;
 | 
			
		||||
			Rotation = Mathf.LerpAngle(Rotation, finalRotation, RotationSpeed * (float)delta);
 | 
			
		||||
            centre.Rotation = Mathf.LerpAngle(centre.Rotation, finalRotation, RotationSpeed * (float)delta);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
@@ -101,6 +109,9 @@ public partial class Player : CharacterBody2D
 | 
			
		||||
    {
 | 
			
		||||
        Health -= damage;
 | 
			
		||||
 | 
			
		||||
        var bar = GetNode<ProgressBar>("HUD/HealthBar");
 | 
			
		||||
        bar.Value = Health / MaxHealth * 100;
 | 
			
		||||
 | 
			
		||||
        var shakableCamera = GetNode<CameraShake>("Camera2D");
 | 
			
		||||
        shakableCamera.AddTrauma(0.5f);
 | 
			
		||||
    }
 | 
			
		||||
@@ -108,7 +119,7 @@ public partial class Player : CharacterBody2D
 | 
			
		||||
    [Rpc(MultiplayerApi.RpcMode.AnyPeer, CallLocal = true)]
 | 
			
		||||
    private void Shoot()
 | 
			
		||||
    {
 | 
			
		||||
		var marker = GetNode<Marker2D>("Muzzle");
 | 
			
		||||
        var marker = GetNode<Marker2D>("RotationCentre/Muzzle");
 | 
			
		||||
        var projectile = BulletScene.Instantiate<Bullet>();
 | 
			
		||||
        projectile.Transform = marker.GlobalTransform;
 | 
			
		||||
        projectile.PlayerId = PlayerId;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user