예제 #1
0
 public void Paint(IslandTop top)
 {
     foreach (var p in top.Points)
     {
         var color = GetColor(p.Position.y);
         p.cube.GetComponent <MeshRenderer>().material.color = color;
     }
 }
예제 #2
0
    public void Create(IslandTop surface)
    {
        this.surface = surface;
        float highestPoint = surface.HighestPoint;

        int d = (int)(surface.diameter / 2f) + 1;

        treePositions = Poisson.GeneratePoisson(d, d, density, iterationPointCount, (point) =>
        {
            return(surface.PointMap.ContainsKey(point)
            ? Mathf.Abs(highestPoint - (surface.PointMap[point].Position.y * heightWeighting))
            : 0f);
        })
                        .Where(p => surface.PointMap.ContainsKey(p))
                        .Select(p => surface.PointMap[p])
                        .ToList();
    }
예제 #3
0
    public void Create(IslandTop surface, MinMax pathLength, Vector2Int crossingPoint, Direction dir)
    {
        //Determine a length for the path
        int length = (int)pathLength.GetRandomValue();

        //Determine how far the left / south extreme of the path will be
        int offset = (int)(Random.value * length);

        Vector2Int aCoord = Vector2Int.zero, bCoord = Vector2Int.zero;

        switch (dir)
        {
        case Direction.X:
            aCoord = crossingPoint + new Vector2Int(-offset, 0);
            bCoord = crossingPoint + new Vector2Int(length - offset, 0);

            dimensions = new Vector2Int(length, 1);
            break;

        case Direction.Z:
            aCoord = crossingPoint + new Vector2Int(0, -offset);
            bCoord = crossingPoint + new Vector2Int(0, length - offset);

            dimensions = new Vector2Int(1, length);
            break;
        }

        OriginPoint = aCoord;

        var pathGridCoords = GridUtility.DrawRasterLine(aCoord, bCoord);

        Direction = dir;

        Tiles = pathGridCoords.Select(x =>
        {
            if (surface.PointMap.ContainsKey(x))
            {
                return(surface.PointMap[x].GridPosition);
            }
            return(default);
    public void Create(IslandTop surface)
    {
        this.surface = surface;

        List <IslandBuilding> buildings = new List <IslandBuilding>();

        //List of all paths created
        List <IslandPath> paths = new List <IslandPath>();

        //For fast location of a new potential intersection
        //Current intersections recorded to avoid overlaps / close intersections
        List <Vector2Int> intersections = new List <Vector2Int>();

        //Initial intersection point chosen randomly
        //First crossing point is not added to intersections as it is not where two roads meet, but a randomly chosen point
        Vector2Int intersectionPoint = surface.PointMap.Values.ToList().Random().GridPosition;
        //Initial direction chosen randomly
        Direction roadDir = Random.value > 0.5f ? Direction.X : Direction.Z;

        //Create paths until max iterations are no valid space for a new intersection
        for (int i = 0; i < maxPathIterations; i++)
        {
            //Create the path
            IslandPath p = Instantiate(islandPathPrefab);
            p.transform.SetParent(transform);

            p.Create(surface, pathLength, intersectionPoint, roadDir);

            //Add to list of created paths
            paths.Add(p);

            //For each tile occupied, record that the tile's position points to this path - or if it belongs to another path,
            //this is a new intersection
            p.Tiles.ForEach(x =>
            {
                if (structureMap.ContainsKey(x) == false)
                {
                    structureMap[x] = p;
                }
                else
                {
                    intersections.Add(x);
                }
            });

            //Create buildings while creating roads to crate more integrated villages
            PopulateBuildings(paths);

            //Find the next intersection from all possible roads
            //Assess every point on every path
            intersectionPoint = structureMap.Keys.Where(pathTile =>
            {
                //If the point is too close to any existing intersection, reject that point
                foreach (var intersection in intersections)
                {
                    if (Vector2Int.Distance(pathTile, intersection) < minIntersectionSeparation)
                    {
                        return(false);
                    }
                }

                return(true);
            })
                                .ToList()
                                //Choose random point from the survivors
                                .Random();

            //Case where no space for a new intersection
            if (intersectionPoint == null)
            {
                break;
            }

            //Find which path the new intersection belongs to
            var nextCrossingPath = structureMap[intersectionPoint] as IslandPath;

            //Flip direction for next path to opposite of selected path
            roadDir = (nextCrossingPath.Direction == Direction.X) ? Direction.Z : Direction.X;
        }

        //Front end
        paths.ForEach(x => CreatePathCubes(x, surface.CubeSize));
    }