public List <Vector3> GetGenPositions(STPattern pattern, Vector3 nodePosition, int prevPatternPos, List <int> paternVects, int branchLength)
    {
        foreach (STNetNode netNode in elementNetNodesArray)
        {
            netNode.transform.position += nodePosition - prevElementPostion;
        }

        prevElementPostion.x = nodePosition.x;
        prevElementPostion.y = nodePosition.y;
        prevElementPostion.z = nodePosition.z;

        Vector3 genPos = new Vector3();


        List <Vector3> genPoints = new List <Vector3> ();

        //Debug.Log ("GEN");


        if (STPatternManager.GetMode() == GenMode.patternMode)
        {
            List <int> verts = pattern.GetVertices();
            if (verts != null)
            {
                foreach (int vert in verts)
                {
                    int circleN           = (vert - 1) / 8;
                    int prevPatternCircle = (prevPatternPos - 1) % 8;
                    int posInCircle       = ((vert - 1) % 8 + prevPatternCircle) % 8;

                    genPos = elementNetNodesArray [circleN * 8 + posInCircle + 1].transform.position;
                    genPoints.Add(genPos);
                    paternVects.Add(circleN * 8 + posInCircle + 1);
                }
            }
        }
        else
        {
            int randN;
            int nBranches = (int)(Random.value * (pattern.maxBranches - pattern.minBranches)) + pattern.minBranches;
            //	int nBranches = 1;
            int genCount      = 0;
            int totalGenCount = 0;

            do
            {
                bool goodVect = false;
                //int index;


                do
                {
                    int minLength = pattern.minLength;
                    int maxLength = pattern.maxLength;

                    //		Debug.Log ("MIN" + minLength);
                    //		Debug.Log ("MAX" + maxLength);


                    //	randN = (int) (Random.value * 23) + 1;
                    randN = (int)((minLength - 1) * 8 + Mathf.Round(Random.value * (maxLength - minLength + 1) * 8.0f));

                    if (randN == 0)
                    {
                        continue;
                    }

                    //Debug.Log (randN);

                    //	int circleN = (randN - 1) / 8;
                    //	int prevPatternCircle = (prevPatternPos - 1) % 8;
                    //	int posInCircle = ((randN - 1) % 8 + prevPatternCircle) % 8;

                    //	index = circleN * 8 + posInCircle + 1;
                    genPos = elementNetNodesArray [randN].transform.position;


                    bool checkGenPos = true;



                    SymetryMode mode = STPatternManager.GetSymetryMode();

                    if (mode == SymetryMode.symetry_4)
                    {
                        if ((genPos.x <= STNode.nodeSize) || (genPos.y <= STNode.nodeSize))
                        {
                            checkGenPos = false;
                        }
                    }
                    else if ((mode == SymetryMode.symetry_2) || (mode == SymetryMode.symetry_2fliped))
                    {
                        if (genPos.y <= STNode.nodeSize)
                        {
                            checkGenPos = false;

                            //	Debug.Log ("GEN POS ERR");
//							Debug.Log (genPos);
                        }
                    }


                    if ((Mathf.Abs(genPos.y + STNode.nodeSize) > Camera.main.orthographicSize) || (Mathf.Abs(genPos.x + STNode.nodeSize) > Camera.main.orthographicSize))
                    {
                        checkGenPos = false;
//						Debug.Log ("OUT OF SCREEN");
                    }

//					if (branchLength + ( randN - 1) / 8 + 1 > 6)
//					{
//						checkGenPos = false;
//						goodVect = false;
//					}


                    if (((prevPatternPos == 0) || (Mathf.Abs(randN - prevPatternPos) % 8 != 4)) && (checkGenPos))
                    {
                        goodVect = true;
                        foreach (int pos in paternVects)
                        {
                            if ((randN % 8) == (pos % 8))
                            {
                                goodVect = false;
                                //	Debug.Log ("PREV GEN POS ERR");
                            }
                        }
                    }
                    else
                    {
                        //Debug.Log ("BACK GEN ERR");
                    }


                    genCount++;
                    if (genCount > 30)
                    {
                        //					Debug.Log ("FAIL 1" + genCount);
                        break;
                    }
                } while (goodVect == false);



                //	if (goodVect == true)
                if (STLevel.GetRootNode().CheckForIntersection(genPos.x, genPos.y, nodePosition.x, nodePosition.y, 0, 0) == true)
                {
                    goodVect = false;
                }

                totalGenCount += genCount;
                genCount       = 0;
                if (totalGenCount > 300)
                {
//					Debug.Log ("FAIL 2" + totalGenCount);
                    goodVect = false;
                }
                else
                if (goodVect == false)
                {
                    continue;
                }

                //Debug.Log ("PREV - " + prevPatternPos);
                //	Debug.Log (randN);
                //	Debug.Log (genPos);

                if (goodVect == true)
                {
                    genPoints.Add(genPos);
                    paternVects.Add(randN);
                }
                //else
                //Debug.Log ("FAIL");


                totalGenCount = 0;
                nBranches--;
            }while (nBranches > 0);

            //paternVects = verts;
        }

        return(genPoints);
    }
