public void SetTargetPosition(Vector2 position) { _targetPosition = position; int currentTargetX = (int)(position.X / Helper.GRID_CELL_SIZE); int currentTargetY = (int)(position.Y / Helper.GRID_CELL_SIZE); if (_prevTargetX != currentTargetX || _prevTargetY != currentTargetY) { _stop = false; _prevTargetX = currentTargetX; _prevTargetY = currentTargetY; _grid.SetStart(Tank.Location); _grid.SetFinish(position); _pathToTarget = _grid.GetPath(); _pathToTarget.Reverse(); if (_pathToTarget.Count > 0) { _pathToTarget.RemoveAt(_pathToTarget.Count - 1); _stop = false; } else { _stop = true; } _cells.Clear(); foreach (Vector2 pos in _pathToTarget) { Cell c = new Cell(pos); c.LoadContent(_content); _cells.Add(c); } if (_pathToTarget.Count > 0) { _pathToTarget[0] = new Vector2( _pathToTarget[0].X + Helper.GRID_CELL_SIZE / 2, _pathToTarget[0].Y + Helper.GRID_CELL_SIZE / 2); _toTargetDirection = _pathToTarget[0] - Tank.Location; _toTargetDirection.Normalize(); } } }