✨ Better bullet
This commit is contained in:
parent
3fa89145b4
commit
cf6b4b0273
@ -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")
|
||||
|
@ -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")
|
||||
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
};
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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}";
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user