示例#1
0
        private IList <Tile> BuildSquare(int sideLength, bool centerOrigin)
        {
            var square       = new List <Tile>();
            var increment    = TileShape.Square.DoubleIncrement ? 2 : 1;
            var centerOffset = centerOrigin ? (((sideLength * increment) / 2) - 1) : 0;

            // Loop through rows x columns
            for (var rowIndex = 0; rowIndex < sideLength; rowIndex++)
            {
                var row = (rowIndex * increment) - centerOffset;
                for (var colIndex = 0; colIndex < sideLength; colIndex++)
                {
                    var col = (colIndex * increment) - centerOffset;
                    var cubicCoordinates = CubicCoordinates.FromOffset(
                        new OffsetCoordinates(row: row, col: col)
                        );
                    square.Add(new Tile(
                                   cubicCoordinates: cubicCoordinates,
                                   tileShape: TileShape.Square,
                                   terrain: Terrain.Water
                                   ));
                }
            }

            // return the square tiles
            return(square);
        }
示例#2
0
        public CubicCoordinates FindHex(Vector2f pixelCoordinates)
        {
            pixelCoordinates.X -= HorizontalSize / 2;
            pixelCoordinates.Y -= VerticalSize / 2;

            var position = new Vector2f(
                (pixelCoordinates.X * (float)Math.Sqrt(3) / 3f - pixelCoordinates.Y / 3f) / EdgeLength,
                pixelCoordinates.Y * 2 / 3 / EdgeLength
                );

            var hexFloatingPoint = new Vector3f(position.X, -position.X - position.Y, position.Y);

            var roundedPosition = new CubicCoordinates(
                (int)Math.Round(hexFloatingPoint.X),
                (int)Math.Round(hexFloatingPoint.Y),
                (int)Math.Round(hexFloatingPoint.Z));

            var differences = new Vector3f(
                Math.Abs(hexFloatingPoint.X - roundedPosition.X),
                Math.Abs(hexFloatingPoint.Y - roundedPosition.Y),
                Math.Abs(hexFloatingPoint.Z - roundedPosition.Z)
                );

            if (differences.X > differences.Y && differences.X > differences.Z)
            {
                roundedPosition.X = -roundedPosition.Y - roundedPosition.Z;
            }
            else if (differences.Y > differences.Z)
            {
                roundedPosition.Y = -roundedPosition.X - roundedPosition.Z;
            }
            else
            {
                roundedPosition.Z = -roundedPosition.X - roundedPosition.Y;
            }

            return(roundedPosition);
        }
示例#3
0
        private IList <Tile> BuildRectangle(int columnCount, int rowCount, TileShape tileShape)
        {
            var rectangle = new List <Tile>();
            var increment = tileShape.DoubleIncrement ? 2 : 1;

            for (var rowIndex = 0; rowIndex < rowCount; rowIndex++)
            {
                var row = rowIndex * increment;
                for (var colIndex = 0; colIndex < columnCount; colIndex++)
                {
                    var col = colIndex * increment;
                    var cubicCoordinates = CubicCoordinates.FromOffset(
                        new OffsetCoordinates(col: col, row: row)
                        );
                    rectangle.Add(new Tile(
                                      cubicCoordinates: cubicCoordinates,
                                      tileShape: tileShape,
                                      terrain: Terrain.Water
                                      ));
                }
            }
            return(rectangle);
        }
