Exemplo n.º 1
0
    public void GenerateChunk(int xStart, int yStart, Chunk chunk)
    {
        Tilemap tilemap = chunk.ChunkTilemap;

        chunk.transform.position = new Vector3(xStart, yStart, 0);
        for (int x = 0; x < ChunkSize; x++)
        {
            for (int y = 0; y < ChunkSize; y++)
            {
                DestructibleTile toSet = null;
                int baseOre            = 0;

                float perlin         = MainPerlin.GetPerlin(x + xStart, y + yStart);
                float solidThreshold = SolidThresholdPerlin.GetPerlin(x + xStart, y + yStart);
                //if we're generating a solid tile:
                if (perlin > solidThreshold)
                {
                    //check whether it should be explosive
                    if (ShouldBeExplosive(x + xStart, y + yStart))
                    {
                        toSet = ExplosiveTiles[0];
                        //tilemap.SetTile(new Vector3Int(x, y, 0), newTile);
                    }
                    else
                    {
                        //determine how much ore the tile should have
                        float normOre = Mathf.InverseLerp(solidThreshold, 1, perlin);
                        normOre = Mathf.InverseLerp(.5f, 1, normOre);
                        int oreAmount = Mathf.FloorToInt(normOre / (1.0f / OreTiles.Length));
                        oreAmount = Mathf.Clamp(oreAmount, 0, OreTiles.Length);
                        baseOre   = oreAmount;
                        //set the tile to the normal tile thing
                        toSet = TerrainTiles[0];
                        //tilemap.SetTile(new Vector3Int(x, y, 0), newTile);
                    }
                }
                else
                {
                    //tilemap.SetTile(new Vector3Int(x, y, 0), null);
                    //chunk.ForegroundTilemap.SetTile(new Vector3Int(x, y, 0), null);
                    //chunk.OreAmount[x, y] = 0;
                }

                chunk.SetTile(x, y, toSet, baseOre);
            }
        }
        chunk.ApplyTiles();

        chunk.Caverns = Cavern.GetChunkCaverns(chunk, chunk.MinCavernSize);
        if (chunk.Caverns.Count > 0)
        {
            chunk.BiggestCavern = chunk.Caverns.Aggregate((i1, i2) => i1.AirTiles.Count > i2.AirTiles.Count ? i1 : i2);
        }
        else
        {
            chunk.BiggestCavern = null;
        }

        GenerateLevelFeatures(chunk);
    }
Exemplo n.º 2
0
    bool ShouldBeExplosive(float x, float y)
    {
        float perlin = ExplosivePerlin.GetPerlin(x, y);         //inverting

        if (perlin > ExplosiveThreshold)
        {
            return(true);
        }
        return(false);
    }