🐛 Fix buges
This commit is contained in:
parent
b5819a249c
commit
3fa89145b4
@ -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="."]
|
||||
|
@ -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")
|
||||
|
29
Scripts/Brick.cs
Normal file
29
Scripts/Brick.cs
Normal file
@ -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<Timer>("DecayTimer").Timeout += () =>
|
||||
{
|
||||
DecayProgress--;
|
||||
if (DecayProgress > 0) return;
|
||||
|
||||
GetNode<Timer>("DecayTimer").Stop();
|
||||
QueueFree();
|
||||
};
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
var sprite = GetNode<Sprite2D>("Sprite2D");
|
||||
sprite.SelfModulate = new Color(sprite.SelfModulate, (float)DecayProgress / MaxDecayProgress);
|
||||
}
|
||||
}
|
@ -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();
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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<Timer>("ReloadTimer").IsStopped();
|
||||
public bool IsCurrentPlayer => _currentPlayerId == Multiplayer.GetUniqueId();
|
||||
|
||||
public double TimeRemainingOfReload
|
||||
=> GetNode<Timer>("ReloadTimer").TimeLeft;
|
||||
public bool IsReloading
|
||||
=> !GetNode<Timer>("ReloadTimer").IsStopped();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Health = MaxHealth;
|
||||
ActionPoints = MaxActionPoints;
|
||||
public double TimeRemainingOfReload
|
||||
=> GetNode<Timer>("ReloadTimer").TimeLeft;
|
||||
|
||||
if (PlayerId == Multiplayer.GetUniqueId())
|
||||
PlayerCamera.Enabled = true;
|
||||
public override void _Ready()
|
||||
{
|
||||
Health = MaxHealth;
|
||||
ActionPoints = MaxActionPoints;
|
||||
|
||||
PlayerName ??= $"Player#{PlayerId}";
|
||||
GetNode<Label>("Overlay/NameTag").Text = PlayerName;
|
||||
if (PlayerId == Multiplayer.GetUniqueId())
|
||||
PlayerCamera.Enabled = true;
|
||||
|
||||
GetNode<ProgressBar>("Overlay/HealthBar").Value = Health / MaxHealth * 100;
|
||||
PlayerName ??= $"Player#{PlayerId}";
|
||||
GetNode<Label>("Overlay/NameTag").Text = PlayerName;
|
||||
|
||||
GetNode<Timer>("ReloadTimer").Timeout += () =>
|
||||
{
|
||||
AmmoAmount = MaxAmmoAmount;
|
||||
PlayerInput.IsReloading = false;
|
||||
};
|
||||
}
|
||||
GetNode<ProgressBar>("Overlay/HealthBar").Value = Health / MaxHealth * 100;
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (PlayerInput.IsShooting)
|
||||
{
|
||||
PlayerInput.IsShooting = false;
|
||||
Shoot();
|
||||
}
|
||||
GetNode<Timer>("ReloadTimer").Timeout += () =>
|
||||
{
|
||||
AmmoAmount = MaxAmmoAmount;
|
||||
PlayerInput.IsReloading = false;
|
||||
};
|
||||
}
|
||||
|
||||
if (PlayerInput.IsReloading)
|
||||
{
|
||||
var timer = GetNode<Timer>("ReloadTimer");
|
||||
if (timer.IsStopped())
|
||||
{
|
||||
AmmoAmount = 0;
|
||||
timer.Start();
|
||||
}
|
||||
}
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (PlayerInput.IsShooting)
|
||||
{
|
||||
PlayerInput.IsShooting = false;
|
||||
|
||||
if (PlayerInput.IsBuilding)
|
||||
{
|
||||
PlayerInput.IsBuilding = false;
|
||||
|
||||
var target = GetGlobalMousePosition();
|
||||
var distance = Position.DistanceTo(target);
|
||||
if (distance <= Reach * TileSize)
|
||||
{
|
||||
var name = GD.Randi();
|
||||
Rpc(nameof(AddTile), target, name.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
var name = GD.Randi();
|
||||
Rpc(nameof(Shoot), name.ToString());
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
var input = PlayerInput.MovementDirection;
|
||||
if (PlayerInput.IsReloading)
|
||||
{
|
||||
if (AmmoAmount == MaxAmmoAmount)
|
||||
{
|
||||
PlayerInput.IsReloading = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
var timer = GetNode<Timer>("ReloadTimer");
|
||||
if (timer.IsStopped())
|
||||
{
|
||||
AmmoAmount = 0;
|
||||
timer.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (input != Vector2.Zero)
|
||||
{
|
||||
input = input.Normalized();
|
||||
Velocity = Velocity.MoveToward(input * MaxSpeed, Acceleration * (float)delta);
|
||||
if (PlayerInput.IsBuilding)
|
||||
{
|
||||
PlayerInput.IsBuilding = false;
|
||||
|
||||
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);
|
||||
}
|
||||
var target = GetGlobalMousePosition();
|
||||
var distance = Position.DistanceTo(target);
|
||||
if (distance <= Reach * TileSize)
|
||||
{
|
||||
var name = GD.Randi();
|
||||
if (GetParent<World>().GetTileByPosition<Node2D>(target) == null)
|
||||
Rpc(nameof(AddTile), target, PlayerId, name.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var dashCountdown = GetNode<Timer>("DashCountdown");
|
||||
if (PlayerInput.IsDashing && dashCountdown.IsStopped() && ActionPoints > 0)
|
||||
{
|
||||
PlayerInput.IsDashing = false;
|
||||
Velocity *= PlayerDashAcceleration;
|
||||
ActionPoints--;
|
||||
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);
|
||||
}
|
||||
|
||||
private void Shoot()
|
||||
{
|
||||
if (AmmoAmount <= 0) return;
|
||||
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);
|
||||
}
|
||||
|
||||
var marker = GetNode<Marker2D>("RotationCentre/Muzzle");
|
||||
var projectile = BulletScene.Instantiate<Bullet>();
|
||||
projectile.Transform = marker.GlobalTransform;
|
||||
projectile.PlayerId = PlayerId;
|
||||
var dashCountdown = GetNode<Timer>("DashCountdown");
|
||||
if (PlayerInput.IsDashing && dashCountdown.IsStopped() && ActionPoints > 0)
|
||||
{
|
||||
PlayerInput.IsDashing = false;
|
||||
Velocity *= PlayerDashAcceleration;
|
||||
ActionPoints--;
|
||||
dashCountdown.Start();
|
||||
}
|
||||
|
||||
GetParent().AddChild(projectile);
|
||||
AmmoAmount--;
|
||||
}
|
||||
|
||||
Position += Velocity * (float)delta;
|
||||
MoveAndSlide();
|
||||
}
|
||||
|
||||
[Rpc(MultiplayerApi.RpcMode.AnyPeer, CallLocal = true)]
|
||||
private void GotDamage(double damage)
|
||||
{
|
||||
var protection = GetNode<Timer>("ProtectionCountdown");
|
||||
public void TakeDamage(double damage)
|
||||
{
|
||||
Rpc(nameof(GotDamage), damage);
|
||||
}
|
||||
|
||||
if (protection.IsStopped())
|
||||
{
|
||||
Health -= damage;
|
||||
[Rpc(MultiplayerApi.RpcMode.AnyPeer, CallLocal = true)]
|
||||
private void Shoot(string name)
|
||||
{
|
||||
if (AmmoAmount <= 0) return;
|
||||
|
||||
var tween = CreateTween();
|
||||
var bar = GetNode<ProgressBar>("Overlay/HealthBar");
|
||||
tween.TweenProperty(bar, "value", Health / MaxHealth * 100, 0.3);
|
||||
var marker = GetNode<Marker2D>("RotationCentre/Muzzle");
|
||||
var projectile = BulletScene.Instantiate<Bullet>();
|
||||
projectile.Name = $"Bullet@{name}";
|
||||
projectile.Transform = marker.GlobalTransform;
|
||||
projectile.PlayerId = PlayerId;
|
||||
|
||||
protection.Start();
|
||||
}
|
||||
GetParent().AddChild(projectile);
|
||||
AmmoAmount--;
|
||||
}
|
||||
|
||||
var shakableCamera = GetNode<CameraShake>("Camera2D");
|
||||
shakableCamera.AddTrauma(0.5f);
|
||||
}
|
||||
[Rpc(MultiplayerApi.RpcMode.AnyPeer, CallLocal = true)]
|
||||
public void AddTile(Vector2 pos, int playerId, string name)
|
||||
{
|
||||
var tiles = GetParent<World>();
|
||||
var tileVec = new Vector2(50, 50);
|
||||
var instance = TileScene.Instantiate<Node2D>();
|
||||
instance.SetMultiplayerAuthority(playerId);
|
||||
instance.Name = $"Brick@{name}";
|
||||
instance.Position = pos.Snapped(tileVec);
|
||||
tiles.AddChild(instance);
|
||||
}
|
||||
|
||||
[Rpc(mode: MultiplayerApi.RpcMode.AnyPeer, CallLocal = true)]
|
||||
public void AddTile(Vector2 pos, string name)
|
||||
{
|
||||
if (GetParent<World>().GetTileByPosition<Node2D>(pos) != null) return;
|
||||
[Rpc(MultiplayerApi.RpcMode.AnyPeer, CallLocal = true)]
|
||||
private void GotDamage(double damage)
|
||||
{
|
||||
var protection = GetNode<Timer>("ProtectionCountdown");
|
||||
|
||||
var tiles = GetParent<World>();
|
||||
var tileVec = new Vector2(50, 50);
|
||||
var instance = TileScene.Instantiate<Node2D>();
|
||||
instance.Name = $"Brick@{name}";
|
||||
instance.Position = pos.Snapped(tileVec);
|
||||
tiles.AddChild(instance);
|
||||
}
|
||||
}
|
||||
if (protection.IsStopped())
|
||||
{
|
||||
Health -= damage;
|
||||
|
||||
var tween = CreateTween();
|
||||
var bar = GetNode<ProgressBar>("Overlay/HealthBar");
|
||||
tween.TweenProperty(bar, "value", Health / MaxHealth * 100, 0.3);
|
||||
|
||||
protection.Start();
|
||||
}
|
||||
|
||||
var shakableCamera = GetNode<CameraShake>("Camera2D");
|
||||
shakableCamera.AddTrauma(0.5f);
|
||||
}
|
||||
}
|
@ -15,6 +15,10 @@ run/main_scene="res://Scenes/Root.tscn"
|
||||
config/features=PackedStringArray("4.2", "C#", "Mobile")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[display]
|
||||
|
||||
window/stretch/mode="canvas_items"
|
||||
|
||||
[dotnet]
|
||||
|
||||
project/assembly_name="AceField"
|
||||
@ -48,7 +52,7 @@ move_dash={
|
||||
}
|
||||
weapon_shoot={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":70,"key_label":0,"unicode":102,"echo":false,"script":null)
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(166, 20),"global_position":Vector2(174, 100),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
weapon_reload={
|
||||
@ -56,6 +60,11 @@ weapon_reload={
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":82,"key_label":0,"unicode":114,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
skill_place_tile={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":2,"position":Vector2(174, 42),"global_position":Vector2(182, 122),"factor":1.0,"button_index":2,"canceled":false,"pressed":true,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[rendering]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user