예제 #1
0
    void SetTile(GridCell cell)
    {
        if (cell.data.HasRoad && cell.data.HasWater)
        {
            SetTile(new Vector2(4, 0));
            // draw bridge
        }
        else if (cell.data.HasRoad)
        {
            var neighbors = cell.AreNeighborsRoad();
            if (neighbors == 255)   // 1111 1111
            {
                SetTile(TileSpriteMap.ROAD_8);
            }
            else if (neighbors == 85)     // 1111 1101
            {
                SetTile(TileSpriteMap.ROAD_0);
            }
            else if (neighbors == 85)     // 0101 0101
            {
                SetTile(TileSpriteMap.ROAD_0);
            }
            else if (neighbors == 215)     // 1101 0111
            {
                SetTile(TileSpriteMap.ROAD_EWST_2);
            }
            else if (neighbors == 125)     // 0111 1101
            {
                SetTile(TileSpriteMap.ROAD_EWNT_2);
            }
            else if (neighbors == 245)     // 1111 0101
            {
                SetTile(TileSpriteMap.ROAD_NSET_2);
            }
            else if (neighbors == 95)     // 1111 1010
            {
                SetTile(TileSpriteMap.ROAD_NSWT_2);
            }
            else if (cell.IsNeighborRoad(GridDirection.E) &&
                     cell.IsNeighborRoad(GridDirection.W) &&
                     cell.IsNeighborRoad(GridDirection.N) &&
                     cell.IsNeighborRoad(GridDirection.NE) &&
                     cell.IsNeighborRoad(GridDirection.NW))
            {
                SetTile(TileSpriteMap.ROAD_EWS_2);
            }
            else if (cell.IsNeighborRoad(GridDirection.E) &&
                     cell.IsNeighborRoad(GridDirection.W) &&
                     cell.IsNeighborRoad(GridDirection.S) &&
                     cell.IsNeighborRoad(GridDirection.SE) &&
                     cell.IsNeighborRoad(GridDirection.SW))
            {
                SetTile(TileSpriteMap.ROAD_EWN_2);
            }
            else if (cell.IsNeighborRoad(GridDirection.S) &&
                     cell.IsNeighborRoad(GridDirection.N) &&
                     cell.IsNeighborRoad(GridDirection.E) &&
                     cell.IsNeighborRoad(GridDirection.NE) &&
                     cell.IsNeighborRoad(GridDirection.SE))
            {
                SetTile(TileSpriteMap.ROAD_NSW_2);
            }
            else if (cell.IsNeighborRoad(GridDirection.S) &&
                     cell.IsNeighborRoad(GridDirection.N) &&
                     cell.IsNeighborRoad(GridDirection.W) &&
                     cell.IsNeighborRoad(GridDirection.NW) &&
                     cell.IsNeighborRoad(GridDirection.SW))
            {
                SetTile(TileSpriteMap.ROAD_NSE_2);
            }
            else if (cell.IsNeighborRoad(GridDirection.E) &&
                     cell.IsNeighborRoad(GridDirection.W) &&
                     cell.IsNeighborRoad(GridDirection.N))
            {
                SetTile(TileSpriteMap.ROAD_NT_1);
            }
            else if (cell.IsNeighborRoad(GridDirection.E) &&
                     cell.IsNeighborRoad(GridDirection.W) &&
                     cell.IsNeighborRoad(GridDirection.S))
            {
                SetTile(TileSpriteMap.ROAD_ST_1);
            }
            else if (cell.IsNeighborRoad(GridDirection.S) &&
                     cell.IsNeighborRoad(GridDirection.N) &&
                     cell.IsNeighborRoad(GridDirection.E))
            {
                SetTile(TileSpriteMap.ROAD_WT_1);
            }
            else if (cell.IsNeighborRoad(GridDirection.S) &&
                     cell.IsNeighborRoad(GridDirection.N) &&
                     cell.IsNeighborRoad(GridDirection.W))
            {
                SetTile(TileSpriteMap.ROAD_ET_1);
            }
            else if (cell.IsNeighborRoad(GridDirection.E) &&
                     cell.IsNeighborRoad(GridDirection.N))
            {
                SetTile(TileSpriteMap.ROAD_WN_1);
            }
            else if (cell.IsNeighborRoad(GridDirection.E) &&
                     cell.IsNeighborRoad(GridDirection.S))
            {
                SetTile(TileSpriteMap.ROAD_WS_1);
            }
            else if (cell.IsNeighborRoad(GridDirection.W) &&
                     cell.IsNeighborRoad(GridDirection.S))
            {
                SetTile(TileSpriteMap.ROAD_ES_1);
            }
            else if (cell.IsNeighborRoad(GridDirection.W) &&
                     cell.IsNeighborRoad(GridDirection.N))
            {
                SetTile(TileSpriteMap.ROAD_EN_1);
            }
            else if (cell.IsNeighborRoad(GridDirection.E) &&
                     cell.IsNeighborRoad(GridDirection.W))
            {
                SetTile(TileSpriteMap.ROAD_EW_1);
            }
            else if (cell.IsNeighborRoad(GridDirection.S) &&
                     cell.IsNeighborRoad(GridDirection.N))
            {
                SetTile(TileSpriteMap.ROAD_NS_1);
            }
            else if (cell.IsNeighborRoad(GridDirection.E))
            {
                SetTile(TileSpriteMap.ROAD_W_END);
            }
            else if (cell.IsNeighborRoad(GridDirection.W))
            {
                SetTile(TileSpriteMap.ROAD_E_END);
            }
            else if (cell.IsNeighborRoad(GridDirection.N))
            {
                SetTile(TileSpriteMap.ROAD_S_END);
            }
            else if (cell.IsNeighborRoad(GridDirection.S))
            {
                SetTile(TileSpriteMap.ROAD_N_END);
            }
            else
            {
                SetTile(TileSpriteMap.ROAD_0);
            }

            // draw road
        }
        else if (cell.data.HasWater)
        {
            SetTile(new Vector2(0, 4));
            // draw water
        }
        else if (cell.data.HasBuilding)
        {
            // draw building
            SetTile(new Vector2(6, 6));
        }
        else
        {
            // draw ground
            SetTile(new Vector2(6, 5));
        }
    }