✨ Name & Health bar
This commit is contained in:
parent
0f9192a5f8
commit
58caef0014
@ -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);
|
||||
}
|
||||
}
|
@ -6,113 +6,124 @@ namespace AceField.Scripts;
|
||||
|
||||
public partial class Player : CharacterBody2D
|
||||
{
|
||||
private int _currentPlayerId = 1;
|
||||
private int _currentPlayerId = 1;
|
||||
|
||||
[Export] public float MaxSpeed = 400f;
|
||||
[Export] public float Acceleration = 500f;
|
||||
[Export] public float Deceleration = 500f;
|
||||
[Export] public float RotationSpeed = 5f;
|
||||
[Export] public float MaxSpeed = 400f;
|
||||
[Export] public float Acceleration = 500f;
|
||||
[Export] public float Deceleration = 500f;
|
||||
[Export] public float RotationSpeed = 5f;
|
||||
|
||||
[Export] public int Reach = 5;
|
||||
[Export] public int Reach = 5;
|
||||
|
||||
[Export] public double Health = 100;
|
||||
[Export] public double MaxHealth = 100;
|
||||
[Export] public double ActionPoints = 20;
|
||||
[Export] public double MaxActionPoints = 20;
|
||||
[Export] public double Health = 100;
|
||||
[Export] public double MaxHealth = 100;
|
||||
[Export] public double ActionPoints = 20;
|
||||
[Export] public double MaxActionPoints = 20;
|
||||
|
||||
[Export] public Camera2D PlayerCamera;
|
||||
[Export] public PlayerInput PlayerInput;
|
||||
[Export] public Camera2D PlayerCamera;
|
||||
[Export] public PlayerInput PlayerInput;
|
||||
|
||||
[Export] public float PlayerDashAcceleration = 2f;
|
||||
[Export] public float PlayerDashAcceleration = 2f;
|
||||
|
||||
[Export] public PackedScene BulletScene;
|
||||
[Export] public PackedScene BulletScene;
|
||||
|
||||
[Export]
|
||||
public int PlayerId
|
||||
{
|
||||
get => _currentPlayerId;
|
||||
set
|
||||
{
|
||||
_currentPlayerId = value;
|
||||
PlayerInput.SetMultiplayerAuthority(value);
|
||||
}
|
||||
}
|
||||
[Export] public string PlayerName;
|
||||
|
||||
public void SetPlayerId(int id)
|
||||
{
|
||||
PlayerId = id;
|
||||
PlayerInput.SetMultiplayerAuthority(id);
|
||||
}
|
||||
[Export]
|
||||
public int PlayerId
|
||||
{
|
||||
get => _currentPlayerId;
|
||||
set
|
||||
{
|
||||
_currentPlayerId = value;
|
||||
PlayerInput.SetMultiplayerAuthority(value);
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Health = MaxHealth;
|
||||
ActionPoints = MaxActionPoints;
|
||||
public void SetPlayerId(int id)
|
||||
{
|
||||
PlayerId = id;
|
||||
PlayerInput.SetMultiplayerAuthority(id);
|
||||
}
|
||||
|
||||
if (PlayerId == Multiplayer.GetUniqueId())
|
||||
PlayerCamera.Enabled = true;
|
||||
}
|
||||
public override void _Ready()
|
||||
{
|
||||
Health = MaxHealth;
|
||||
ActionPoints = MaxActionPoints;
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (PlayerInput.IsShooting)
|
||||
{
|
||||
Rpc(nameof(Shoot));
|
||||
PlayerInput.IsShooting = false;
|
||||
}
|
||||
}
|
||||
if (PlayerId == Multiplayer.GetUniqueId())
|
||||
PlayerCamera.Enabled = true;
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
var input = PlayerInput.MovementDirection;
|
||||
PlayerName = $"Player#{PlayerId}"; // TODO Remove mock data
|
||||
GetNode<Label>("HUD/NameTag").Text = PlayerName;
|
||||
|
||||
if (input != Vector2.Zero)
|
||||
{
|
||||
input = input.Normalized();
|
||||
Velocity = Velocity.MoveToward(input * MaxSpeed, Acceleration * (float)delta);
|
||||
GetNode<ProgressBar>("HUD/HealthBar").Value = Health / MaxHealth * 100;
|
||||
}
|
||||
|
||||
var finalRotation = input.Angle() + Mathf.Pi / 2;
|
||||
Rotation = Mathf.LerpAngle(Rotation, finalRotation, RotationSpeed * (float)delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
Velocity = Velocity.MoveToward(Vector2.Zero, Deceleration * (float)delta);
|
||||
}
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (PlayerInput.IsShooting)
|
||||
{
|
||||
Rpc(nameof(Shoot));
|
||||
PlayerInput.IsShooting = false;
|
||||
}
|
||||
}
|
||||
|
||||
var dashCountdown = GetNode<Timer>("DashCountdown");
|
||||
if (PlayerInput.IsDashing && dashCountdown.IsStopped())
|
||||
{
|
||||
PlayerInput.IsDashing = false;
|
||||
Velocity *= PlayerDashAcceleration;
|
||||
dashCountdown.Start();
|
||||
}
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
var input = PlayerInput.MovementDirection;
|
||||
|
||||
Position += Velocity * (float)delta;
|
||||
MoveAndSlide();
|
||||
}
|
||||
if (input != Vector2.Zero)
|
||||
{
|
||||
input = input.Normalized();
|
||||
Velocity = Velocity.MoveToward(input * MaxSpeed, Acceleration * (float)delta);
|
||||
|
||||
public void TakeDamage(double damage)
|
||||
{
|
||||
Rpc(nameof(GotDamage), damage);
|
||||
}
|
||||
var centre = GetNode<Node2D>("RotationCentre");
|
||||
var finalRotation = input.Angle() + Mathf.Pi / 2;
|
||||
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)]
|
||||
private void GotDamage(double damage)
|
||||
{
|
||||
Health -= damage;
|
||||
var dashCountdown = GetNode<Timer>("DashCountdown");
|
||||
if (PlayerInput.IsDashing && dashCountdown.IsStopped())
|
||||
{
|
||||
PlayerInput.IsDashing = false;
|
||||
Velocity *= PlayerDashAcceleration;
|
||||
dashCountdown.Start();
|
||||
}
|
||||
|
||||
var shakableCamera = GetNode<CameraShake>("Camera2D");
|
||||
shakableCamera.AddTrauma(0.5f);
|
||||
}
|
||||
Position += Velocity * (float)delta;
|
||||
MoveAndSlide();
|
||||
}
|
||||
|
||||
[Rpc(MultiplayerApi.RpcMode.AnyPeer, CallLocal = true)]
|
||||
private void Shoot()
|
||||
{
|
||||
var marker = GetNode<Marker2D>("Muzzle");
|
||||
var projectile = BulletScene.Instantiate<Bullet>();
|
||||
projectile.Transform = marker.GlobalTransform;
|
||||
projectile.PlayerId = PlayerId;
|
||||
public void TakeDamage(double damage)
|
||||
{
|
||||
Rpc(nameof(GotDamage), damage);
|
||||
}
|
||||
|
||||
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