示例#1
0
    public static void WaterRage( )
    {
        int[] validPointsX = new int[20];
        int[] validPointsY = new int[20];
        int   validPoints  = 0;
        int   maxPoints;

        for (int a = 0; a < h / 2; a++)
        {
            for (int b = 0; b < w; b++)
            {
                if ((grid[b, a] == null) && (grid[b, a + 1]) && (validPoints < 20))
                {
                    validPointsX [validPoints] = b;
                    validPointsY [validPoints] = a;
                    validPoints++;
                }
            }
        }
        if (validPoints > 6)
        {
            maxPoints = Random.Range(6, validPoints);
        }
        else
        {
            maxPoints = validPoints;
        }
        validPoints--;
        for (int c = 0; c < maxPoints; c++)
        {
            int  point  = Random.Range(0, validPoints);
            int  posX   = validPointsX [point];
            int  posY   = validPointsY [point];
            bool bottom = false;
            while (!bottom)
            {
                //	while ((grid [posX, posY] == null)&&(posY>=0)) {
                Instantiate(Resources.Load("Bubble"), grid [posX, posY + 1].gameObject.transform.position, Quaternion.identity);
                grid [posX, posY + 1].position += new Vector3(0, -1, 0);
                grid [posX, posY]     = grid [posX, posY + 1];
                grid [posX, posY + 1] = null;
                posY--;
                bottom = true;
                if (posY >= 0)
                {
                    if (grid [posX, posY] == null)
                    {
                        bottom = false;
                    }
                }
            }
            validPointsX [point]       = validPointsX [validPoints];
            validPointsY [point]       = validPointsY [validPoints];
            validPointsX [validPoints] = 0;
            validPointsY [validPoints] = 0;
            validPoints--;
        }
        wtr = GameObject.Find("Water").GetComponent <Bubbles> ();
        wtr.BlueBubbles();
    }
示例#2
0
    public static void AirBubbles()
    {
        int bubbles = Random.Range(1, 3);

        int[] valid4x4 = new int[9];
        int[] valid2x2 = new int[9];
        int   validbubbles2, validbubbles4, position;

        for (int c = 0; c < bubbles; c++)
        {
            validbubbles2 = 0;
            validbubbles4 = 0;
            for (int xsearch = 0; xsearch < 9; xsearch++)
            {
                if ((grid [xsearch, 0] != null) && (grid [xsearch + 1, 0] != null))
                {
                    valid2x2 [xsearch] = 1;
                    validbubbles2++;
                    if ((grid [xsearch, 1] != null) && (grid [xsearch + 1, 1] != null))
                    {
                        valid4x4 [xsearch] = 1;
                        validbubbles4++;
                    }
                    else
                    {
                        valid4x4 [xsearch] = 0;
                    }
                }
                else
                {
                    valid2x2 [xsearch] = 0;
                }
            }
            if (validbubbles2 > 0)
            {
                if (validbubbles4 > 0)
                {
                    position = Random.Range(0, 9);
                    while (valid4x4 [position] != 1)
                    {
                        position = Random.Range(0, 9);
                    }
                    if (grid [position, 0] != null)
                    {
                        Instantiate(Resources.Load("Bubble"), grid[position, 0].gameObject.transform.position, Quaternion.identity);
                        Destroy(grid [position, 0].gameObject);
                        grid [position, 0] = null;
                    }
                    if (grid [position + 1, 0] != null)
                    {
                        Instantiate(Resources.Load("Bubble"), grid[position + 1, 0].gameObject.transform.position, Quaternion.identity);
                        Destroy(grid [position + 1, 0].gameObject);
                        grid [position + 1, 0] = null;
                    }
                    if (grid [position, 1] != null)
                    {
                        Instantiate(Resources.Load("Bubble"), grid [position, 1].gameObject.transform.position, Quaternion.identity);
                        Destroy(grid [position, 1].gameObject);
                        grid [position, 1] = null;
                    }
                    if (grid [position + 1, 1] != null)
                    {
                        Instantiate(Resources.Load("Bubble"), grid[position + 1, 1].gameObject.transform.position, Quaternion.identity);
                        Destroy(grid [position + 1, 1].gameObject);
                        grid [position + 1, 1] = null;
                    }
                }
                else
                {
                    position = Random.Range(0, 9);
                    while (valid2x2 [position] != 1)
                    {
                        position = Random.Range(0, 9);
                    }
                    if (grid [position, 0] != null)
                    {
                        Instantiate(Resources.Load("Bubble"), grid [position, 0].gameObject.transform.position, Quaternion.identity);
                        Destroy(grid [position, 0].gameObject);
                        grid [position, 0] = null;
                    }
                    if (grid [position + 1, 0] != null)
                    {
                        Instantiate(Resources.Load("Bubble"), grid [position + 1, 0].gameObject.transform.position, Quaternion.identity);
                        Destroy(grid [position + 1, 0].gameObject);
                        grid [position + 1, 0] = null;
                    }
                }
            }
        }
        wtr = GameObject.Find("Water").GetComponent <Bubbles> ();
        wtr.BlueBubbles();
    }