/// <summary> /// Called when the game determines it is time to draw a frame. /// </summary> public override void Draw() { Display.ClearBuffers(); Batch.Begin(); // Draw map for (int y = 0; y < MapSize.Height; y++) { for (int x = 0; x < MapSize.Width; x++) { PathNode node = PathFinder.GetNode(x, y); Color color = node.IsWalkable ? Color.White : Color.Black; Batch.FillRectangle(new Rectangle(x * BlockSize.Width, y * BlockSize.Height, BlockSize.Width, BlockSize.Height), color); if (!node.IsOpen) { Batch.FillRectangle(new Rectangle(x * BlockSize.Width, y * BlockSize.Height, BlockSize.Width, BlockSize.Height), Color.FromArgb(128, Color.LightBlue)); } } } // Draw path if (Path != null) { foreach (PathNode node in Path) { Point location = new Point(node.Location.X * BlockSize.Width, node.Location.Y * BlockSize.Height); // Draw rectangle Batch.FillRectangle(new Rectangle(location.X, location.Y, BlockSize.Width, BlockSize.Height), Color.FromArgb(128, Color.Red)); } } // DebugPath(); if (!Start.IsEmpty) { Batch.FillRectangle(new Rectangle(Start.X * BlockSize.Width, Start.Y * BlockSize.Height, BlockSize.Width, BlockSize.Height), Color.Red); } if (!Destination.IsEmpty) { Batch.FillRectangle(new Rectangle(Destination.X * BlockSize.Width, Destination.Y * BlockSize.Height, BlockSize.Width, BlockSize.Height), Color.Green); } // Draw mouse int mousex = Mouse.Location.X - (Mouse.Location.X % BlockSize.Width); int mousey = Mouse.Location.Y - (Mouse.Location.Y % BlockSize.Height); if (mousex < BlockSize.Width * MapSize.Width && mousey < BlockSize.Height * MapSize.Height) { Batch.DrawRectangle(new Rectangle(mousex, mousey, BlockSize.Width, BlockSize.Height), Color.FromArgb(128, Color.Red)); } // some debug text Batch.DrawString(Font, new Point(MapSize.Width * BlockSize.Width + 50, 10), Color.Black, "Mouse location : " + MouseLocation.ToString()); Batch.DrawString(Font, new Point(MapSize.Width * BlockSize.Width + 50, 25), Color.Red, "Start location : " + Start.ToString()); Batch.DrawString(Font, new Point(MapSize.Width * BlockSize.Width + 50, 40), Color.Green, "Destination location : " + Destination.ToString()); Batch.DrawString(Font, new Point(MapSize.Width * BlockSize.Width + 50, 100), Color.Black, "Press spacebar to reset Start and Destination."); Batch.DrawString(Font, new Point(MapSize.Width * BlockSize.Width + 50, 115), Color.Black, "Press enter to find the path."); Batch.DrawString(Font, new Point(MapSize.Width * BlockSize.Width + 50, 130), Color.Black, "Press R to make some random unwakable block."); Batch.DrawString(Font, new Point(MapSize.Width * BlockSize.Width + 50, 145), Color.Black, "Press C to clear map."); Batch.DrawString(Font, new Point(MapSize.Width * BlockSize.Width + 50, 200), Color.Black, "F = G + H."); Batch.DrawString(Font, new Point(MapSize.Width * BlockSize.Width + 50, 215), Color.Black, "G = Movement cost to move from the starting point."); Batch.DrawString(Font, new Point(MapSize.Width * BlockSize.Width + 50, 230), Color.Black, "H = Estimated movement cost to move to the final destination."); Batch.End(); }