⏪ Rollback place brick feature
This commit is contained in:
parent
e5be2bdc7c
commit
b5819a249c
13
.idea/.idea.CodingLand/.idea/workspace.xml
generated
13
.idea/.idea.CodingLand/.idea/workspace.xml
generated
@ -5,18 +5,9 @@
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="c7bd02c7-bbb4-431f-81ca-d2f8b7b09b37" name="Changes" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/Scenes/UI/HUD.tscn" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/Scripts/UI/HUD.cs" 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$/Scenes/Root.tscn" beforeDir="false" afterPath="$PROJECT_DIR$/Scenes/Root.tscn" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Scenes/UI/LaunchScreen.tscn" beforeDir="false" afterPath="$PROJECT_DIR$/Scenes/UI/LaunchScreen.tscn" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Scripts/Bullet.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Scripts/Bullet.cs" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Scripts/Launcher.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Scripts/Launcher.cs" 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/Logic/World.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Scripts/Logic/World.cs" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Scenes/UI/HUD.tscn" beforeDir="false" afterPath="$PROJECT_DIR$/Scenes/UI/HUD.tscn" 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" />
|
||||
@ -119,7 +110,7 @@
|
||||
<workItem from="1722846222698" duration="9239000" />
|
||||
<workItem from="1722855558149" duration="11578000" />
|
||||
<workItem from="1723040712804" duration="74000" />
|
||||
<workItem from="1723040934916" duration="16092000" />
|
||||
<workItem from="1723040934916" duration="18349000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary=":sparkles: Usable multiplayer">
|
||||
<option name="closed" value="true" />
|
||||
|
28
Scenes/Brick.tscn
Normal file
28
Scenes/Brick.tscn
Normal file
@ -0,0 +1,28 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://nu34biv4xo5k"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://c2qpm7mcrvq57" path="res://Sprites/Brick.png" id="1_tqbee"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_5wmf4"]
|
||||
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
|
||||
|
||||
[node name="Brick" type="StaticBody2D"]
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
position = Vector2(2.08165e-12, 2.08165e-12)
|
||||
scale = Vector2(0.05, 0.05)
|
||||
texture = ExtResource("1_tqbee")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("RectangleShape2D_5wmf4")
|
||||
|
||||
[node name="DecayTimer" type="Timer" parent="."]
|
||||
one_shot = true
|
||||
autostart = true
|
||||
|
||||
[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."]
|
||||
replication_config = SubResource("SceneReplicationConfig_r3565")
|
@ -1,8 +1,9 @@
|
||||
[gd_scene load_steps=10 format=3 uid="uid://b3gx0bl43lku3"]
|
||||
[gd_scene load_steps=11 format=3 uid="uid://b3gx0bl43lku3"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scripts/Player.cs" id="1_0btyt"]
|
||||
[ext_resource type="Texture2D" uid="uid://c4als6t3k4myc" path="res://Sprites/Player.png" id="1_cqpqa"]
|
||||
[ext_resource type="PackedScene" uid="uid://ds40mib6ur8yf" path="res://Scenes/Bullet.tscn" id="2_nmop0"]
|
||||
[ext_resource type="PackedScene" uid="uid://nu34biv4xo5k" path="res://Scenes/Brick.tscn" id="3_6sbto"]
|
||||
[ext_resource type="Script" path="res://Scripts/Logic/PlayerInput.cs" id="3_tvoua"]
|
||||
[ext_resource type="Script" path="res://Scripts/Effects/CameraShake.cs" id="4_fwngj"]
|
||||
|
||||
@ -56,6 +57,8 @@ script = ExtResource("1_0btyt")
|
||||
PlayerCamera = NodePath("Camera2D")
|
||||
PlayerInput = NodePath("InputSynchronizer")
|
||||
BulletScene = ExtResource("2_nmop0")
|
||||
TileScene = ExtResource("3_6sbto")
|
||||
TileSize = 50.0
|
||||
|
||||
[node name="Overlay" type="VBoxContainer" parent="."]
|
||||
offset_left = -90.0
|
||||
|
@ -25,6 +25,6 @@ World = NodePath("../../World")
|
||||
script = ExtResource("3_xwguj")
|
||||
PlayerScene = ExtResource("1_vby0g")
|
||||
|
||||
[node name="PlayerSpawner" type="MultiplayerSpawner" parent="."]
|
||||
_spawnable_scenes = PackedStringArray("res://Scenes/Player.tscn")
|
||||
[node name="WorldSpawner" type="MultiplayerSpawner" parent="."]
|
||||
_spawnable_scenes = PackedStringArray("res://Scenes/Player.tscn", "res://Scenes/Brick.tscn")
|
||||
spawn_path = NodePath("../World")
|
||||
|
@ -1,7 +1,13 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://c7w5sgq0bshk0"]
|
||||
[gd_scene load_steps=4 format=3 uid="uid://c7w5sgq0bshk0"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scripts/UI/HUD.cs" id="1_2iqqk"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_bl2bd"]
|
||||
bg_color = Color(0.243137, 0.243137, 0.243137, 1)
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_it2a4"]
|
||||
bg_color = Color(0.545098, 0.545098, 0.545098, 1)
|
||||
|
||||
[node name="Hud" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
@ -72,3 +78,20 @@ rounded = true
|
||||
allow_greater = true
|
||||
allow_lesser = true
|
||||
show_percentage = false
|
||||
|
||||
[node name="BottomBox" type="VBoxContainer" parent="."]
|
||||
layout_mode = 0
|
||||
offset_top = 608.0
|
||||
offset_right = 1152.0
|
||||
offset_bottom = 648.0
|
||||
alignment = 2
|
||||
|
||||
[node name="ProgressBar" type="ProgressBar" parent="BottomBox"]
|
||||
custom_minimum_size = Vector2(2.08165e-12, 4)
|
||||
layout_mode = 2
|
||||
theme_override_styles/background = SubResource("StyleBoxFlat_bl2bd")
|
||||
theme_override_styles/fill = SubResource("StyleBoxFlat_it2a4")
|
||||
value = 50.0
|
||||
allow_greater = true
|
||||
allow_lesser = true
|
||||
show_percentage = false
|
||||
|
@ -5,7 +5,7 @@ namespace AceField.Scripts;
|
||||
public partial class Bullet : Area2D
|
||||
{
|
||||
[Export] public int PlayerId = 1;
|
||||
|
||||
|
||||
[Export] public float Speed = 1500;
|
||||
[Export] public double Damage = 8;
|
||||
|
||||
@ -18,7 +18,11 @@ public partial class Bullet : Area2D
|
||||
BodyEntered += body =>
|
||||
{
|
||||
if (body is not Player player || player.PlayerId == PlayerId) return;
|
||||
player.TakeDamage(Damage);
|
||||
if (body is Player p)
|
||||
{
|
||||
p.TakeDamage(Damage);
|
||||
}
|
||||
|
||||
QueueFree();
|
||||
};
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ namespace AceField.Scripts.Logic;
|
||||
public partial class PlayerInput : MultiplayerSynchronizer
|
||||
{
|
||||
[Export] public bool IsDashing;
|
||||
[Export] public bool IsBuilding;
|
||||
[Export] public bool IsShooting;
|
||||
[Export] public bool IsReloading;
|
||||
|
||||
@ -30,6 +31,10 @@ public partial class PlayerInput : MultiplayerSynchronizer
|
||||
[Rpc(CallLocal = true)]
|
||||
private void Reload()
|
||||
=> IsReloading = true;
|
||||
|
||||
[Rpc(CallLocal = true)]
|
||||
private void Build()
|
||||
=> IsBuilding = true;
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
@ -46,5 +51,7 @@ public partial class PlayerInput : MultiplayerSynchronizer
|
||||
public override void _Input(InputEvent evt)
|
||||
{
|
||||
if (!IsCurrentPlayer) return;
|
||||
if (evt is InputEventMouseButton { Pressed: true })
|
||||
Rpc(nameof(Build));
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ public partial class World : Node2D
|
||||
}
|
||||
|
||||
private static string BuildPlayerName(int id)
|
||||
=> $"Player#{id}";
|
||||
=> $"Player@{id}";
|
||||
|
||||
private void AddPlayer_Adaptor(long id)
|
||||
=> AddPlayer((int)id);
|
||||
@ -75,4 +75,15 @@ public partial class World : Node2D
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public T GetTileByPosition<T>(Vector2 position) where T : Node2D
|
||||
{
|
||||
foreach (var item in GetChildren())
|
||||
{
|
||||
if (item is T tile && tile.Position == position)
|
||||
return tile;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -28,6 +28,9 @@ public partial class Player : CharacterBody2D
|
||||
[Export] public float PlayerDashAcceleration = 2f;
|
||||
|
||||
[Export] public PackedScene BulletScene;
|
||||
[Export] public PackedScene TileScene;
|
||||
|
||||
[Export] public float TileSize;
|
||||
|
||||
[Export] public string PlayerName;
|
||||
|
||||
@ -82,7 +85,23 @@ public partial class Player : CharacterBody2D
|
||||
{
|
||||
var timer = GetNode<Timer>("ReloadTimer");
|
||||
if (timer.IsStopped())
|
||||
{
|
||||
AmmoAmount = 0;
|
||||
timer.Start();
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,6 +140,20 @@ public partial class Player : CharacterBody2D
|
||||
{
|
||||
Rpc(nameof(GotDamage), damage);
|
||||
}
|
||||
|
||||
private void Shoot()
|
||||
{
|
||||
if (AmmoAmount <= 0) return;
|
||||
|
||||
var marker = GetNode<Marker2D>("RotationCentre/Muzzle");
|
||||
var projectile = BulletScene.Instantiate<Bullet>();
|
||||
projectile.Transform = marker.GlobalTransform;
|
||||
projectile.PlayerId = PlayerId;
|
||||
|
||||
GetParent().AddChild(projectile);
|
||||
AmmoAmount--;
|
||||
}
|
||||
|
||||
|
||||
[Rpc(MultiplayerApi.RpcMode.AnyPeer, CallLocal = true)]
|
||||
private void GotDamage(double damage)
|
||||
@ -142,16 +175,16 @@ public partial class Player : CharacterBody2D
|
||||
shakableCamera.AddTrauma(0.5f);
|
||||
}
|
||||
|
||||
private void Shoot()
|
||||
[Rpc(mode: MultiplayerApi.RpcMode.AnyPeer, CallLocal = true)]
|
||||
public void AddTile(Vector2 pos, string name)
|
||||
{
|
||||
if (AmmoAmount <= 0) return;
|
||||
if (GetParent<World>().GetTileByPosition<Node2D>(pos) != null) return;
|
||||
|
||||
var marker = GetNode<Marker2D>("RotationCentre/Muzzle");
|
||||
var projectile = BulletScene.Instantiate<Bullet>();
|
||||
projectile.Transform = marker.GlobalTransform;
|
||||
projectile.PlayerId = PlayerId;
|
||||
|
||||
GetParent().AddChild(projectile);
|
||||
AmmoAmount--;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user