From 3fa89145b4940e0cac2b50f9c08652e1a879ff5d Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Fri, 9 Aug 2024 00:42:22 +0800 Subject: [PATCH] :bug: Fix buges --- Scenes/Brick.tscn | 14 +- Scenes/Root.tscn | 4 +- Scripts/Brick.cs | 29 ++++ Scripts/Bullet.cs | 6 +- Scripts/Logic/PlayerInput.cs | 7 +- Scripts/Player.cs | 306 ++++++++++++++++++----------------- project.godot | 11 +- 7 files changed, 214 insertions(+), 163 deletions(-) create mode 100644 Scripts/Brick.cs diff --git a/Scenes/Brick.tscn b/Scenes/Brick.tscn index a3caa8c..5724382 100644 --- a/Scenes/Brick.tscn +++ b/Scenes/Brick.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=4 format=3 uid="uid://nu34biv4xo5k"] +[gd_scene load_steps=5 format=3 uid="uid://nu34biv4xo5k"] [ext_resource type="Texture2D" uid="uid://c2qpm7mcrvq57" path="res://Sprites/Brick.png" id="1_tqbee"] +[ext_resource type="Script" path="res://Scripts/Brick.cs" id="1_u0jqj"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_5wmf4"] size = Vector2(51.2, 51.2) @@ -8,9 +9,16 @@ size = Vector2(51.2, 51.2) [sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_r3565"] properties/0/path = NodePath(".:position") properties/0/spawn = true -properties/0/replication_mode = 1 +properties/0/replication_mode = 0 +properties/1/path = NodePath(".:DecayProgress") +properties/1/spawn = true +properties/1/replication_mode = 0 +properties/2/path = NodePath(".:MaxDecayProgress") +properties/2/spawn = true +properties/2/replication_mode = 0 [node name="Brick" type="StaticBody2D"] +script = ExtResource("1_u0jqj") [node name="Sprite2D" type="Sprite2D" parent="."] position = Vector2(2.08165e-12, 2.08165e-12) @@ -21,7 +29,7 @@ texture = ExtResource("1_tqbee") shape = SubResource("RectangleShape2D_5wmf4") [node name="DecayTimer" type="Timer" parent="."] -one_shot = true +wait_time = 0.1 autostart = true [node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."] diff --git a/Scenes/Root.tscn b/Scenes/Root.tscn index e560299..717caca 100644 --- a/Scenes/Root.tscn +++ b/Scenes/Root.tscn @@ -25,6 +25,6 @@ World = NodePath("../../World") script = ExtResource("3_xwguj") PlayerScene = ExtResource("1_vby0g") -[node name="WorldSpawner" type="MultiplayerSpawner" parent="."] -_spawnable_scenes = PackedStringArray("res://Scenes/Player.tscn", "res://Scenes/Brick.tscn") +[node name="PlayerSpawner" type="MultiplayerSpawner" parent="."] +_spawnable_scenes = PackedStringArray("res://Scenes/Player.tscn") spawn_path = NodePath("../World") diff --git a/Scripts/Brick.cs b/Scripts/Brick.cs new file mode 100644 index 0000000..9122b8f --- /dev/null +++ b/Scripts/Brick.cs @@ -0,0 +1,29 @@ +using Godot; + +namespace AceField.Scripts; + +public partial class Brick : StaticBody2D +{ + [Export] public int MaxDecayProgress = 50; + [Export] public int DecayProgress; + + public override void _Ready() + { + DecayProgress = MaxDecayProgress; + + GetNode("DecayTimer").Timeout += () => + { + DecayProgress--; + if (DecayProgress > 0) return; + + GetNode("DecayTimer").Stop(); + QueueFree(); + }; + } + + public override void _Process(double delta) + { + var sprite = GetNode("Sprite2D"); + sprite.SelfModulate = new Color(sprite.SelfModulate, (float)DecayProgress / MaxDecayProgress); + } +} diff --git a/Scripts/Bullet.cs b/Scripts/Bullet.cs index 6b82e1e..d99a4dd 100644 --- a/Scripts/Bullet.cs +++ b/Scripts/Bullet.cs @@ -17,10 +17,10 @@ public partial class Bullet : Area2D BodyEntered += body => { - if (body is not Player player || player.PlayerId == PlayerId) return; - if (body is Player p) + if (body is Player player) { - p.TakeDamage(Damage); + if (player.PlayerId == PlayerId) return; + player.TakeDamage(Damage); } QueueFree(); diff --git a/Scripts/Logic/PlayerInput.cs b/Scripts/Logic/PlayerInput.cs index 786963c..92c82e4 100644 --- a/Scripts/Logic/PlayerInput.cs +++ b/Scripts/Logic/PlayerInput.cs @@ -46,12 +46,7 @@ public partial class PlayerInput : MultiplayerSynchronizer Rpc(nameof(Shoot)); if (Input.IsActionJustPressed("weapon_reload")) Rpc(nameof(Reload)); - } - - public override void _Input(InputEvent evt) - { - if (!IsCurrentPlayer) return; - if (evt is InputEventMouseButton { Pressed: true }) + if (Input.IsActionJustPressed("skill_place_tile")) Rpc(nameof(Build)); } } diff --git a/Scripts/Player.cs b/Scripts/Player.cs index 7972ab3..2d03108 100644 --- a/Scripts/Player.cs +++ b/Scripts/Player.cs @@ -6,185 +6,195 @@ 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 AmmoAmount = 30; - [Export] public double MaxAmmoAmount = 30; + [Export] public double Health = 100; + [Export] public double MaxHealth = 100; + [Export] public double ActionPoints = 20; + [Export] public double MaxActionPoints = 20; + [Export] public int AmmoAmount = 30; + [Export] public int MaxAmmoAmount = 30; - [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 TileScene; - - [Export] public float TileSize; + [Export] public PackedScene BulletScene; + [Export] public PackedScene TileScene; - [Export] public string PlayerName; + [Export] public float TileSize; - [Export] - public int PlayerId - { - get => _currentPlayerId; - set - { - _currentPlayerId = value; - PlayerInput.SetMultiplayerAuthority(value); - } - } + [Export] public string PlayerName; - public bool IsCurrentPlayer => _currentPlayerId == Multiplayer.GetUniqueId(); + [Export] + public int PlayerId + { + get => _currentPlayerId; + set + { + _currentPlayerId = value; + PlayerInput.SetMultiplayerAuthority(value); + } + } - public bool IsReloading - => !GetNode("ReloadTimer").IsStopped(); + public bool IsCurrentPlayer => _currentPlayerId == Multiplayer.GetUniqueId(); - public double TimeRemainingOfReload - => GetNode("ReloadTimer").TimeLeft; + public bool IsReloading + => !GetNode("ReloadTimer").IsStopped(); - public override void _Ready() - { - Health = MaxHealth; - ActionPoints = MaxActionPoints; + public double TimeRemainingOfReload + => GetNode("ReloadTimer").TimeLeft; - if (PlayerId == Multiplayer.GetUniqueId()) - PlayerCamera.Enabled = true; + public override void _Ready() + { + Health = MaxHealth; + ActionPoints = MaxActionPoints; - PlayerName ??= $"Player#{PlayerId}"; - GetNode