Ejemplo n.º 1
0
    public WorldMap GenerateNewMap(WorldMapConfig config)
    {
        int length = config.length;
        int width  = config.width;

        if (length < 1)
        {
            throw new ArgumentOutOfRangeException(string.Format("Invalid length ({0})", length));
        }

        if (width < 1)
        {
            throw new ArgumentOutOfRangeException(string.Format("Invalid width ({0})", width));
        }

        rng.Reset(config.seed);

        HexGrid <float> heightMap = GenerateHeightMap(length, width, config.continents, config.seaLevel * 0.5f, config.terrainFrequency, config.terrainOctaves);
        HexGrid <float> biomeMap  = GenerateBiomeMap(length, width, config.temperature, config.surfaceFrequency, config.surfaceOctaves, config.forestFrequency, config.forestOctaves);

        WorldMap map = new WorldMap(length, width);

        map.For(delegate(int x, int y)
        {
            map[x, y] = new WorldMapTile(x, y, heightMap[x, y], biomeMap[x, y]);
        });

        return(map);
    }
Ejemplo n.º 2
0
    public void InitWorldMapObject(WorldMapTile tiledata)
    {
        tile = tiledata;

        sr.sprite          = Resources.Load <SpriteAtlas>(FilePath.TileSetAtlas).GetSprite(tile.filename);
        transform.position = new Vector3(tile.position.X, tile.position.Y, 0);
    }
    private void DrawTilePreview(int x, int y)
    {
        WorldMapTile tile     = map[x, y];
        int          tileType = ReadTileType(tile);

        WorldMapTile.Landform landform = (WorldMapTile.Landform)((tileType >> 16) & 7);
        WorldMapTile.Biome    biome    = (WorldMapTile.Biome)(tileType >> 19);

        MeshRenderer[] landformPrefabs = tilePrefabs[(int)landform];
        MeshRenderer   tilePrefab      = landformPrefabs[Math.Min(landformPrefabs.Length - 1, (int)biome)];

        Transform cell = Instantiate(tilePrefab).transform;

        cell.parent          = canvas.transform;
        cell.localPosition   = WorldMap.ToWorldCoordinates(x, y, tileSize);
        cell.localScale     *= tileSize;
        cell.gameObject.name = tile.ToString();

        if (biome == WorldMapTile.Biome.FOREST)
        {
            if (landform == WorldMapTile.Landform.PLAIN)
            {
                Transform forest = Instantiate(forestPrefab).transform;
                forest.parent        = cell;
                forest.localPosition = Vector3.zero;
                forest.localScale    = Vector3.one;
                forest.Rotate(0, 0, UnityEngine.Random.Range(0, 360));
                forest.gameObject.name = "Forest";
            }
            else if (landform == WorldMapTile.Landform.HILL)
            {
                Transform forest = Instantiate(forestPrefab).transform;
                forest.parent        = cell;
                forest.localPosition = new Vector3(0, 0, 0.2f);
                forest.localScale    = 0.9f * Vector3.one;
                forest.Rotate(0, 0, UnityEngine.Random.Range(0, 360));
                forest.gameObject.name = "Forest";
            }
        }

        //Transform wrappedTile = Instantiate(tilePrefab).transform;
        //wrappedTile.parent = canvas.transform;
        //wrappedTile.localPosition = WorldMap.ToWorldCoordinates(x + length, y, tileSize) + new Vector3(tileSize, 0, 0);
        //wrappedTile.localScale *= tileSize;
        //wrappedTile.gameObject.name = "~" + tile.ToString();
    }
Ejemplo n.º 4
0
 public WorldMapTile(WorldMapTile other)
 {
     _axialCoordinates = new IntVector2(other._axialCoordinates);
     _altitude         = other.altitude;
 }
    private int ReadTileType(WorldMapTile tile)
    {
        int tileType = 0;

        float latitude = Math.Abs(WorldMap.ToGeographicCoordinates(tile, length, width).y * 2f / width);

        int numLandform = (int)WorldMapTile.Landform.count;

        if (tile.v < 2 || tile.v > width - 3)
        {
            BitOperationUtility.WriteBit(ref tileType, (int)WorldMapTile.Landform.GLACIER, 1);
            tileType += (int)WorldMapTile.Landform.GLACIER << 16;
        }
        else if (tile.altitude < 0)
        {
            BitOperationUtility.WriteBit(ref tileType, (int)WorldMapTile.Landform.OCEAN, 1);
            tileType += (int)WorldMapTile.Landform.OCEAN << 16;
        }
        else if (tile.altitude < 25 + rainfall * 2)
        {
            BitOperationUtility.WriteBit(ref tileType, (int)WorldMapTile.Landform.LAKE, 1);
            tileType += (int)WorldMapTile.Landform.LAKE << 16;
        }
        else if (tile.altitude > 65 - roughness)
        {
            BitOperationUtility.WriteBit(ref tileType, (int)WorldMapTile.Landform.MOUNTAIN, 1);
            tileType += (int)WorldMapTile.Landform.MOUNTAIN << 16;
        }
        else if (tile.altitude > 60 - roughness)
        {
            BitOperationUtility.WriteBit(ref tileType, (int)WorldMapTile.Landform.HILL, 1);
            tileType += (int)WorldMapTile.Landform.HILL << 16;
        }
        else
        {
            BitOperationUtility.WriteBit(ref tileType, (int)WorldMapTile.Landform.PLAIN, 1);
            tileType += (int)WorldMapTile.Landform.PLAIN << 16;
        }

        if (tile.biome < 0 && latitude > 0.55f + temperature * 0.025f)
        {
            BitOperationUtility.WriteBit(ref tileType, numLandform + (int)WorldMapTile.Biome.TUNDRA, 1);
            tileType += (int)WorldMapTile.Biome.TUNDRA << 19;
        }
        else if (tile.biome == 0 && latitude < 0.35f + temperature * 0.025f)
        {
            BitOperationUtility.WriteBit(ref tileType, numLandform + (int)WorldMapTile.Biome.DESERT, 1);
            tileType += (int)WorldMapTile.Biome.DESERT << 19;
        }
        else if (tile.biome > 60 - rainfall)
        {
            BitOperationUtility.WriteBit(ref tileType, numLandform + (int)WorldMapTile.Biome.FOREST, 1);
            tileType += (int)WorldMapTile.Biome.FOREST << 19;
        }
        else
        {
            BitOperationUtility.WriteBit(ref tileType, numLandform + (int)WorldMapTile.Biome.GRASSLAND, 1);
            tileType += (int)WorldMapTile.Biome.GRASSLAND << 19;
        }

        return(tileType);
    }