示例#1
0
    public static void GenerateCave(int x, WorldData worldData)
    {
        int depth = 0;

        Vector2i surface = TerrainUtilities.FindUpperMostTile(x, worldData, type => type != TileType.Empty);
        int      y       = Random.Range(surface.Y, worldData.Height);

        do
        {
            if (!(Random.value < caveContinuationChance))
            {
                continue;
            }

            depth++;
            TerrainUtilities.GenerateFuzzyCircle(minimumCaveSize, maximumCaveSize, worldData, new Vector2i(x, y), TileType.Empty);
            //Logger.Log("TerrainCaveProcessor", string.Format("Generated cave at ({0}, {1}). Current depth: {2}", x * Chunk.Size, y * Chunk.Size, depth));

            float   angle     = Random.value * MathHelper.Tau;
            Vector2 direction = new Vector2((float)Math.Cos(angle), (float)-Math.Sin(angle));

            int step = Random.Range(minimumCaveSize, maximumCaveSize);
            x += (int)Math.Floor(direction.x * step);
            y += (int)Math.Floor(direction.y * step);
        }while (depth < maximumCaveDepth);
    }
示例#2
0
    private static void GenerateCanyon(int startX, WorldData worldData)
    {
        int steps    = Random.Range(minimumCanyonSteps, maximumCanyonSteps);
        int currentX = startX;

        for (int i = 0; i < steps; i++)
        {
            int radius = Random.Range(minimumCanyonSize, maximumCanyonSize);

            int pivot = Random.Range(-radius, radius);
            int x     = currentX + pivot;

            Vector2i spot = TerrainUtilities.FindUpperMostTile(x, worldData, type => type != TileType.Empty);
            TerrainUtilities.GenerateFuzzyCircle(minimumCanyonSize, maximumCanyonSize, worldData, spot, TileType.Empty);

            currentX = x;
        }
    }
    private void Impact()
    {
        float    size           = impactRadius / 2f;
        Vector2i impactPosition = WorldController.Instance.WorldCoordiantesToGridSpace(transform.position + new Vector3(0, size));

        TerrainUtilities.GenerateFuzzyCircle(impactRadius, impactRadius + 2, World.Current.WorldData, impactPosition, TileType.Empty);

        GameObject impactGameObject = Instantiate(impactPrefab, transform.position + new Vector3(0, 0, -1), Quaternion.identity);

        impactGameObject.transform.localScale = new Vector3(size, size, size);

        if (Vector3.Distance(transform.position, Player.Current.transform.position) <= impactRadius)
        {
            Player.Current.Shock(0.5f);
        }

        Destroy(impactGameObject, impactGameObject.GetComponent <ParticleSystem>().main.duration);
        Destroy(gameObject);
    }
示例#4
0
    private static void GenerateValley(int startX, WorldData worldData)
    {
        int steps    = Random.Range(minimumValleySteps, maximumValleySteps);
        int currentX = startX;

        for (int i = 0; i < steps; i++)
        {
            int radius = Random.Range(minimumValleySize, maximumValleySize);

            int pivot = Random.Range(-radius, radius);
            int x     = currentX + pivot;

            Vector2i spot     = TerrainUtilities.FindUpperMostTile(x, worldData, type => type != TileType.Empty);
            TileType spotType = Random.value < valleyExtrusionChance ? TileType.NonEmpty : TileType.Empty;
            TerrainUtilities.GenerateFuzzyCircle(minimumValleySize, maximumValleySize, worldData, spot, spotType);

            currentX = x;
        }
    }