public void Update(float elapsed, ComFigureController controller) { if (Finished) { return; } var current = controller.GetTilePosition(); if (_wayPoints == null) { _wayPoints = new Queue <PlaceNode>(controller.NodeMap.FindWayTo(current, _toReachNode)); _currentNodeToReach = _wayPoints.Dequeue(); } var toReachVector = controller.Level.GetWorldFromTilePositionCentered(_currentNodeToReach.TilePosition); var distance = toReachVector - controller.Figure.Position; var moveStep = controller.Figure.Speed * elapsed; if (current == _currentNodeToReach.TilePosition && distance.LengthSquared() < moveStep * moveStep) { ((FigureImp)controller.Figure).Position = toReachVector; controller.SetMoveDirectionTo(Vector2.Zero); if (_wayPoints.Count == 0) { controller.SetMoveDirectionTo(Vector2.Zero); Finished = true; } else { _currentNodeToReach = _wayPoints.Dequeue(); } } if (_currentNodeToReach.TilePosition.X < current.X) { controller.SetMoveDirectionTo(-Vector2.UnitX); } else if (_currentNodeToReach.TilePosition.X > current.X) { controller.SetMoveDirectionTo(Vector2.UnitX); } else if (_currentNodeToReach.TilePosition.Y < current.Y) { controller.SetMoveDirectionTo(-Vector2.UnitY); } else if (_currentNodeToReach.TilePosition.Y > current.Y) { controller.SetMoveDirectionTo(Vector2.UnitY); } else if (distance.LengthSquared() > moveStep * moveStep) { controller.SetMoveDirectionTo(Vector2.Normalize(distance)); } }
public void setInitConfig(int width, int height, List <Point> exits) { xCount = width; yCount = height; this.exits = exits; nodes = new PlaceNode[width, height]; //初始化地点节点 for (int i = 0; i < getWidth(); ++i) { for (int j = 0; j < getHeight(); ++j) { nodes[i, j] = new PlaceNode(); } } }
public NeighborNode(PlaceNode node, int direction) { heightLine = node.heightLine; this.direction = direction; }
public WayPointTask(PlaceNode toReach) { _toReachNode = toReach; }