-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoveToSystem.cs
More file actions
67 lines (57 loc) · 2.3 KB
/
MoveToSystem.cs
File metadata and controls
67 lines (57 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
using Leopotam.EcsLite;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using RTS;
public class MoveToSystem : IEcsInitSystem, IEcsRunSystem
{
private EcsWorld _world;
private EcsFilter _filter;
private Camera _camera;
public MoveToSystem(EcsWorld world, Camera camera)
{
_world = world;
_camera = camera;
}
public void Init(IEcsSystems systems)
{
_filter = _world.Filter<Movement>().Inc<GameObject>().Inc<Selected>().End();
}
public void Run(IEcsSystems systems)
{
// Если левая кнопка только что нажата (предполагаю, вы имели в виду правую, как в коде)
if (Game1.CurrentMouseState.RightButton == ButtonState.Pressed && Game1.PreviousMouseState.RightButton == ButtonState.Released)
{
// Получить список выделенных юнитов
var selectedEntities = new List<int>();
foreach (var entity in _filter)
{
selectedEntities.Add(entity);
}
int unitCount = selectedEntities.Count;
if (unitCount == 0) return;
Vector2 formationCenter = Game1.MouseGlobalPosition;
float formationRadius = _filter.GetEntitiesCount(); // Радиус формации (настройте по размеру клеток/юнитов)
for (int i = 0; i < unitCount; i++)
{
ref var movement = ref _world.GetPool<Movement>().Get(selectedEntities[i]);
if (unitCount == 1)
{
// Один юнит идёт прямо к центру
movement.NewFinishPoint = formationCenter;
}
else
{
// Круговая формация: равномерное распределение по кругу
float angle = (i / (float)unitCount) * MathHelper.TwoPi; // Угол в радианах (0-2π)
Vector2 offset = new Vector2(
(float)Math.Cos(angle) * formationRadius,
(float)Math.Sin(angle) * formationRadius
);
movement.NewFinishPoint = formationCenter + offset;
}
}
}
}
}