Example #1
0
        private int DrawFromVertex2(IntVector2 topLeftCell, HexSprite currentSprite, IntVector2 currentCell, List <IntVector2> gridCells, List <Vector3> vertexList)
        {
            IntVector2 nextCell;

            // compare the coordinates of the next
            // if current x even, the next cell on the same y level is up; if odd, it's down
            // if even and x, y or if odd and x, y-1
            if (currentCell.x % 2 == 0)
            {
                nextCell = gridCells.FirstOrDefault(c => c.x == currentCell.x + 1 && c.y == currentCell.y);
            }
            else
            {
                nextCell = gridCells.FirstOrDefault(c => c.x == currentCell.x + 1 && c.y == currentCell.y - 1);
            }

            if (nextCell != null)
            {
                // we need 6->1 of the next cell
                HexSprite nextSprite = _cells[nextCell.x, nextCell.y].GetComponent <HexSprite>();
                vertexList.Add(nextSprite.FindVertex1());
                return(DrawFromVertex1(topLeftCell, nextSprite, nextCell, gridCells, vertexList));
            }
            else
            {
                // vertex 2 should not touch the topLeftHex, so draw 2 -> 3 on this cell and continue
                vertexList.Add(currentSprite.FindVertex3());
                return(DrawFromVertex3(topLeftCell, currentSprite, currentCell, gridCells, vertexList));
            }
        }
Example #2
0
        private int DrawFromVertex6(IntVector2 topLeftCell, HexSprite currentSprite, IntVector2 currentCell, List <IntVector2> gridCells, List <Vector3> vertexList)
        {
            IntVector2 nextCell;

            // compare the coordinates of the next
            // if current x even, the next cell on the same y level is up; if odd, it's down
            // if even and x, y or if odd and x, y-1
            if (currentCell.x % 2 == 0)
            {
                nextCell = gridCells.FirstOrDefault(c => c.x == currentCell.x - 1 && c.y == currentCell.y);
            }
            else
            {
                nextCell = gridCells.FirstOrDefault(c => c.x == currentCell.x - 1 && c.y == currentCell.y - 1);
            }

            if (nextCell != null)
            {
                // we need 4->5 of the next cell
                HexSprite nextSprite = _cells[nextCell.x, nextCell.y].GetComponent <HexSprite>();
                vertexList.Add(nextSprite.FindVertex5());
                return(DrawFromVertex5(topLeftCell, nextSprite, nextCell, gridCells, vertexList));
            }
            else
            {
                // see if the top left hex is to our top left
                if ((currentCell.x % 2 == 0 && topLeftCell.x == currentCell.x - 1 && topLeftCell.y == currentCell.y) ||
                    (currentCell.x % 2 == 1 && topLeftCell.x == currentCell.x - 1 && topLeftCell.y == currentCell.y - 1))
                {
                    return(4);
                }
                else
                {
                    // draw 6->1 on this cell and continue
                    vertexList.Add(currentSprite.FindVertex1());
                    return(DrawFromVertex1(topLeftCell, currentSprite, currentCell, gridCells, vertexList));
                }
            }
        }