/// <summary>
    /// Generate the voronoi diagram
    /// </summary>
    public void GenerateVoronoi()
    {
        /*
         * Test seeds
         * 1056279151
         * 1188430406
         * 916508404
         * 1161899265
         * 1969582979
         * 380612368
         * 1517822890
         * 1720479531
         * 1817852180
         * 571502800
         * 981687587
         * 1884839221
         * 1869074966
         * 90542208
         * 1961817730
         * 1342973776
         * 1654753252
         * 355825481
         * 1316400197
         * 1401185548
         * 924199008
         */

        Random.InitState((int)System.DateTime.Now.Ticks);

        //check if we need to generate a random seed
        if (RandomSeed)
        {
            Seed = Random.Range(0, int.MaxValue);
        }
        //Setup the Voronoi with sites
        _voronoi.RandomCells(Voronoi.SiteCount, Voronoi.GridSize, Seed);
        //Calculate the voronoi diagram
        _voronoi.Calculate();
        //clip the voronoi diagram
        _voronoi.Clip(Voronoi.GridSize);
    }
Esempio n. 2
0
        public void GenerateWorldVoronoi(int?seed = null)
        {
            Tiles.Clear();

            Vor = new Voronoi(seed);
            Vor.Calculate(150, 300, 300);

            SetSpawnVoronoi();

            var tileset = _engine.TileSetManager.Current;
            var rand    = new Random();

            foreach (var point in Vor.Points)
            {
                var tilesettile = tileset.GetRandomTile(point.Type, rand);
                var tile        = new Tile(point, tileset.Texture, tilesettile.Rect, tilesettile.IsPassable);
                Tiles.Add(tile);

                if (point.Type == Tile.TileType.Spawn)
                {
                    Spawn = tile;
                }
            }
        }