Beispiel #1
0
    //周囲の同じ種別の地形をカウント
    static private CountInfo countSameCell(int treatCount, Vector2Int size, WorldDataConst.EachTerrainData[] tileMap, int x, int y)
    {
        int cellCount = 0;

        WorldDataConst.EachTerrainData currentTile     = tileMap[y * size.x + x];
        WorldDataConst.TileType        currentTileType = currentTile.type;
        WorldDataConst.TileType        diffTileType    = WorldDataConst.TileType.NONE;

        for (int i = 0; i < treatCount; i++)
        {
            Vector2Int targetPos = treatPosition(size, x + (int)WorldDataConst.DIRECTIONS[i].x, y + (int)WorldDataConst.DIRECTIONS[i].y);
            //           Debug.Log(targetPos.x + " " + size.x + " " +  targetPos.y + " "+size.y);
            WorldDataConst.TileType roundTileType = tileMap[targetPos.y * size.x + targetPos.x].type;
            if (currentTileType != roundTileType)
            {
                cellCount++;
                diffTileType = roundTileType;
            }
        }
        return(new CountInfo()
        {
            currentTile = currentTile,
            diffType = diffTileType,
            count = cellCount
        });
    }
    public void UpdateMap()
    {
        UpdateMapInfoContainer dispContainer;

        DateTime start = DateTime.Now;

        if (updateList4Disp != null)
        {
            while (updateList4Disp.TryDequeue(out dispContainer))
            {
                while (dispContainer.nextReadIndex < dispContainer.tiles.Length)
                {
                    EachTerrainTileData eachtile = dispContainer.tiles[dispContainer.nextReadIndex];
                    if (eachtile != null)
                    {
                        WorldDataConst.TileType currentTileType = eachtile.type;

                        Vector3Int currentPos = new Vector3Int(eachtile.x, eachtile.y, 0);
                        if (
                            (player.groundTilemap.GetTile(currentPos) == null) ||
                            (!player.groundTilemap.GetTile(currentPos).Equals(currentTileType))
                            )
                        {
                            if ((currentTileType == WorldDataConst.TileType.FIELD))
                            {
                                player.groundTilemap.SetTile(currentPos, field);
                            }
                            else
                            {
                                player.groundTilemap.SetTile(currentPos, sea);
                            }
                        }
                    }
                    dispContainer.nextReadIndex++;
                    DateTime current = DateTime.Now;

                    if ((current - start).TotalMilliseconds > 100)
                    {
                        current = start;
                        break;
                    }
                }
                if (dispContainer.nextReadIndex < dispContainer.tiles.Length)
                {
                    updateList4Disp.Enqueue(dispContainer);
                    break;
                }
            }
        }
    }
Beispiel #3
0
    //初期マップを生成
    static private WorldDataConst.EachTerrainData[] generateFirstTileMap(
        System.Random rnd,
        Vector2Int size,
        List <BandSeed> verticalBands,
        List <BandSeed> horizontalBands,
        List <TerrainSeed> sea_seeds,
        List <TerrainSeed> field_seeds
        )
    {
        WorldDataConst.EachTerrainData[] tileMap = new WorldDataConst.EachTerrainData[size.x * size.y];
        for (int y = 0; y < size.y; y++)
        {
            bool verticalSplitFlag = false;
            for (int i = 0; i < verticalBands.Count; i++)
            {
                if ((verticalBands[i].position * verticalBands[i].bandWidth <= y) && ((verticalBands[i].position + 1) * verticalBands[i].bandWidth > y))
                {
                    verticalSplitFlag = true;
                    break;
                }
            }
            for (int x = 0; x < size.x; x++)
            {
                WorldDataConst.EachTerrainData tile = new WorldDataConst.EachTerrainData();
                tile.x = x;
                tile.y = y;
                WorldDataConst.TileType type = WorldDataConst.TileType.NONE;

                for (int i = 0; i < sea_seeds.Count; i++)
                {
                    if ((Mathf.Pow((sea_seeds[i].position.x - x), 2) + Mathf.Pow((sea_seeds[i].position.y - y), 2)) < Mathf.Pow(sea_seeds[i].radius, 2))
                    {
                        type = WorldDataConst.TileType.SEA;
                        break;
                    }
                }

                if (type == WorldDataConst.TileType.NONE)
                {
                    for (int i = 0; i < field_seeds.Count; i++)
                    {
                        if ((Mathf.Pow((field_seeds[i].position.x - x), 2) + Mathf.Pow((field_seeds[i].position.y - y), 2)) < Mathf.Pow(field_seeds[i].radius, 2))
                        {
                            type = WorldDataConst.TileType.FIELD;
                            break;
                        }
                    }
                }
                if ((type == WorldDataConst.TileType.NONE) && (verticalSplitFlag))
                {
                    type = WorldDataConst.TileType.SEA;
                }

                if (type == WorldDataConst.TileType.NONE)
                {
                    for (int i = 0; i < horizontalBands.Count; i++)
                    {
                        if ((horizontalBands[i].position * horizontalBands[i].bandWidth <= x) && ((horizontalBands[i].position + 1) * horizontalBands[i].bandWidth > x))
                        {
                            type = WorldDataConst.TileType.SEA;
                            break;
                        }
                    }
                }
                if (type == WorldDataConst.TileType.NONE)
                {
                    type = WorldDataConst.TileType.SEA;
                    if (rnd.Next(0, 2) == 0)
                    {
                        type = WorldDataConst.TileType.FIELD;
                    }
                }

                tile.type = type;
                tileMap[y * size.x + x] = tile;
            }
        }
        return(tileMap);
    }