Example #2
0
    public static void SetGenParameters(int depth, List <int> minDepthValues, List <int> maxDepthValues, List <int> minLengthValues, List <int> maxLengthValues, SymetryMode mode)
    {
        STPatternManager.GetInstance().levelDepth = depth;

        STPatternManager.GetInstance().symetryMode = mode;

        for (int i = 0; i < depth; i++)
        {
            STPatternManager.GetInstance().randomPaterns[i].minBranches = minDepthValues[i];
            STPatternManager.GetInstance().randomPaterns[i].maxBranches = maxDepthValues[i];

            STPatternManager.GetInstance().randomPaterns[i].minLength = minLengthValues[i];
            STPatternManager.GetInstance().randomPaterns[i].maxLength = maxLengthValues[i];

            //		Debug.Log (minLengthValues[i] + " " + maxLengthValues[i]);

//			Debug.Log (minDepthValues[i]);
        }
    }
Example #3
0
    void generateLevel()
    {
        List <int> minValues = new List <int> ();
        List <int> maxValues = new List <int> ();

        List <int> minLValues = new List <int> ();
        List <int> maxLValues = new List <int> ();

        //Debug.Log ("GENERATE");

        for (int i = 0; i < 6; i++)
        {
            minValues.Add(1);
            maxValues.Add(1);

            minLValues.Add(1);
            maxLValues.Add(1);
        }


        for (int i = 0; i < depthLevelValue; i++)
        {
            minValues[i] = genBranchesCountStringsMin[i][0] - '0';
            maxValues[i] = genBranchesCountStringsMax[i][0] - '0';

            minLValues[i] = genBranchesLengthStringsMin[i][0] - '0';
            maxLValues[i] = genBranchesLengthStringsMax[i][0] - '0';
        }

        SymetryMode mode = SymetryMode.symetry_0;

        switch (selectionGrid)
        {
        case 0:
            mode = SymetryMode.symetry_2;
            break;

        case 1:
            mode = SymetryMode.symetry_2fliped;
            break;

        case 2:
            mode = SymetryMode.symetry_4;
            break;

        case 3:
            mode = SymetryMode.symetry_0;
            break;
        }

        //Debug.Log ("SYM MODE" + selectionGrid);

        STPatternManager.SetGenParameters(depthLevelValue, minValues, maxValues, minLValues, maxLValues, mode);
        STLevel.GenerateRandomLevel();

        STLevel.GetRootNode().SetAnimation();

        if (STScene.getMode() == SCENE_MODE.TEST_ANIM)
        {
            genCount++;

            if (genCount == 2)
            {
                isOnGUI = false;
            }
        }

        STLevel.GetRootNode().UpdateLinkPosition(STLevel.GetRootNode().transform.position);
    }