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> items = new List>(); 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 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); } } } }