Example #1
0
        /// <summary>
        /// Alters a pre-generated map so that obstructions exist within the map.
        /// </summary>
        private void GenerateSphericalContainers()
        {
            //Generate hazards
            for (int i = 0; i < ConfigurationManager.Instance.Number_Of_Conatiner_Spheres; i++)
            {
                int xCoord = RNG.Next(0, Blocks.GetLength(0));
                int zCoord = RNG.Next(0, Blocks.GetLength(2));
                int yCoord = RNG.Next(0, Blocks.GetLength(1));


                //Generate a sphere around this point overriding non-air blocks
                for (int HX = xCoord - ConfigurationManager.Instance.Conatiner_Sphere_Radius; HX < xCoord + ConfigurationManager.Instance.Conatiner_Sphere_Radius; HX++)
                {
                    for (int HZ = zCoord - ConfigurationManager.Instance.Conatiner_Sphere_Radius; HZ < zCoord + ConfigurationManager.Instance.Conatiner_Sphere_Radius; HZ++)
                    {
                        for (int HY = yCoord - ConfigurationManager.Instance.Conatiner_Sphere_Radius; HY < yCoord + ConfigurationManager.Instance.Conatiner_Sphere_Radius; HY++)
                        {
                            float xSquare = (xCoord - HX) * (xCoord - HX);
                            float ySquare = (yCoord - HY) * (yCoord - HY);
                            float zSquare = (zCoord - HZ) * (zCoord - HZ);
                            float Dist    = Mathf.Sqrt(xSquare + ySquare + zSquare);
                            if (Dist <= ConfigurationManager.Instance.Conatiner_Sphere_Radius)
                            {
                                int CX, CY, CZ;
                                CX = Mathf.Clamp(HX, 1, Blocks.GetLength(0) - 2);
                                CZ = Mathf.Clamp(HZ, 1, Blocks.GetLength(2) - 2);
                                CY = Mathf.Clamp(HY, 1, Blocks.GetLength(1) - 2);
                                Blocks[CX, CY, CZ] = new ContainerBlock();
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Generates the preliminary world data based on perlin noise.
        /// </summary>
        private void GeneratePreliminaryWorld()
        {
            for (int x = 0; x < Blocks.GetLength(0); x++)
            {
                for (int z = 0; z < Blocks.GetLength(2); z++)
                {
                    /**
                     * These numbers have been fine-tuned and tweaked through trial and error.
                     * Altering these numbers may produce weird looking worlds.
                     **/
                    int stoneCeiling = SimplexNoise.GetPerlinNoise(x, 0, z, 10, 3, 1.2) +
                                       SimplexNoise.GetPerlinNoise(x, 300, z, 20, 4, 0) +
                                       10;
                    int grassHeight = SimplexNoise.GetPerlinNoise(x, 100, z, 30, 10, 0);
                    int foodHeight  = SimplexNoise.GetPerlinNoise(x, 200, z, 20, 5, 1.5);

                    Topography[x, z] = stoneCeiling + grassHeight + foodHeight;

                    for (int y = 0; y < Blocks.GetLength(1); y++)
                    {
                        if (y <= stoneCeiling)
                        {
                            Blocks[x, y, z] = new StoneBlock();
                        }
                        else if (y <= stoneCeiling + grassHeight)
                        {
                            Blocks[x, y, z] = new GrassBlock();
                        }
                        else if (y <= stoneCeiling + grassHeight + foodHeight)
                        {
                            Blocks[x, y, z] = new MulchBlock();
                        }
                        else
                        {
                            Blocks[x, y, z] = new AirBlock();
                        }
                        if
                        (
                            x == 0 ||
                            x >= Blocks.GetLength(0) - 1 ||
                            z == 0 ||
                            z >= Blocks.GetLength(2) - 1 ||
                            y == 0
                        )
                        {
                            Blocks[x, y, z] = new ContainerBlock();
                        }
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        /// This method performs a deep copy of the initial world state to a backup array for later restoration.
        /// </summary>
        private void CopyBlocks()
        {
            for (int x = 0; x < Blocks.GetLength(0); x++)
            {
                for (int y = 0; y < Blocks.GetLength(1); y++)
                {
                    for (int z = 0; z < Blocks.GetLength(2); z++)
                    {
                        if (Blocks[x, y, z] is AirBlock)
                        {
                            InitialBlocks[x, y, z] = new AirBlock();
                        }
                        else if (Blocks[x, y, z] is MulchBlock)
                        {
                            InitialBlocks[x, y, z] = new MulchBlock();
                        }
                        else if (Blocks[x, y, z] is ContainerBlock)
                        {
                            InitialBlocks[x, y, z] = new ContainerBlock();
                        }
                        else if (Blocks[x, y, z] is GrassBlock)
                        {
                            InitialBlocks[x, y, z] = new GrassBlock();
                        }
                        else if (Blocks[x, y, z] is StoneBlock)
                        {
                            InitialBlocks[x, y, z] = new StoneBlock();
                        }
                        else if (Blocks[x, y, z] is AcidicBlock)
                        {
                            InitialBlocks[x, y, z] = new AcidicBlock();
                        }
                        else if (Blocks[x, y, z] is NestBlock)
                        {
                            InitialBlocks[x, y, z] = new NestBlock();
                        }

                        InitialBlocks[x, y, z].worldXCoordinate = x;
                        InitialBlocks[x, y, z].worldYCoordinate = y;
                        InitialBlocks[x, y, z].worldZCoordinate = z;
                    }
                }
            }
        }