-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebugMapView.cs
More file actions
57 lines (49 loc) · 2.76 KB
/
DebugMapView.cs
File metadata and controls
57 lines (49 loc) · 2.76 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
using System;
using Leopotam.EcsLite;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using RTS;
public class DebugMapView : IEcsInitSystem, IEcsRunSystem
{
private EcsWorld _world;
private EcsPool<GameObject> pool;
private EcsFilter filter;
private SpriteBatch _spriteBatch;
private Texture2D _pixelTexture; // 1x1 пиксель для рисования линий
private Camera _camera;
public DebugMapView(EcsWorld world, SpriteBatch spriteBatch, Camera camera)
{
_world = world;
_spriteBatch = spriteBatch;
_camera = camera;
}
public void Init(IEcsSystems systems)
{
pool = _world.GetPool<GameObject>();
filter = _world.Filter<GameObject>().End();
// Создаём 1x1 текстуру (белый пиксель) для линий
_pixelTexture = new Texture2D(_spriteBatch.GraphicsDevice, 1, 1);
_pixelTexture.SetData(new[] { Color.White });
}
public void Run(IEcsSystems systems)
{
// Получаем границы карты из статических полей
float xLeft = Game1.XLLimit;
float xRight = Game1.XRLimit;
float yTop = Game1.YLLimit; // YLLimit - верхняя граница (минимум Y)
float yBottom = Game1.YRLimit; // YRLimit - нижняя граница (максимум Y)
// Толщина линии контура (можно увеличить для видимости)
float lineThickness = (int)MathHelper.Clamp((int)(3 / _camera.Zoom), 3, 10f);;
// Цвет контура (можно задать статически или через компонент, например, белый)
Color outlineColor = Color.White;
// Рисуем контур карты: четыре линии в мировых координатах
// Верхняя линия (от xLeft до xRight на yTop)
_spriteBatch.Draw(_pixelTexture, new Rectangle((int)xLeft, (int)yTop, (int)(xRight - xLeft), (int)lineThickness), outlineColor);
// Нижняя линия (от xLeft до xRight на yBottom)
_spriteBatch.Draw(_pixelTexture, new Rectangle((int)xLeft, (int)(yBottom - lineThickness), (int)(xRight - xLeft), (int)lineThickness), outlineColor);
// Левая линия (от yTop до yBottom на xLeft)
_spriteBatch.Draw(_pixelTexture, new Rectangle((int)xLeft, (int)yTop, (int)lineThickness, (int)(yBottom - yTop)), outlineColor);
// Правая линия (от yTop до yBottom на xRight)
_spriteBatch.Draw(_pixelTexture, new Rectangle((int)(xRight - lineThickness), (int)yTop, (int)lineThickness, (int)(yBottom - yTop)), outlineColor);
}
}