Esempio n. 1
0
    private void PlaceRoadsOnCertainlSides(Tile tile, TileDirection tileDirection)
    {
        int tileX  = tile.x;
        int tileY  = tile.y;
        int offset = tileY % 2;

        //int xLeft = (2 * tileX) + offset;
        //int yLeft = 2 * tileY + 1;
        ////int xTopLeft = 2 * tileX + offset;
        ////int yTopLeft = 2 * tileY;
        //int xBottomRight = 2 * tileX + offset;
        //int yBottomRight = 2 * tileY + 2;
        //int xBottomLeft = 2 * tileX + 1 + offset;
        //int yBottomLeft = 2 * tileY + 2;


        //left
        if (tileDirection == TileDirection.Left)
        {
            int        xLeft = 2 * tileX + offset;
            int        yLeft = 2 * tileY + 1;
            GameObject road  = (GameObject)Instantiate(roadPrefab);
            road.transform.parent = roadSpotsGameObject.transform;
            RoadData roadData = road.GetComponent <RoadData>();
            roadData.setPosition(xLeft, yLeft);

            road.transform.name = "Road (" + xLeft + "," + yLeft + ")";

            Vector2 gridPos  = new Vector2(tileX, tileY);
            Vector3 worldPos = CalcWorldPosTiles(gridPos);
            worldPos.x = worldPos.x - (hexWidth / 2);
            road.transform.position = worldPos;
            roads[xLeft, yLeft]     = new Road(road, xLeft, yLeft);
        }

        ////top left
        //if (tileDirection == TileDirection.TopLeft) {
        //    GameObject road = (GameObject)Instantiate(roadPrefab);
        //    road.transform.parent = roadSpotsGameObject.transform;
        //    road.transform.name = "Road (" + xLeft + "," + yLeft + ")";

        //    Vector2 gridPos = new Vector2(tileX, tileY);
        //    Vector3 worldPos = CalcWorldPosTiles(gridPos);
        //    worldPos.x = worldPos.x - (hexWidth / 4);
        //    worldPos.y = worldPos.y + (hexHeight / 3);
        //    road.transform.position = worldPos;
        //    road.transform.Rotate(0, 0, -60, Space.Self);
        //    roads[xTopLeft, yTopLeft] = new Road(road, xTopLeft, yTopLeft);
        //}


        //bottom right
        if (tileDirection == TileDirection.BottomRight)
        {
            int        xBottomRight = 2 * tileX + 1 + offset;
            int        yBottomRight = 2 * tileY + 2;
            GameObject road         = (GameObject)Instantiate(roadPrefab);
            road.transform.parent = roadSpotsGameObject.transform;
            RoadData roadData = road.GetComponent <RoadData>();
            roadData.setPosition(xBottomRight, yBottomRight);

            road.transform.name = "Road (" + xBottomRight + "," + yBottomRight + ")";

            Vector2 gridPos  = new Vector2(tileX, tileY);
            Vector3 worldPos = CalcWorldPosTiles(gridPos);
            worldPos.x = worldPos.x + ((hexWidth / 4) - (gap / 2));
            worldPos.y = worldPos.y - (hexHeight / 3) - (gap);
            road.transform.position = worldPos;
            road.transform.Rotate(0, 0, -60, Space.Self);
            roads[xBottomRight, yBottomRight] = new Road(road, xBottomRight, yBottomRight);
        }


        //bottom left
        if (tileDirection == TileDirection.BottomLeft)
        {
            int        xBottomLeft = 2 * tileX + offset;
            int        yBottomLeft = 2 * tileY + 2;
            GameObject road        = (GameObject)Instantiate(roadPrefab);
            road.transform.parent = roadSpotsGameObject.transform;
            RoadData roadData = road.GetComponent <RoadData>();
            roadData.setPosition(xBottomLeft, yBottomLeft);

            road.transform.name = "Road (" + xBottomLeft + "," + yBottomLeft + ")";

            Vector2 gridPos  = new Vector2(tileX, tileY);
            Vector3 worldPos = CalcWorldPosTiles(gridPos);
            worldPos.x = worldPos.x - (hexWidth / 4);
            worldPos.y = worldPos.y - (hexHeight / 3) - (gap);
            road.transform.position = worldPos;
            road.transform.Rotate(0, 0, 60, Space.Self);
            roads[xBottomLeft, yBottomLeft] = new Road(road, xBottomLeft, yBottomLeft);
        }
    }
