void drawPathStepByStep() { SpriteBatch spriteBatch = Game.SpriteBatch; Texture2D texture = Game.Texture; float lastStep = drawStep; if (drawStep < path.Closed.Count) { drawStep += drawSpeed; } if (drawStep >= path.Closed.Count) { drawStep = path.Closed.Count; drawMode = PathDrawMode.Full; } int max = (int)drawStep; for (int i = 0; i < max; i++) { Color color = Color.White * 0.5f; if (i >= lastStep) { color = Color.Red * 0.75f; } drawNode(spriteBatch, texture, path.Closed[i], color); } }
public override void Update() { base.Update(); KeyboardState keyboard = Keyboard.GetState(); if (keyboard.IsKeyDown(Keys.Q)) { slowness = 1; } else if (keyboard.IsKeyDown(Keys.W)) { slowness = 10; } else if (keyboard.IsKeyDown(Keys.E)) { slowness = 100; } else if (keyboard.IsKeyDown(Keys.R)) { slowness = 1000; } else if (keyboard.IsKeyDown(Keys.A)) { drawMode = PathDrawMode.Full; } else if (keyboard.IsKeyDown(Keys.S)) { drawMode = PathDrawMode.StepByStep; } else if (keyboard.IsKeyDown(Keys.Z)) { drawSpeed = 1f; } else if (keyboard.IsKeyDown(Keys.X)) { drawSpeed = 10f; } else if (keyboard.IsKeyDown(Keys.C)) { drawSpeed = 100f; } else if (keyboard.IsKeyDown(Keys.V)) { drawSpeed = 1000f; } MouseState mouse = Mouse.GetState(); Point point = new Point(mouse.X / Map.TileSize, mouse.Y / Map.TileSize); Node node = Map.TryGetNodeAt(point); if (node != null) { if (mouse.LeftButton == ButtonState.Pressed && previousMouse.LeftButton == ButtonState.Released) { start = node; if (destination != null) { drawStep = 0; Stopwatch stopwatch = Stopwatch.StartNew(); for (int i = 0; i < slowness; i++) { path = FindPath(start, destination); } stopwatch.Stop(); time = stopwatch.ElapsedMilliseconds; } } else if (mouse.RightButton == ButtonState.Pressed && previousMouse.RightButton == ButtonState.Released) { destination = node; if (start != null) { drawStep = 0; Stopwatch stopwatch = Stopwatch.StartNew(); for (int i = 0; i < slowness; i++) { path = FindPath(start, destination); } stopwatch.Stop(); time = stopwatch.ElapsedMilliseconds; } } } previousMouse = mouse; }