示例#4
0
        private IList <Tile> BuildRegularHexagon(int sideLength, bool centerOrigin, TileShape tileShape = null)
        {
            var hexagon      = new List <Tile>();
            var increment    = TileShape.Hexagon.DoubleIncrement ? 2 : 1;
            var maxLength    = (2 * sideLength) - 1;
            var centerOffset = centerOrigin ? ((sideLength * increment) - 1) : 0;

            if (tileShape == null)
            {
                tileShape = TileShape.Hexagon;
            }

            // Build top portion of hexagon
            var rowLength = sideLength - 1;
            var rowIndex  = -1;

            while (rowLength < (maxLength - 1))
            {
                rowLength++;
                rowIndex++;
                var topRow    = (rowIndex * increment) - centerOffset;
                var colOffset = Convert.ToInt32(Math.Floor((maxLength - rowLength) / 2.0)); // TODO:  Fix bug where column offset produces fractional value
                for (var colIndex = 0; colIndex < rowLength; colIndex++)
                {
                    var col = ((colIndex + colOffset) * increment) - centerOffset;
                    hexagon.Add(new Tile(
                                    cubicCoordinates: CubicCoordinates.FromOffset(
                                        new OffsetCoordinates(row: topRow, col: col)
                                        ),
                                    tileShape: tileShape,
                                    terrain: Terrain.Water
                                    ));
                }
            }

            // Build middle row of hexagon
            rowIndex++;
            rowLength = maxLength;
            var middleRow = (rowIndex * increment) - centerOffset;

            for (var colIndex = 0; colIndex < rowLength; colIndex++)
            {
                var col = (colIndex * increment) - centerOffset;
                hexagon.Add(new Tile(
                                cubicCoordinates: CubicCoordinates.FromOffset(
                                    new OffsetCoordinates(row: middleRow, col: col)
                                    ),
                                tileShape: tileShape,
                                terrain: Terrain.Water
                                ));
            }

            // Build bottom portion of hexagon
            while (rowLength > sideLength)
            {
                rowLength--;
                rowIndex++;
                var bottomRow = (rowIndex * increment) - centerOffset;
                var colOffset = Convert.ToInt32(Math.Floor((maxLength - rowLength) / 2.0)); // TODO:  Fix bug where column offset produces fractional value
                for (var colIndex = 0; colIndex < rowLength; colIndex++)
                {
                    var col = ((colIndex + colOffset) * increment) - centerOffset;
                    hexagon.Add(new Tile(
                                    cubicCoordinates: CubicCoordinates.FromOffset(
                                        new OffsetCoordinates(row: bottomRow, col: col)
                                        ),
                                    tileShape: tileShape,
                                    terrain: Terrain.Water
                                    ));
                }
            }

            // return the hexagon tiles
            return(hexagon);
        }
示例#5
0
        private IList <Tile> BuildRegularOctagon(int sideLength, bool centerOrigin)
        {
            var octagon      = new List <Tile>();
            var increment    = TileShape.Octagon.DoubleIncrement ? 2 : 1;
            var maxLength    = sideLength + 2 * (sideLength - 1);
            var centerOffset = centerOrigin ? (((maxLength * increment) / 2) - 1) : 0;

            // Build top portion of octagon
            var rowLength = sideLength - 2;
            var rowIndex  = -1;

            while (rowLength < (maxLength - 2))
            {
                rowLength += 2;
                rowIndex++;
                var row       = (rowIndex * increment) - centerOffset;
                var colOffset = (maxLength - rowLength) / 2;
                for (var colIndex = 0; colIndex < rowLength; colIndex++)
                {
                    var col = ((colIndex + colOffset) * increment) - centerOffset;
                    octagon.Add(new Tile(
                                    cubicCoordinates: CubicCoordinates.FromOffset(
                                        new OffsetCoordinates(row: row, col: col)
                                        ),
                                    tileShape: TileShape.Octagon,
                                    terrain: Terrain.Water
                                    ));
                }
            }

            // Build middle portion of octagon
            rowIndex++;
            var middleRowCount = rowIndex + sideLength;
            int middleRowIndex;

            for (middleRowIndex = rowIndex; middleRowIndex < middleRowCount; middleRowIndex++)
            {
                rowLength = maxLength;
                var row = (middleRowIndex * increment) - centerOffset;
                for (var colIndex = 0; colIndex < rowLength; colIndex++)
                {
                    var col = (colIndex * increment) - centerOffset;
                    octagon.Add(new Tile(
                                    cubicCoordinates: CubicCoordinates.FromOffset(
                                        new OffsetCoordinates(row: row, col: col)
                                        ),
                                    tileShape: TileShape.Octagon,
                                    terrain: Terrain.Water
                                    ));
                }
            }
            rowIndex = middleRowIndex;

            // Build bottom portion of octagon
            rowIndex--;
            while (rowLength > sideLength)
            {
                rowLength -= 2;
                rowIndex++;
                var row       = (rowIndex * increment) - centerOffset;
                var colOffset = (maxLength - rowLength) / 2;
                for (var colIndex = 0; colIndex < rowLength; colIndex++)
                {
                    var col = ((colIndex + colOffset) * increment) - centerOffset;
                    octagon.Add(new Tile(
                                    cubicCoordinates: CubicCoordinates.FromOffset(
                                        new OffsetCoordinates(row: row, col: col)
                                        ),
                                    tileShape: TileShape.Octagon,
                                    terrain: Terrain.Water
                                    ));
                }
            }

            // return the octagon tiles
            return(octagon);
        }
 public bool IsEqualTo(CubicCoordinates other) => other.X == X && other.Y == Y && other.Z == Z;
示例#7
0
 public Tile(CubicCoordinates cubicCoordinates, TileShape tileShape, Terrain terrain)
 {
     CubicCoordinates = cubicCoordinates;
     TileShape        = tileShape;
     Terrain          = terrain;
 }