Exemple #1
0
    void Awake()
    {
        maxScaling = 3f;

        pinkCollider         = GetComponent <BoxCollider> ();
        transform.localScale = startingScale;
        growDir  = Directions2D._directions.down;
        branches = new GameObject[maxBranches + maxExtraBranches];
        for (int i = 0; i < maxBranches + maxExtraBranches; i++)
        {
            branches [i] = null;
        }

        branchAt += Random.Range(-branchAtVariance, branchAtVariance);

        touchingOtherPinks = new GameObject[stopWhenTouching];
        for (int i = 0; i < stopWhenTouching; i++)
        {
            touchingOtherPinks[i] = null;
        }

        pinkStorage = GameObject.Find("pink storage").transform;
        transform.SetParent(pinkStorage);

        hallwayMode     = _hallwayMode.off;
        hallTriggersHit = new List <Collider> ();

        GameManager.numGrowths++;
    }
Exemple #2
0
    private void HallwayTriggers(Collider other)
    {
        if (DEBUGHALL)
        {
            //Debug.Log ("HallwayTriggers called for trigger = " + other.gameObject.tag + "   object = " + other.gameObject.name);
        }

        if (other.gameObject.CompareTag("Hall Start Trigger") && !other.GetComponent <HallwayTrigger> ().hall.pinkHasTraversed)
        {
            if (DEBUGHALL)
            {
                Debug.Log("hit hall start trigger");
            }

            HallwayTrigger hallTrig = other.GetComponent <HallwayTrigger> ();

            if (hallwayMode == _hallwayMode.off)
            {
                if (DEBUGHALL)
                {
                    Debug.Log("hallway mode was off when hit");
                }

                if (growDir == hallTrig.hallDirection)
                {
                    // confirmed pink is growing in same direction as the length of the hallway


                    float otherPos   = Directions2D.FlattenToDirection(Directions2D.OppositeAxis(growDir), other.transform.position);
                    float pairPos    = Directions2D.FlattenToDirection(Directions2D.OppositeAxis(growDir), hallTrig.pairedTrigger.transform.position);
                    float thisPos    = Directions2D.FlattenToDirection(Directions2D.OppositeAxis(growDir), transform.position);
                    float otherScale = Directions2D.FlattenToDirection(Directions2D.OppositeAxis(growDir), other.transform.lossyScale);
                    float thisScale  = Directions2D.FlattenToDirection(Directions2D.OppositeAxis(growDir), transform.lossyScale);

                    float triggerDistance = Mathf.Abs(pairPos - otherPos);
                    float midpoint        = triggerDistance / 2 + otherPos;
                    float allowance       = thisScale - (triggerDistance - otherScale);

                    if (DEBUGHALL)
                    {
                        Debug.Log("growdir same as hallway, triggerDistance = " + triggerDistance + "   midpoint = " + midpoint + "   allowance = " + allowance);
                    }

                    if (thisPos > midpoint - allowance && thisPos < midpoint + allowance)
                    {
                        // confirmed pink is centered enough that it has hit both hall triggers
                        // it will clear the hallway walls and only needs to be extended
                        if (DEBUGHALL)
                        {
                            Debug.Log("start traversing");
                        }
                        float hallLength = Directions2D.FlattenToDirection(growDir, other.transform.position - hallTrig.oppositeTrigger.transform.position);
                        maxScaling += Mathf.Abs(hallLength);
                        hallwayMode = _hallwayMode.traversing;
                        hallTrig.hall.pinkHasTraversed = true;
                    }
                    else
                    {
                        // pink is not centered enough and needs to branch to align
                        // create connecting branch
                        Pink newBranch = Branch(FrontBranchPoint(), 0f, true, hallTrig.pairDirection, _hallwayMode.connecting);
                    }
                }
                else if (growDir == hallTrig.pairDirection)
                {
                    // confirmed pink is growing in direction of paired hallway trigger
                    float connectionLength = Directions2D.FlattenToDirection(growDir, other.transform.position - hallTrig.pairedTrigger.transform.position);
                    maxScaling += Mathf.Abs(connectionLength);
                    hallwayMode = _hallwayMode.connecting;
                }
            }
            else if (hallwayMode == _hallwayMode.connecting && hallStartTriggersHit % 2 == 1)
            {
                // create traversing branch
                Pink newBranch = Branch(FrontBranchPoint(), 0f, true, hallTrig.hallDirection, _hallwayMode.traversing);

                float hallLength = Directions2D.FlattenToDirection(hallTrig.hallDirection, other.transform.position - hallTrig.oppositeTrigger.transform.position);
                newBranch.maxScaling += Mathf.Abs(hallLength);

                hallwayMode = _hallwayMode.off;
                hallTrig.hall.pinkHasTraversed = true;
            }

            hallStartTriggersHit++;
        }
        else if (other.gameObject.CompareTag("Hall End Trigger") && !hallTriggersHit.Contains(other))
        {
            // hit end point

            if (hallwayMode == _hallwayMode.traversing && hallTriggersHit.Count > 0)
            {
                // branch both directions
                if (DEBUGHALL)
                {
                    Debug.Log("hit hall end trigger while traversing");
                }

                BranchBloom(FrontBranchPoint(), 0f, true);
                hallwayMode = _hallwayMode.off;
            }
            hallTriggersHit.Add(other);
        }
    }
Exemple #3
0
    private Pink Branch(Vector3 startPoint, float overshotBy = 0f, bool extraBranch = false, Directions2D._directions direction = Directions2D._directions.numDirections, _hallwayMode hall = _hallwayMode.off)
    {
        if (normalBranches == maxBranches)
        {
            Debug.Log("ERROR: attmepted to branch from pink object (" + this.name + ") when already at max branches");
            return(null);
        }

        branches [branchCount] = Instantiate(pinkTemplate[0], startPoint, Quaternion.identity) as GameObject;


        Pink newBranchPink = branches [branchCount].GetComponentInChildren <Pink> ();

        if (direction == Directions2D._directions.numDirections)
        {
            Directions2D._directions newDir = NewBranchDirection(startPoint);
            newBranchPink.SetDirection(newDir);
        }
        else
        {
            newBranchPink.SetDirection(direction);
        }

        if (overshotBy >= 0.05f)
        {
            newBranchPink.AddGrowthBurst(overshotBy);
        }
        newBranchPink.hallwayMode = hall;

        branchCount++;
        if (!extraBranch)
        {
            normalBranches++;
        }

        newBranchPink.DEBUGHALL = false;

        return(newBranchPink);
    }