Exemplo n.º 1
0
    void OnGUI()
    {
        //button dimensions
        float buttonW = Screen.width / 4.8f;;
        float buttonH = Screen.height / 6;

        float halfScreenW = (Screen.width) - (buttonW * 1.1f);
        //float halfScreenH = Screen.height/13;
        float halfScreenH = buttonH / 3;

        GUIStyle style = new GUIStyle(GUI.skin.button);

        style.fontSize = (int)(buttonH / 3.5f);

        GUI.skin = skin;

        if (GUI.Button(new Rect(halfScreenW, halfScreenH, buttonW, buttonH), "||", style))
        {
            paused = true;
            GlobalFlags.setPaused(true);
        }

        if (paused)
        {
            //if paused build the menu

            buttonW = Screen.width / 2;
            buttonH = Screen.height / 10;

            style.alignment = TextAnchor.UpperCenter;
            GUI.Box(backWindow, "Pause Menu", style);            //title the menu
            style.alignment = TextAnchor.MiddleCenter;

            // set the resume button and functionality
            halfScreenW = (Screen.width / 2) - buttonW / 2;
            halfScreenH = Screen.height / 3;
            if (GUI.Button(new Rect(halfScreenW, halfScreenH, buttonW, buttonH), "Resume", style))
            {
                paused = false;
                GlobalFlags.setPaused(false);
                GlobalFlags.bandAidFixToDefeatAllOtherBandAidFixes = true;
            }

            //set the restart button and functionality
            halfScreenW = (Screen.width / 2) - buttonW / 2;
            halfScreenH = Screen.height / 3 + buttonH * 1.5f;
            if (GUI.Button(new Rect(halfScreenW, halfScreenH, buttonW, buttonH), "Restart", style))
            {
                Application.LoadLevel("game");
                GlobalFlags.canFire         = true;
                GlobalFlags.trianglesStatic = true;
                GlobalFlags.setPaused(false);
                GlobalFlags.updateControlPoints = true;
            }

            //set the back to menu button and functionality
            halfScreenW = (Screen.width / 2) - buttonW / 2;
            halfScreenH = Screen.height / 3 + buttonH * 3;
            if (!GlobalFlags.getRandLevel())
            {
                if (GUI.Button(new Rect(halfScreenW, halfScreenH, buttonW, buttonH), "Back To Menu", style))
                {
                    Application.LoadLevel("LevelSelectPreMenu");
                    GlobalFlags.setPaused(false);
                    GlobalFlags.canFire             = true;
                    GlobalFlags.trianglesStatic     = true;
                    GlobalFlags.updateControlPoints = true;
                }
            }
            else
            {
                if (GUI.Button(new Rect(halfScreenW, halfScreenH, buttonW, buttonH), "Back To Menu", style))
                {
                    //GlobalFlags.canFire = true;
                    GlobalFlags.setRandLevel(false);
                    GlobalFlags.infiniteRandomMode = false;
                    Application.LoadLevel("ModeSelectMenu");
                    GlobalFlags.setPaused(false);
                    GlobalFlags.updateControlPoints = true;
                }
            }
        }
    }
Exemplo n.º 2
0
    /**
     * This has to be awake, as the levels have to be parsed before everything else calls the data
     * from the file. Depending on if the RandomLevel flag is flipped in the @GlobalFlag.cs class,
     * then a level will be generated randomly and without the use of a file.
     */
    void Awake()
    {
        bool randomLevel = GlobalFlags.getRandLevel();

        if (!randomLevel)
        {
            //TODO Once we have levels being set globally, get the level here from the global variables.
            try {
                TextAsset file       = (TextAsset)Resources.Load("levels/level" + GlobalFlags.getLevel());
                string    fileString = file.text;

                string[] lines = fileString.Split('\n');
                //string[] lines = System.IO.File.ReadAllLines("assets/Resources/levels/level" + GlobalFlags.getLevel() + ".txt");

                triArray  = new TriInfo[lines.Length - 1];                //first line of the level file is the queue for that level
                queueTris = lines[0].Split(',');
                for (int i = 1; i < lines.Length; i++)
                {
                    int     commaIndex = lines[i].IndexOf(',');
                    int     colonIndex = lines[i].IndexOf(':');
                    int     x          = int.Parse(lines[i].Substring(0, commaIndex));
                    int     y          = int.Parse(lines[i].Substring(commaIndex + 1, colonIndex - 1 - commaIndex));
                    string  colour     = lines[i].Substring(colonIndex + 1, lines[i].Length - 1 - colonIndex);
                    TriInfo triInfo    = new TriInfo(x, y, colour.Trim());

                    triArray[i - 1] = triInfo;                     // first "i" was for the queue
                }
            }
            catch (UnityException e) {
                Debug.Log("error reading file level" + GlobalFlags.getLevel() + ".txt");
                Debug.Log(e.StackTrace);
            }
        }
        else
        {
            //Loads a random level into the Triangle array
            int        negRandY = (int)Random.Range(1, RANDOM_LENGTH) * -1;
            int        randY    = (int)Random.Range(1, RANDOM_LENGTH);
            TriInfo [] temp     = new TriInfo[(RANDOM_LENGTH + Mathf.Abs(RANDOM_LENGTH) + 1) * (RANDOM_LENGTH + Mathf.Abs(RANDOM_LENGTH) + 1) - 1];

            //used to help make sure there is no complete cluster in the random level
            string [,] testComplete = new string[RANDOM_LENGTH * 2 + 1, RANDOM_LENGTH * 2 + 1];

            int arrLoc  = 0;
            int yLocTri = RANDOM_LENGTH - randY;             //y location  of the triangle in an array
            for (int i = randY; i >= negRandY; i--)
            {
                int negRandX = (int)Random.Range(1, RANDOM_LENGTH) * -1;
                int randX    = (int)Random.Range(1, RANDOM_LENGTH);

                int xLocTri = negRandX + RANDOM_LENGTH;                 //x location  of the triangle in an array
                for (int j = negRandX; j <= randX; j++)
                {
                    if (i == 0 && j == 0)
                    {
                        testComplete[xLocTri, yLocTri] = "black";
                        xLocTri++;
                        continue;
                    }

                    string rColour = randomColour();
                    testComplete[xLocTri, yLocTri] = rColour;
                    while (hasCompleteTriangle(testComplete, false, xLocTri, yLocTri))
                    {
                        rColour = randomColour();
                        testComplete[xLocTri, yLocTri] = rColour;
                    }


                    TriInfo triInfo = new TriInfo(j, i, rColour);
                    temp[arrLoc] = triInfo;
                    arrLoc++;
                    xLocTri++;
                }
                yLocTri++;
            }

            triArray = new TriInfo[arrLoc];
            System.Array.Copy(temp, 0, triArray, 0, arrLoc);

            //loops over arbitrary number (just picked 20), to load the queue with that many random colours.
            queueTris = new string[40];
            for (int i = 0; i < queueTris.Length; i++)
            {
                queueTris[i] = randomColour();
            }
        }
    }