Esempio n. 1
0
        private void BuildGrid()
        {
            var pointList = PoissonDisk.GeneratePoisson(ExampleUtils.ScreenRect, cellDimensions.magnitude, 10);

            grid = LineGrid <SpriteCell> .BeginShape().Segment(pointList.Count).EndShape();

            var map2D = VoronoiMap <LinePoint> .MakeMap(pointList);

            voronoiMap = map2D.To3DXY();

            foreach (var point in grid)
            {
                var     cell       = Instantiate(cellPrefab);
                Vector3 worldPoint = voronoiMap[point];

                cell.transform.parent        = root.transform;
                cell.transform.localScale    = Vector3.one;
                cell.transform.localPosition = worldPoint;

                cell.Color = ExampleUtils.Colors[ColorFunction(point)] + Color.white * 0.1f;
                cell.name  = point.ToString();

                grid[point] = cell;
            }

            ExampleUtils.PaintScreenTexture(plane, voronoiMap.To2D(), ColorFunction);
        }
        private void PlaceLevels(Floor floor, Location location)
        {
            const float levelDistance = 75f;
            var         disk          = new PoissonDisk(Random.Next());
            var         points        = disk.SampleRectangle(new Vector2(0, 0), new Vector2(floor.Settings.Width, floor.Settings.Height), levelDistance);

            foreach (var point in points)
            {
                if (!floor.IsPointPassable(point))
                {
                    continue;
                }

                double roll = Random.NextDouble();

                var returnWarp = new Warp(location, point);

                floor.Tiles[point] = roll > 0.5
                    ? GenerateWarp(ParentWorld.DungeonGenerator, LocationType.Dungeon, returnWarp, Sprites.LadderDown)
                    : GenerateWarp(ParentWorld.CaveGenerator, LocationType.Cave, returnWarp, Sprites.LadderDown);
            }
        }
        private void PlantTrees(Floor floor)
        {
            const float baseTreeDistance = 10f;
            var         disk             = new PoissonDisk(Random.Next());
            var         points           = disk.SampleRectangle(new Vector2(0, 0), new Vector2(floor.Settings.Width, floor.Settings.Height), baseTreeDistance);

            foreach (var point in points)
            {
                if (floor.Tiles[point] is WaterTile)
                {
                    continue;
                }

                double roll = Random.NextDouble();

                bool plantTree = false;

                switch (floor.Tiles[point].SpriteId)
                {
                case Sprites.Sand:
                    plantTree = roll < 0.1;
                    break;

                case Sprites.ValleyGrass:
                    plantTree = roll < 0.5;
                    break;

                case Sprites.ForestGrass:
                    plantTree = roll < 0.9;
                    break;
                }

                if (plantTree)
                {
                    floor.Entities.Add(point, new Tree(Sprites.Reserved));
                }
            }
        }
Esempio n. 4
0
    private void assignTrees()
    {
        PoissonDisk poisson = new PoissonDisk();

        Vector2[,] treeSamples = poisson.GenerateSamples();

        for (int i = 0; i < treeSamples.GetLength(0); i++)
        {
            for (int j = 0; j < treeSamples.GetLength(1); j++)
            {
                if (treeSamples[i, j] != Vector2.zero)
                {
                    int x = (int)treeSamples[i, j].x;
                    int z = (int)treeSamples[i, j].y;

                    int height = this.getHeightForCoords(x, z);

                    Voxel voxel = this.voxelData[x, height, z];

                    voxel.SetTree();
                }
            }
        }
    }