Example #1
0
    public static List<CubeMeta> Generate(int gap, int minimumWallWidth, int maximumWallWidth)
    {
        // Set the next position
        NextPosition();

        // Create list of meta data for cube spawning
        List<CubeMeta> cubes = new List<CubeMeta>();

        int mid = gap - 20;
        if (mid < 0) mid = 0;

        // number of cubes on the top
        int topCubes = Random.Range(minimumWallWidth, maximumWallWidth);

        // number of cubes on the bottom
        int botCubes = Random.Range(minimumWallWidth, maximumWallWidth);

        // number of cubes (and gaps) in this column
        int total = topCubes + botCubes + gap + mid;

        for (int i = 1; i < total; i++)
        {
            /*	i < topCubes
            *	gaps (no cubes)
            *	i > bot cubes
            */
            if (i < topCubes || i > total - botCubes)
            {
                CubeMeta tempCube = new CubeMeta();
                // target position is height determined by i
                tempCube.targetPosition = currentPosition + (Vector3.up * i);
                // start offset is some Z offset
                tempCube.startPosition = tempCube.targetPosition + (Vector3.left * Random.Range(-20, 20));
                // additional offset is just zero here
                //tempCube.positionOffset = Vector3.zero;//Vector3.forward * Mathf.Abs(i - (total/2f)) * 0.25f;

                // audio beat value should be less than 1
                //float beat = Mathf.Abs(i - (total/2f));
                //Rescale(ref beat, total/2f, 0f, 0.5f, 0f);
                //tempCube.audioBeat = beat;

                // add metadata to list
                cubes.Add(tempCube);
            }

            if (i > topCubes + gap/2f && i < total - botCubes - gap/2f )
            {
                CubeMeta tempCube = new CubeMeta();
                // target position is height determined by i
                tempCube.targetPosition = currentPosition + (Vector3.up * i);
                // start offset is some Z offset
                tempCube.startPosition = tempCube.targetPosition + (Vector3.left * Random.Range(-20, 20));
                // additional offset is just zero here
                //tempCube.positionOffset = Vector3.forward * Mathf.Abs(i - (total/2f)) * 0.25f;

                // audio beat value should be less than 1
                //float beat = Mathf.Abs(i - (total/2f));
                //Rescale(ref beat, total/2f, 0f, 0.5f, 0f);
                //tempCube.audioBeat = 0f;

                // add metadata to list
                cubes.Add(tempCube);
            }
        }

        return cubes;
    }
Example #2
0
    public static List<CubeMeta> Generate3D(float cubeSize)
    {
        // 3D level is a tunnel formed from sequential ellipses
        // ellipses walls are the cubes
        // Here's the maths:
        // 		General Equation of an ellipse
        // 			x^2/a^2  +   y^2/b^2  =  1
        //		where:
        //			x, y are the coordinates of any point on the ellipse
        // 			a, b are the radius on the x and y axes respectively
        //		source: http://www.mathopenref.com/coordgeneralellipse.html

        spacing = cubeSize;
        List<CubeMeta> cubes = new List<CubeMeta>();
        NextPosition();		// update center point
        NextSize();			// update radii

        bool middleSpread = false;
        if (Random.value < 0.1f) middleSpread = true;

        // Scan a square shape around the ellipse
        // Add a cube around the outside of the ellipse
        for (float y = -yRadius-1; y <= yRadius+1; y++)
        {
            for (float x = -xRadius-1; x <= xRadius+1; x++)
            {
                float xy = ((x*x)/(xRadius*xRadius)) + ((y*y)/(yRadius*yRadius));

                if ( xy > 1f && xy < 2f)
                {
                    CubeMeta tempCube = new CubeMeta();
                    Vector3 pos = new Vector3(x*spacing, y*spacing);
                    //Debug.DrawLine(pos, pos + Vector3.left, Color.green, 1f);
                    tempCube.targetPosition = currentPosition + pos;
                    if (middleSpread) tempCube.startPosition = currentPosition;
                    else tempCube.startPosition  = currentPosition + pos*5f;
                    tempCube.layerCenter = currentPosition;
                    tempCube.layerIndex = ticker;
                    tempCube.startTime = Time.time;
                    cubes.Add(tempCube);
                }
                //random obstacle
                else if (Random.value < 0.005f && obstacles)
                {
                    CubeMeta tempCube = new CubeMeta();
                    Vector3 pos = new Vector3(x*spacing, y*spacing);
                    //Debug.DrawLine(pos, pos + Vector3.left, Color.green, 1f);
                    tempCube.targetPosition = currentPosition + pos;
                    tempCube.startPosition  = currentPosition + pos*5f;
                    tempCube.layerCenter = currentPosition;
                    tempCube.layerIndex = ticker;
                    tempCube.startTime = Time.time;
                    cubes.Add(tempCube);
                }
            }
        }
        return cubes;
    }