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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198 |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Brains.Framework;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Brains;
using Brains.Framework.QuadTree;
using Brains.Framework.Map;
using Brains.Framework.Utility;
namespace AIRendering
{
public class DrawableWorld : World, IRender
{
public SpriteFont Font;
public SpriteBatch Batch;
public List<QuadTreePositionItem<GridCell>> items = new List<QuadTreePositionItem<GridCell>>();
public void Render(PrimitiveBatch batch)
{
items.Clear();
RectangleF _rect = new RectangleF(
batch.CameraPosition,
batch.CameraPosition +
new Vector2(
batch.Device.Viewport.Width * batch.Zoom,
batch.Device.Viewport.Height * batch.Zoom));
Map.GridCellTree.GetItems(_rect, ref items);
foreach (var item in items)
{
DrawCell(batch, item);
}
foreach (var item in Map.ClusterGrid.Grids)
{
Vector2 position = item.Position;
batch.DrawLine(
position,
position + new Vector2(item.Width, 0),
Color.Yellow);
batch.DrawLine(
position + new Vector2(item.Width, 0),
position + new Vector2(item.Width, item.Height),
Color.Yellow);
batch.DrawLine(
position + new Vector2(0, item.Height),
position + new Vector2(item.Width, item.Height),
Color.Yellow);
batch.DrawLine(
position,
position + new Vector2(0, item.Height),
Color.Yellow);
Color pathColor;
Color bisectorsColor;
foreach (var path in item.PredeterminedPaths)
{
for (int index = 0; index < path.Nodes.Count; index++)
{
pathColor = Color.Gold;
bisectorsColor = Color.Honeydew;
if (index < path.Nodes.Count - 1)
{
Vector2 pos1;
pos1 = item.GetCell(path.Nodes[index].X, path.Nodes[index].Y).Position;
Vector2 pos2 = item.GetCell(path.Nodes[index + 1].X, path.Nodes[index + 1].Y).Position;
batch.DrawLine(
pos1,
pos2,
pathColor
);
}
if (index < path.Nodes.Count - 1)
{
batch.DrawLine(
path.Nodes[index].nodePosition,
path.Nodes[index + 1].nodePosition,
pathColor
);
}
batch.DrawLine(
path.Nodes[index].biNormalStart,
path.Nodes[index].biNormalEnd,
bisectorsColor
);
}
}
}
foreach (DrawableActor item1 in Actors)
{
item1.Render(batch);
}
}
protected virtual void DrawCell(PrimitiveBatch batch, QuadTreePositionItem<GridCell> item)
{
batch.DrawBox(item.Rect.TopLeft, item.Rect.BottomRight, Color.White);
Vector2 firstLine = item.Rect.TopLeft + new Vector2(3, 3);
if (item.Parent.Labels[AIConsts.COLORG] == 255 &&
item.Parent.Labels[AIConsts.COLORB] == 0)
{
batch.DrawCircle(item.Parent.Position, 5, Color.Green);
Vector2 half = new Vector2(item.Parent.Parent.CellSize / 2);
batch.DrawLine(
item.Rect.TopLeft + new Vector2(24),
item.Rect.BottomRight - new Vector2(24),
Color.Green);
batch.DrawLine(
item.Rect.TopRight - new Vector2(24, -24),
item.Rect.BottomLeft + new Vector2(24, -24),
Color.Green);
}
foreach (var item1 in Map.ClusterGrid.Entrances)
{
batch.DrawLine(
item1.CellA.Position,
item1.CellB.Position,
Color.White);
batch.DrawCircle(
item1.CellA.Position,5,Color.Blue);
batch.DrawCircle(
item1.CellB.Position, 5, Color.Blue);
}
/*for (int i = 0; i < item.Parent.Type; i++)
{
batch.DrawLine(
firstLine,
firstLine + new Vector2(0, 5), Color.White);
firstLine.X += 6;
}*/
if (Batch != null)
{
//string clearance = item.Parent.Labels[AIConsts.CLEARANCEVALUE].ToString();
//Batch.DrawString(
// Font,
// clearance,
// (item.Position - batch.CameraPosition) / batch.Zoom,
// Color.White,
// 0,
// new Vector2(8, 8),
// 1,
// SpriteEffects.None,
// 0);
}
if (item.Parent.Type == 0)
{
Vector2 half = new Vector2(item.Parent.Parent.CellSize / 2);
batch.DrawLine(
item.Rect.TopLeft,
item.Rect.BottomRight,
Color.Red);
batch.DrawLine(
item.Rect.TopRight,
item.Rect.BottomLeft,
Color.Red);
}
if (item.Parent.Type == 2)
{
Vector2 half = new Vector2(item.Parent.Parent.CellSize / 2);
batch.DrawLine(
item.Rect.TopLeft,
item.Rect.BottomRight,
Color.Blue);
batch.DrawLine(
item.Rect.TopRight,
item.Rect.BottomLeft,
Color.Blue);
}
}
}
}
|