Better bullet

This commit is contained in:
LittleSheep 2024-08-09 02:20:56 +08:00
parent 3fa89145b4
commit cf6b4b0273
8 changed files with 197 additions and 172 deletions

View File

@ -6,16 +6,16 @@
[sub_resource type="RectangleShape2D" id="RectangleShape2D_5wmf4"]
size = Vector2(51.2, 51.2)
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_r3565"]
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_ccaja"]
properties/0/path = NodePath(".:position")
properties/0/spawn = true
properties/0/replication_mode = 0
properties/1/path = NodePath(".:DecayProgress")
properties/0/replication_mode = 1
properties/1/path = NodePath(".:PlayerId")
properties/1/spawn = true
properties/1/replication_mode = 0
properties/2/path = NodePath(".:MaxDecayProgress")
properties/1/replication_mode = 1
properties/2/path = NodePath(".:DecayProgress")
properties/2/spawn = true
properties/2/replication_mode = 0
properties/2/replication_mode = 1
[node name="Brick" type="StaticBody2D"]
script = ExtResource("1_u0jqj")
@ -33,4 +33,4 @@ wait_time = 0.1
autostart = true
[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."]
replication_config = SubResource("SceneReplicationConfig_r3565")
replication_config = SubResource("SceneReplicationConfig_ccaja")

View File

@ -115,6 +115,10 @@ one_shot = true
wait_time = 0.05
one_shot = true
[node name="WeaponCountdown" type="Timer" parent="."]
wait_time = 0.1
one_shot = true
[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."]
replication_config = SubResource("SceneReplicationConfig_bekoo")

View File

@ -38,6 +38,7 @@ text = "Health 100/100"
custom_minimum_size = Vector2(2.08165e-12, 16)
layout_mode = 2
size_flags_horizontal = 3
max_value = 1.0
rounded = true
allow_greater = true
allow_lesser = true
@ -56,6 +57,7 @@ horizontal_alignment = 1
custom_minimum_size = Vector2(2.08165e-12, 16)
layout_mode = 2
size_flags_horizontal = 3
max_value = 1.0
rounded = true
allow_greater = true
allow_lesser = true

View File

@ -7,6 +7,8 @@ public partial class Brick : StaticBody2D
[Export] public int MaxDecayProgress = 50;
[Export] public int DecayProgress;
[Export] public int PlayerId;
public override void _Ready()
{
DecayProgress = MaxDecayProgress;
@ -15,14 +17,14 @@ public partial class Brick : StaticBody2D
{
DecayProgress--;
if (DecayProgress > 0) return;
GetNode<Timer>("DecayTimer").Stop();
QueueFree();
};
}
public override void _Process(double delta)
{
if(DecayProgress <= 0) QueueFree();
var sprite = GetNode<Sprite2D>("Sprite2D");
sprite.SelfModulate = new Color(sprite.SelfModulate, (float)DecayProgress / MaxDecayProgress);
}

View File

@ -23,6 +23,12 @@ public partial class Bullet : Area2D
player.TakeDamage(Damage);
}
if (body is Brick brick)
{
if (brick.PlayerId == PlayerId) return;
brick.DecayProgress--;
}
QueueFree();
};
}

View File

@ -42,7 +42,7 @@ public partial class PlayerInput : MultiplayerSynchronizer
if (Input.IsActionJustPressed("move_dash"))
Rpc(nameof(Dash));
if (Input.IsActionJustPressed("weapon_shoot"))
if (Input.IsActionPressed("weapon_shoot"))
Rpc(nameof(Shoot));
if (Input.IsActionJustPressed("weapon_reload"))
Rpc(nameof(Reload));

View File

@ -79,8 +79,14 @@ public partial class Player : CharacterBody2D
{
PlayerInput.IsShooting = false;
var timer = GetNode<Timer>("WeaponCountdown");
if (timer.IsStopped())
{
var name = GD.Randi();
Rpc(nameof(Shoot), name.ToString());
Shoot(name.ToString());
timer.Start();
}
}
if (PlayerInput.IsReloading)
@ -142,6 +148,11 @@ public partial class Player : CharacterBody2D
dashCountdown.Start();
}
if (IsReloading)
{
Velocity *= 0.8f;
}
Position += Velocity * (float)delta;
MoveAndSlide();
}
@ -151,7 +162,6 @@ public partial class Player : CharacterBody2D
Rpc(nameof(GotDamage), damage);
}
[Rpc(MultiplayerApi.RpcMode.AnyPeer, CallLocal = true)]
private void Shoot(string name)
{
if (AmmoAmount <= 0) return;
@ -171,10 +181,10 @@ public partial class Player : CharacterBody2D
{
var tiles = GetParent<World>();
var tileVec = new Vector2(50, 50);
var instance = TileScene.Instantiate<Node2D>();
instance.SetMultiplayerAuthority(playerId);
var instance = TileScene.Instantiate<Brick>();
instance.Name = $"Brick@{name}";
instance.Position = pos.Snapped(tileVec);
instance.PlayerId = playerId;
tiles.AddChild(instance);
}

View File

@ -13,7 +13,7 @@ public partial class HUD : Control
Position = new Vector2(0, 0);
Size = screenSize;
GetNode<HBoxContainer>("TopBox").Size = new Vector2(screenSize.X-16*2, 16);
GetNode<HBoxContainer>("TopBox").Size = new Vector2(screenSize.X - 16 * 2, 16);
}
public override void _Process(double delta)
@ -33,8 +33,9 @@ public partial class HUD : Control
var ammoBar = GetNode<ProgressBar>("TopBox/AmmoBox/Bar");
var ammoLabel = GetNode<Label>("TopBox/AmmoBox/Label");
ammoBar.Value = player.AmmoAmount / player.MaxAmmoAmount * 100;
if (player.IsReloading) ammoLabel.Text = $"Reloading... {player.TimeRemainingOfReload:F2}";
else ammoLabel.Text = $"Ammo {player.AmmoAmount}/{player.MaxAmmoAmount}";
ammoBar.Value = (float)player.AmmoAmount / player.MaxAmmoAmount * 100;
ammoLabel.Text = player.IsReloading
? $"Reloading... {player.TimeRemainingOfReload:F2}"
: $"Ammo {player.AmmoAmount}/{player.MaxAmmoAmount}";
}
}