Esempio n. 2
0
    private void PlaceRoadsOnAllSides(Tile tile)
    {
        int tileX  = tile.x;
        int tileY  = tile.y;
        int offset = tileY % 2;
        int xLeft  = 2 * tileX + offset;
        int yLeft  = 2 * tileY + 1;
        //int xTopLeft = 2 * tileX + offset;
        //int yTopLeft = 2 * tileY;
        int xBottomRight = 2 * tileX + 1 + offset;
        int yBottomRight = 2 * tileY + 2;
        int xBottomLeft  = 2 * tileX + offset;
        int yBottomLeft  = 2 * tileY + 2;

        //left
        //      roads[2 * x + offset, 2 * y + 1],
        //    //top left
        //    roads[2 * x + offset, 2 * y],
        //    //top right
        //    roads[2 * x + 1 + offset, 2 * y],
        //    //right
        //    roads[2 * x + 2 + offset, 2 * y + 1],
        //    //bottom right
        //    roads[2 * x + 1 + offset, 2 * y + 2],
        //    //bottom left
        //    roads[2 * x + offset, 2 * y + 2]

        //left
        GameObject road = (GameObject)Instantiate(roadPrefab);

        road.transform.parent = roadSpotsGameObject.transform;
        RoadData roadData = road.GetComponent <RoadData>();

        roadData.setPosition(xLeft, yLeft);


        //road.transform.parent = tile.gameObject.transform;
        road.transform.name = "Road (" + xLeft + "," + yLeft + ")";

        Vector2 gridPos  = new Vector2(tileX, tileY);
        Vector3 worldPos = CalcWorldPosTiles(gridPos);

        worldPos.x = worldPos.x - ((hexWidth / 2) + (gap / 2));
        road.transform.position = worldPos;


        roads[xLeft, yLeft] = new Road(road, xLeft, yLeft);

        ////top left
        //road = (GameObject)Instantiate(roadPrefab);
        //road.transform.parent = roadSpotsGameObject.transform;
        ////road.transform.parent = tile.gameObject.transform;

        //road.transform.name = "Road (" + xTopLeft + "," + yTopLeft + ")";

        //gridPos = new Vector2(tileX, tileY);
        //worldPos = CalcWorldPosTiles(gridPos);
        //worldPos.x = worldPos.x - (hexWidth / 4) - (gap/2);
        //worldPos.y = worldPos.y + (hexHeight /3) + (gap/2);
        //road.transform.position = worldPos;
        //road.transform.Rotate(0, 0, -60, Space.Self);
        //roads[xTopLeft, yTopLeft] = new Road(road, xTopLeft, yTopLeft);

        //bottom right
        road = (GameObject)Instantiate(roadPrefab);
        road.transform.parent = roadSpotsGameObject.transform;
        //road.transform.parent = tile.gameObject.transform;
        roadData = road.GetComponent <RoadData>();
        roadData.setPosition(xBottomRight, yBottomRight);

        road.transform.name = "Road (" + xBottomRight + "," + yBottomRight + ")";

        gridPos    = new Vector2(tileX, tileY);
        worldPos   = CalcWorldPosTiles(gridPos);
        worldPos.x = worldPos.x + ((hexWidth / 4) - (gap / 2));
        worldPos.y = worldPos.y - (hexHeight / 3) - (gap);
        road.transform.position = worldPos;
        road.transform.Rotate(0, 0, -60, Space.Self);
        roads[xBottomRight, yBottomRight] = new Road(road, xBottomRight, yBottomRight);


        //bottom left
        road = (GameObject)Instantiate(roadPrefab);
        road.transform.parent = roadSpotsGameObject.transform;
        //road.transform.parent = tile.gameObject.transform;
        roadData = road.GetComponent <RoadData>();
        roadData.setPosition(xBottomLeft, yBottomLeft);

        road.transform.Rotate(0, 0, 60, Space.Self);
        road.transform.name = "Road (" + xBottomLeft + "," + yBottomLeft + ")";

        gridPos    = new Vector2(tileX, tileY);
        worldPos   = CalcWorldPosTiles(gridPos);
        worldPos.x = worldPos.x - (hexWidth / 4) - (gap / 2);
        worldPos.y = worldPos.y - (hexHeight / 3) - (gap);
        road.transform.position         = worldPos;
        roads[xBottomLeft, yBottomLeft] = new Road(road, xBottomLeft, yBottomLeft);
    }