✨ Name & Health bar
This commit is contained in:
parent
0f9192a5f8
commit
58caef0014
@ -5,16 +5,10 @@
|
|||||||
</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/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$/.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$/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$/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>
|
</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" />
|
||||||
@ -116,7 +110,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="6034000" />
|
<workItem from="1723040934916" duration="7673000" />
|
||||||
</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" />
|
||||||
|
@ -33,11 +33,38 @@ PlayerCamera = NodePath("Camera2D")
|
|||||||
PlayerInput = NodePath("InputSynchronizer")
|
PlayerInput = NodePath("InputSynchronizer")
|
||||||
BulletScene = ExtResource("2_nmop0")
|
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)
|
position = Vector2(2.08165e-12, 2.08165e-12)
|
||||||
scale = Vector2(0.04, 0.04)
|
scale = Vector2(0.04, 0.04)
|
||||||
texture = ExtResource("1_cqpqa")
|
texture = ExtResource("1_cqpqa")
|
||||||
|
|
||||||
|
[node name="Muzzle" type="Marker2D" parent="RotationCentre"]
|
||||||
|
position = Vector2(2.08165e-12, -20)
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
shape = SubResource("CircleShape2D_68yf8")
|
shape = SubResource("CircleShape2D_68yf8")
|
||||||
|
|
||||||
@ -49,9 +76,6 @@ rotation_smoothing_enabled = true
|
|||||||
script = ExtResource("4_fwngj")
|
script = ExtResource("4_fwngj")
|
||||||
Noise = SubResource("FastNoiseLite_cfnx7")
|
Noise = SubResource("FastNoiseLite_cfnx7")
|
||||||
|
|
||||||
[node name="Muzzle" type="Marker2D" parent="."]
|
|
||||||
position = Vector2(2.08165e-12, -20)
|
|
||||||
|
|
||||||
[node name="DashCountdown" type="Timer" parent="."]
|
[node name="DashCountdown" type="Timer" parent="."]
|
||||||
one_shot = true
|
one_shot = true
|
||||||
|
|
||||||
|
@ -50,9 +50,4 @@ public partial class CameraShake : Camera2D
|
|||||||
{
|
{
|
||||||
_trauma = Mathf.Min(_trauma + amount, 1.0f);
|
_trauma = Mathf.Min(_trauma + amount, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetTrauma(float amount)
|
|
||||||
{
|
|
||||||
_trauma = Mathf.Min(amount, 1.0f);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -6,113 +6,124 @@ 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 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]
|
[Export] public string PlayerName;
|
||||||
public int PlayerId
|
|
||||||
{
|
|
||||||
get => _currentPlayerId;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_currentPlayerId = value;
|
|
||||||
PlayerInput.SetMultiplayerAuthority(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetPlayerId(int id)
|
[Export]
|
||||||
{
|
public int PlayerId
|
||||||
PlayerId = id;
|
{
|
||||||
PlayerInput.SetMultiplayerAuthority(id);
|
get => _currentPlayerId;
|
||||||
}
|
set
|
||||||
|
{
|
||||||
|
_currentPlayerId = value;
|
||||||
|
PlayerInput.SetMultiplayerAuthority(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override void _Ready()
|
public void SetPlayerId(int id)
|
||||||
{
|
{
|
||||||
Health = MaxHealth;
|
PlayerId = id;
|
||||||
ActionPoints = MaxActionPoints;
|
PlayerInput.SetMultiplayerAuthority(id);
|
||||||
|
}
|
||||||
|
|
||||||
if (PlayerId == Multiplayer.GetUniqueId())
|
public override void _Ready()
|
||||||
PlayerCamera.Enabled = true;
|
{
|
||||||
}
|
Health = MaxHealth;
|
||||||
|
ActionPoints = MaxActionPoints;
|
||||||
|
|
||||||
public override void _Process(double delta)
|
if (PlayerId == Multiplayer.GetUniqueId())
|
||||||
{
|
PlayerCamera.Enabled = true;
|
||||||
if (PlayerInput.IsShooting)
|
|
||||||
{
|
|
||||||
Rpc(nameof(Shoot));
|
|
||||||
PlayerInput.IsShooting = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void _PhysicsProcess(double delta)
|
PlayerName = $"Player#{PlayerId}"; // TODO Remove mock data
|
||||||
{
|
GetNode<Label>("HUD/NameTag").Text = PlayerName;
|
||||||
var input = PlayerInput.MovementDirection;
|
|
||||||
|
|
||||||
if (input != Vector2.Zero)
|
GetNode<ProgressBar>("HUD/HealthBar").Value = Health / MaxHealth * 100;
|
||||||
{
|
}
|
||||||
input = input.Normalized();
|
|
||||||
Velocity = Velocity.MoveToward(input * MaxSpeed, Acceleration * (float)delta);
|
|
||||||
|
|
||||||
var finalRotation = input.Angle() + Mathf.Pi / 2;
|
public override void _Process(double delta)
|
||||||
Rotation = Mathf.LerpAngle(Rotation, finalRotation, RotationSpeed * (float)delta);
|
{
|
||||||
}
|
if (PlayerInput.IsShooting)
|
||||||
else
|
{
|
||||||
{
|
Rpc(nameof(Shoot));
|
||||||
Velocity = Velocity.MoveToward(Vector2.Zero, Deceleration * (float)delta);
|
PlayerInput.IsShooting = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var dashCountdown = GetNode<Timer>("DashCountdown");
|
public override void _PhysicsProcess(double delta)
|
||||||
if (PlayerInput.IsDashing && dashCountdown.IsStopped())
|
{
|
||||||
{
|
var input = PlayerInput.MovementDirection;
|
||||||
PlayerInput.IsDashing = false;
|
|
||||||
Velocity *= PlayerDashAcceleration;
|
|
||||||
dashCountdown.Start();
|
|
||||||
}
|
|
||||||
|
|
||||||
Position += Velocity * (float)delta;
|
if (input != Vector2.Zero)
|
||||||
MoveAndSlide();
|
{
|
||||||
}
|
input = input.Normalized();
|
||||||
|
Velocity = Velocity.MoveToward(input * MaxSpeed, Acceleration * (float)delta);
|
||||||
|
|
||||||
public void TakeDamage(double damage)
|
var centre = GetNode<Node2D>("RotationCentre");
|
||||||
{
|
var finalRotation = input.Angle() + Mathf.Pi / 2;
|
||||||
Rpc(nameof(GotDamage), damage);
|
centre.Rotation = Mathf.LerpAngle(centre.Rotation, finalRotation, RotationSpeed * (float)delta);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Velocity = Velocity.MoveToward(Vector2.Zero, Deceleration * (float)delta);
|
||||||
|
}
|
||||||
|
|
||||||
[Rpc(MultiplayerApi.RpcMode.AnyPeer, CallLocal = true)]
|
var dashCountdown = GetNode<Timer>("DashCountdown");
|
||||||
private void GotDamage(double damage)
|
if (PlayerInput.IsDashing && dashCountdown.IsStopped())
|
||||||
{
|
{
|
||||||
Health -= damage;
|
PlayerInput.IsDashing = false;
|
||||||
|
Velocity *= PlayerDashAcceleration;
|
||||||
|
dashCountdown.Start();
|
||||||
|
}
|
||||||
|
|
||||||
var shakableCamera = GetNode<CameraShake>("Camera2D");
|
Position += Velocity * (float)delta;
|
||||||
shakableCamera.AddTrauma(0.5f);
|
MoveAndSlide();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Rpc(MultiplayerApi.RpcMode.AnyPeer, CallLocal = true)]
|
public void TakeDamage(double damage)
|
||||||
private void Shoot()
|
{
|
||||||
{
|
Rpc(nameof(GotDamage), damage);
|
||||||
var marker = GetNode<Marker2D>("Muzzle");
|
}
|
||||||
var projectile = BulletScene.Instantiate<Bullet>();
|
|
||||||
projectile.Transform = marker.GlobalTransform;
|
|
||||||
projectile.PlayerId = PlayerId;
|
|
||||||
|
|
||||||
GetParent().AddChild(projectile);
|
[Rpc(MultiplayerApi.RpcMode.AnyPeer, CallLocal = true)]
|
||||||
}
|
private void GotDamage(double damage)
|
||||||
|
{
|
||||||
|
Health -= damage;
|
||||||
|
|
||||||
|
var bar = GetNode<ProgressBar>("HUD/HealthBar");
|
||||||
|
bar.Value = Health / MaxHealth * 100;
|
||||||
|
|
||||||
|
var shakableCamera = GetNode<CameraShake>("Camera2D");
|
||||||
|
shakableCamera.AddTrauma(0.5f);
|
||||||
|
}
|
||||||
|
|
||||||
|
[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);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user