ctac.MapService.GetLineTiles C# (CSharp) Method

GetLineTiles() public method

public GetLineTiles ( Vector2 center, Vector2 secondPoint, int distance, bool bothDirections ) : Tile>.Dictionary
center Vector2
secondPoint Vector2
distance int
bothDirections bool
return Tile>.Dictionary
        public Dictionary<Vector2, Tile> GetLineTiles(Vector2 center, Vector2 secondPoint, int distance, bool bothDirections)
        {
            var xDiff = secondPoint.x - center.x;
            var zDiff = secondPoint.y - center.y;

            var ret = new Dictionary<Vector2, Tile>()
            {
                { center, mapModel.tiles.Get(center) }
            };
            Tile neighborTile = null;
            for (var d = 1; d <= distance; d++)
            {
                var toCheck = new List<Vector2>(){
                  center.Add(xDiff * d, zDiff * d)
                };
                if (bothDirections)
                {
                    toCheck.Add(center.Add(-xDiff * d, -zDiff * d));
                }

                foreach (var currentDirection in toCheck)
                {
                    //check it's not off the map
                    neighborTile = mapModel.tiles.Get(currentDirection);
                    if (neighborTile != null)
                    {
                        ret[currentDirection] = neighborTile;
                    }
                }
            }
            return ret;
        }