Example #1
0
/*	ProceedToTarget instructs this object to move towards its 'dockingPosition'
 *      If this object gets stuck behind the nucleus, it will need a push to
 *      move around the object  */
    private bool ProceedToTarget()
    {
        //Unity manual says if the distance between the two objects is < _speed * Time.deltaTime,
        //protein position will equal docking...doesn't seem to work, so it's hard coded below
        transform.position = Vector2.MoveTowards(transform.position, dockingPosition, _speed * Time.deltaTime);
        if (Vector2.Distance(transform.position, lastPosition) < _speed * Time.deltaTime)
        {
            Roam.Roaming(this.gameObject);        //if I didn't move...I'm stuck.  Give me a push
        }
        lastPosition = transform.position;        //breadcrumb trail
        //check to see how close to the phosphate and disable collider when close
        deltaDistance = Vector3.Distance(transform.position, dockingPosition);
        //once in range, station object at docking position
        if (deltaDistance < _speed * .5f)
        {
            transform.GetComponent <BoxCollider2D> ().enabled   = false;
            transform.GetComponent <Rigidbody2D> ().isKinematic = true;
        }
        if (deltaDistance < _speed * Time.deltaTime)
        {
            transform.position = dockingPosition;
            if (myTarget.GetChild(0).tag == "Left")
            {
                //transform.Rotate(180.0f, 0.0f, 0.0f); //orientate protein for docking
                //transform.Rotate(0.0f, 0.0f,180.0f);
                childGDP.transform.position = childGDP.transform.position - (new Vector3(0.86f, 0.0f, 0.0f) * 2);
            }
        }
        return(transform.position == dockingPosition);
    }
Example #2
0
 //------------------------------------------------------------------------------------------------
 void Tutorial.SwitchOnOff.transparent(bool value)
 {
     if (this.GetComponent <Button> () == null)
     {
         if (value == true)
         {
             Roam.setAlpha(this.gameObject, 0.25f);
         }
         else
         {
             Roam.setAlpha(this.gameObject, 1.00f);
         }
     }
     else
     {
         if (value == true)
         {
             this.GetComponent <Button>().transition = Selectable.Transition.ColorTint;
         }
         else
         {
             this.GetComponent <Button>().transition = Selectable.Transition.None;
         }
     }
 }
Example #3
0
    public void FixedUpdate()
    {
        if (Time.timeScale > 0)
        {
            if (!targeting)            //Look for a target
            {
                Roam.Roaming(this.gameObject);
                openTarget = Roam.FindClosest(transform, "DockedG_Protein");
                if (openTarget != null)
                {
                    myTarget        = openTarget.transform;
                    dockingPosition = GetOffset();
                    LockOn();                     //call dibs
                }
            }

            else if (!docked)
            {
                if ((delay += Time.deltaTime) < 5)                //wait 5 seconds before proceeding to target
                {
                    Roam.Roaming(this.gameObject);
                }
                else
                {
                    //docked = ProceedToTarget();
                    docked = Roam.ProceedToVector(this.gameObject, dockingPosition);
                }
                if (docked)
                {
                    Cloak();
                }
            }
        }
    }
Example #4
0
 void Awake()
 {
     rStateRoam          = gameObject.GetComponent <Roam>();
     sShootState         = gameObject.GetComponent <Shoot>();
     csCollectHealth     = gameObject.GetComponent <CollectHealth>();
     activeState         = rStateRoam;
     activeState.enabled = true;
 }
Example #5
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (tag == "ReleasedGDP")
        {
            tag = "DyingGDP";
            StartCoroutine(ReleasingGDP());
            StartCoroutine(DestroyGDP());               //Destroy GDP
        }

        Roam.Roaming(this.gameObject);
    }
Example #6
0
    }    /* end FindClosest */

    public static bool ApproachMidpoint(GameObject obj1, GameObject obj2, bool[] midpointAchieved, Vector3 midpoint, Vector3 Offset, float Restraint)
    {
        if (!midpointAchieved [0])
        {
            midpointAchieved [0] = Roam.ApproachVector(obj1, midpoint, Offset, Restraint);
        }

        if (!midpointAchieved [1])
        {
            midpointAchieved [1] = Roam.ApproachVector(obj2, midpoint, -1 * Offset, Restraint);
        }
        return(midpointAchieved [0] && midpointAchieved [1]);
    }
Example #7
0
    public void FixedUpdate()
    {
        if (Time.timeScale > 0)
        {
            if (spin)
            {
                transform.rotation = Quaternion.Slerp(transform.rotation, rotation, 2 * Time.deltaTime);
                if (Quaternion.Angle(transform.rotation, rotation) == 0)
                {
                    spin = false;
                }
            }
            if (found == false)
            {
                Roam2();
            }
            if (!targeting)            //Look for a target
            {
                Roam2();
                //rigidbody.AddForce(transform.forward);
                Roam.Roaming(this.gameObject);
                openTarget = Roam.FindClosest(transform, "DockedG_Protein");
                if (openTarget != null)
                {
                    myTarget        = openTarget.transform;
                    dockingPosition = GetOffset();
                    LockOn();                     //call dibs
                }
            }

            else if (!docked)
            {
                if ((delay += Time.deltaTime) < 5)                //wait 5 seconds before proceeding to target
                {
                    Roam.Roaming(this.gameObject);
                }
                //Roam2();
                else
                {
                    //docked = ProceedToTarget();
                    docked = Roam.ProceedToVector(this.gameObject, dockingPosition);
                }
                if (docked)
                {
                    Cloak();
                }
            }
        }
    }
Example #8
0
    /*  Function:   setAdenylylCyclaseInactive()
     *  Purpose:    this function sets the Active Adenylyl Cyclase with which
     *              this Alpha Subunit has bound to inactive. This will cause
     *              the Active Cyclase to leave the game and an Inactive Adenylyl
     *              Cyclase to spawn in its place
     */
    private void setAdenylylCyclaseInactive()
    {
        GameObject activeCyclase = Roam.FindClosest(transform, "ATP_tracking");

        if (null != inactiveCyclase)
        {
            inactiveCyclase.SetActive(true);
            inactiveCyclase.GetComponent <ActivationProperties>().isActive = false;
        }
        if (null != activeCyclase)
        {
            activeCyclase.GetComponent <ActivationProperties>().isActive = false;
            activeCyclase.SetActive(false);
        }
    }
Example #9
0
    /*  Function:   FixedUpdate()
     *  Purpose:    This function checks for the GameObject's tag to have been
     *              set to ReleasedGDP. Once that is the case, calls the
     *              functions necessary to release this GDP from whatever parent
     *              it may be riding with and to destroy it in an explosion
     */
    void FixedUpdate()
    {
        if (tag == "ReleasedGDP")
        {
            tag = "DyingGDP";
            StartCoroutine(ReleasingGDP());
            StartCoroutine(DestroyGDP());//Destroy GDP
            //determine if win condition has been reached
            if (GameObject.FindWithTag("Win_ReleasedGDP"))
            {
                WinScenario.dropTag("Win_ReleasedGDP");
            }
        }

        Roam.Roaming(this.gameObject);
    }
Example #10
0
 public static void FindAndWait <T>(T obj, GameObject self, ref Transform myTarget, ref float delay, string changeTag) where T : MonoBehaviour, CollectObject
 {
     if (obj != null && myTarget == null)
     {
         delay = 0;
         obj.GetObject(self, changeTag);
         myTarget = obj.transform;
     }
     if (myTarget != null && (delay += Time.deltaTime) >= 5)
     {
     }
     else
     {
         Roam.Roaming(self.gameObject);
     }
 }
/*	ProceedToTarget instructs this object to move towards its 'dockingPosition'
 *      If this object gets stuck behind the nucleus, it will need a push to
 *      move around the object  */
    private bool ProceedToTarget()
    {
        //Unity manual says if the distance between the two objects is < _speed * Time.deltaTime,
        //protein position will equal docking...doesn't seem to work, so it's hard coded below
        transform.position = Vector2.MoveTowards(transform.position, dockingPosition, _speed * Time.deltaTime);

        if (!docked && Vector2.Distance(transform.position, lastPosition) < _speed * Time.deltaTime)
        {
            Roam.Roaming(this.gameObject);        //if I didn't move...I'm stuck.  Give me a push
        }
        lastPosition = transform.position;        //breadcrumb trail
        //check to see how close to the g-protein and disable collider when close
        deltaDistance = Vector3.Distance(transform.position, dockingPosition);
        //once in range, station object at docking position
        if (deltaDistance < _speed * Time.deltaTime)
        {
            transform.GetComponent <CircleCollider2D> ().enabled = false;
            transform.GetComponent <Rigidbody2D>().isKinematic   = true;
            transform.position = dockingPosition;
            transform.parent   = myTarget;
        }        //end if close enough
        return(transform.position == dockingPosition);
    }
Example #12
0
    private void FixedUpdate()
    {
        if (!haveGTP && transform.tag == "OccupiedG_Protein")
        {
            haveGTP = true;
        }

        if (!targeting && !docked && !haveGTP)          //Look for a target
        {
            openTarget = Roam.FindClosest(transform, "ReceptorPhosphate");
            if (openTarget != null)
            {
                myTarget        = openTarget.transform;
                dockingPosition = GetOffset();
                LockOn();                 //call dibs
            }
        }
        else if (!docked && !haveGTP)
        {
            if ((delay += Time.deltaTime) > 5)              //wait 5 seconds before proceeding to target
            {
                docked = ProceedToTarget();
            }
            if (docked)
            {
                ReleaseGDP();
            }
        }
        if (haveGTP && !roaming && (delay += Time.deltaTime) > 2)          //wait 2 seconds before undocking
        {
            Undock();
        }
        else if (haveGTP && roaming)
        {
            /*if (Kinase == null) {
             *      Kinase = Roam.FindClosest (transform, "Kinase");
             * }
             *
             * if (Kinase != null || myTarget != null) {
             *      Roam.FindAndWait (Kinase.GetComponent<KinaseCmdCtrl> (), this.gameObject, ref myTarget, ref delay, "Kinase_Prep_A");
             *      if (myTarget != null && (delay) >= 5) {
             *
             *      }
             * } else {
             *      Roam.Roaming (this.gameObject);
             *      }*/
            GameObject Kinase = Roam.FindClosest(transform, "Kinase");
            if (Kinase != null && !myTarget && isActive)
            {
                delay = 0;
                Kinase.GetComponent <KinaseCmdCtrl> ().GetObject(this.gameObject, "Kinase_Prep_A");
                myTarget = Kinase.transform;
            }
            if (myTarget && (delay += Time.deltaTime) >= 5)
            {
                isActive = false;
            }
            else if (isActive == true)
            {
                Roam.Roaming(this.gameObject);
            }
        }
        else
        {
            Roam.Roaming(this.gameObject);
        }
    }
 // Update is called once per frame
 void FixedUpdate()
 {
     Roam.Roaming(this.gameObject);
     StartCoroutine(DestroyPHOS());
 }
    // Update is called once per frame
    void FixedUpdate()
    {
        if (timeoutForInteraction > timeoutMaxInterval)
        {
            if (tag == "Kinase_Prep_A" || tag == "Kinase_Prep_B")
            {
                active_G_Protein.GetComponent <G_ProteinCmdCtrl>().resetTarget();
                active_G_Protein.GetComponent <BoxCollider2D>().enabled = true;
                active_G_Protein = null;
                reset();
                tag = "Kinase";
            }
        }

        if (tag == "Kinase")
        {
            Roam.Roaming(this.gameObject);
        }
        else if (tag == "Kinase_Prep_A" || tag == "Kinase_Prep_B")
        {
            if ((delay += Time.deltaTime) >= 5.0f)
            {
                //if ((delay += Time.deltaTime) >= 5.0f && active_G_Protein != null) {
                if (!midpointSet && tag == "Kinase_Prep_A")
                {
                    midpoint    = Roam.CalcMidPoint(active_G_Protein, this.gameObject);
                    midpointSet = true;
                }
                else if (Roam.ApproachMidpoint(active_G_Protein, this.gameObject, midpointAchieved, midpoint, setupVector(), setupRestraint()))
                {
                    setupNextPhase();
                }
            }
            else
            {
                Roam.Roaming(this.gameObject);
            }
            timeoutForInteraction += Time.deltaTime;
        }
        else if (tag == "Kinase_Prep_C")
        {
            if (!midpointAchieved[0] || !midpointAchieved[1])
            {
                midpointAchieved[0] = Roam.ProceedToVector(active_G_Protein, midpoint + new Vector3(0.0f, 0.85f, 0.0f)); //these values to be changed
                midpointAchieved[1] = Roam.ProceedToVector(this.gameObject, midpoint + new Vector3(0.0f, -0.85f, 0.0f)); //for snapping kinase to gprotein
            }
            if (midpointAchieved[0] && midpointAchieved[1])
            {
                if ((delay += Time.deltaTime) >= 3)
                {
                    GameObject obj = Instantiate(Kinase_P2, gameObject.transform.position, Quaternion.identity) as GameObject;
                    GameObject.Find("EventSystem").GetComponent <ObjectCollection>().Add(obj);
                    active_G_Protein.GetComponent <G_ProteinCmdCtrl>().resetTarget();
                    Destroy(gameObject);
                }
                else
                {
                    if (this.gameObject.transform.parent == null)
                    {
                        this.gameObject.GetComponent <Rigidbody2D>().isKinematic   = true;
                        this.gameObject.GetComponent <PolygonCollider2D>().enabled = false;
                        this.gameObject.transform.parent = active_G_Protein.transform;
                        active_G_Protein.GetComponent <BoxCollider2D>().enabled = true;
                    }
                    Roam.Roaming(active_G_Protein);
                }
            }
            timeoutForInteraction += Time.deltaTime;
        }
        else if (tag == "Kinase_Phase_2")
        {
            gameWon = true;
            if (T_Reg == null)
            {
                T_Reg = Roam.FindClosest(transform, "T_Reg");
            }

            /*if(T_Reg != null ) {
             *                  Roam.FindAndWait(T_Reg.GetComponent<T_RegCmdCtrl>(),this.gameObject,ref myTarget,ref delay,"T_Reg_Prep_A");
             *          }
             *          else {
             *                  Roam.Roaming(this.gameObject);
             *          }*/
            if (T_Reg != null && !myTarget)
            {
                delay = 0;
                T_Reg.GetComponent <T_RegCmdCtrl>().GetObject(this.gameObject, "T_Reg_Prep_A");
                myTarget = T_Reg.transform;
            }
            if (myTarget && (delay += Time.deltaTime) >= 5)
            {
            }
            else
            {
                Roam.Roaming(this.gameObject);
            }
        }
    }
    /*  Function:   FixedUpdate()
     *  Purpose:    This function determines whether the GTP should roam around
     *              or if there is something for it to seek our and bind with.
     *              In level one, looks for a G-Protein that is docked with the
     *              Recptor to go bind with. This it finds by looking for a
     *              nearby GameObject with the tag "DockedG_Protein". In the
     *              second level, looks for a T_GProtein's Alpha Subunit with
     *              which to bind. This it finds by searching for a nearby Game
     *              Object with the tag "tGProteinDock". Once an appropriate
     *              Object is found, the GTP targets the object and tracks
     *              to it until it collides with it.
     *              This function also continuously checks the GTP's tag for
     *              ReleasedGDP, which causes it to explode and be removed from
     *              the game
     */
    public void FixedUpdate()
    {
        GameObject obj       = null;
        GameObject objParent = null;

        if (Time.timeScale > 0)
        {
            if (spin)
            {
                transform.rotation = Quaternion.Slerp(transform.rotation, rotation, 2 * Time.deltaTime);
                if (Quaternion.Angle(transform.rotation, rotation) == 0)
                {
                    spin = false;
                }
            }
            if (found == false)
            {
                Roam2();
            }

            if (!targeting)//Look for a target
            {
                Roam2();
                Roam.Roaming(this.gameObject);

                openTarget = Roam.FindClosest(transform, "DockedG_Protein");//level one
                if (null == openTarget)
                {
                    obj = Roam.FindClosest(transform, "tGProteinDock");//level 2
                    if (null != obj)
                    {
                        //get the TGProtien. Doc has parent alpha, which has parent TGProtein
                        objParent = obj.transform.parent.gameObject;
                        if (null != objParent && objParent.name == "alpha")
                        {
                            objParent = objParent.transform.parent.gameObject;
                        }

                        TGProteinProperties objProps = (TGProteinProperties)objParent.GetComponent("TGProteinProperties");
                        if (objProps.isActive)
                        {
                            openTarget = obj;
                        }
                    }
                }

                if (openTarget != null)
                {
                    myTarget        = openTarget.transform;
                    dockingPosition = GetOffset();
                    LockOn();//call dibs
                }
            }
            else if (!docked)
            {
                if ((delay += Time.deltaTime) < 5)//wait 5 seconds before proceeding to target
                {
                    Roam.Roaming(this.gameObject);
                }
                else
                {
                    docked = Roam.ProceedToVector(this.gameObject, dockingPosition);
                }
                if (docked)
                {
                    Cloak();
                }
            }
            if (tag == "ReleasedGTP")
            {
                tag = "DyingGDP";
                StartCoroutine(ReleasingGTP());
                StartCoroutine(DestroyGTP()); //Destroy GDP
            }
        }
    }
Example #16
0
    /*  Function:   FixedUpdate()
     *  Purpose:    this function differs from Update in that, rather than being called once per frame,
     *              it may be called once, zero, or multiple times per frame depending on the speed
     *              of the physics frames per second. Not sure of the reasoning behind decision to use
     *              FixedUpdate rather than Update.
     *              Anyway, this function has the G-Protein search around for a Phosphate on a receptor
     *              dropped off by an ATP. If the G-Protein has a GTP instead of GDP,
     *              seeks out a Protein Kinase with which to bind. If there is nothing to seek,
     *              G-Protein roams aimlessly
     */
    private void FixedUpdate()
    {
        //IF G-Protein does not have a GTP(red) AND it does have GDP(blue)
        if (!haveGTP && transform.tag == "OccupiedG_Protein")
        {
            haveGTP = true;
        }

        //IF G-Protein is not targeting a phosphate AND G-Protein is not docked to receptor AND G-Protein does not have a GTP(red)
        if (!targeting && !docked && !haveGTP)
        {
            //Receptor phosphate = closest one to G-Protein
            openTarget = Roam.FindClosest(transform, "ReceptorPhosphate");

            //IF phosphate is found
            if (openTarget != null)
            {
                myTarget        = openTarget.transform;
                dockingPosition = GetOffset();
                LockOn();  //call dibs
            }
        }
        //ELSE IF G-Protein is not docked to receptor AND G-Protein does not have a GTP(red)                *On route to receptor phosphate
        else if (!docked && !haveGTP)
        {
            docked = ProceedToTarget();
            if (docked)
            {
                ReleaseGDP();
            }
        }

        //IF G-Protein has GTP(red) AND G-Protein is not ready to roam with attached GTP(red) AND wait time is over 2 seconds
        if (haveGTP && !roaming && (delay += Time.deltaTime) > 2)
        {
            Undock();
            //check if action is a win condition for the scene/level
            if (GameObject.FindWithTag("Win_GProteinFreed"))
            {
                WinScenario.dropTag("Win_GProteinFreed");
            }
        }
        //ELSE IF G-Protein has GTP(red) AND G-Protein is ready to roam with attached GTP(red)
        else if (haveGTP && roaming)
        {
            GameObject Kinase = Roam.FindClosest(transform, "Kinase");
            if (Kinase != null && !myTarget && isActive)
            {
                delay = 0;
                Kinase.GetComponent <KinaseCmdCtrl> ().GetObject(this.gameObject, "Kinase_Prep_A");
                myTarget = Kinase.transform;
            }

            if (myTarget && (delay += Time.deltaTime) >= 5)
            {
                isActive = false;
            }

            else if (isActive == true)
            {
                Roam.Roaming(this.gameObject);
            }
        }
        //ELSE have G-Protein roam
        else
        {
            Roam.Roaming(this.gameObject);
        }
    }
    private void FixedUpdate()
    {
        //IF G-Protein does not have a GTP(red) AND it does have GDP(blue)
        if (!haveGTP && transform.tag == "OccupiedG_Protein")
        {
            haveGTP = true;
        }

        //IF G-Protein is not targeting a phosphate AND G-Protein is not docked to receptor AND G-Protein does not have a GTP(red)
        if (!targeting && !docked && !haveGTP)
        {
            //Receptor phosphate = closest one to G-Protein
            openTarget = Roam.FindClosest(transform, "ReceptorPhosphate");


            //IF phosphate is found
            if (openTarget != null)
            {
                //Stop movement and set to kinematic   (David 03/05)
                //if(transform.GetComponent<Rigidbody2D>().isKinematic == false)
                //{
                //    transform.GetComponent<Rigidbody2D>().velocity = Vector3.zero;
                //    transform.GetComponent<BoxCollider2D>().enabled = true;
                //    transform.GetComponent<Rigidbody2D>().isKinematic = true;

                //    //transform.GetComponent<CircleCollider2D>().enabled = false;

                //}

                myTarget        = openTarget.transform;
                dockingPosition = GetOffset();
                LockOn();                   //call dibs
            }
        }

        //ELSE IF G-Protein is not docked to receptor AND G-Protein does not have a GTP(red)                *On route to receptor phosphate
        else if (!docked && !haveGTP)
        {
            docked = ProceedToTarget();

            if (docked)
            {
                ReleaseGDP();
            }
        }

        //IF G-Protein has GTP(red) AND G-Protein is not ready to roam with attached GTP(red) AND wait time is over 2 seconds
        if (haveGTP && !roaming && (delay += Time.deltaTime) > 2)
        {
            Undock();
            //check if action is a win condition for the scene/level
            if (GameObject.FindWithTag("Win_GProteinFreed"))
            {
                WinScenario.dropTag("Win_GProteinFreed");
            }
        }



        //ELSE IF G-Protein has GTP(red) AND G-Protein is ready to roam with attached GTP(red)
        else if (haveGTP && roaming)
        {
            /*
             * if (Kinase == null)
             * {
             *                  Kinase = Roam.FindClosest (transform, "Kinase");
             *      }
             *
             *          if (Kinase != null || myTarget != null)
             * {
             *                  Roam.FindAndWait (Kinase.GetComponent<KinaseCmdCtrl> (), this.gameObject, ref myTarget, ref delay, "Kinase_Prep_A");
             *                  if (myTarget != null && (delay) >= 5)
             *  {
             *
             *                  }
             *          }
             *
             * else
             * {
             *                  Roam.Roaming (this.gameObject);
             *          }
             */



            GameObject Kinase = Roam.FindClosest(transform, "Kinase");
            if (Kinase != null && !myTarget && isActive)
            {
                delay = 0;
                Kinase.GetComponent <KinaseCmdCtrl> ().GetObject(this.gameObject, "Kinase_Prep_A");
                myTarget = Kinase.transform;
            }

            if (myTarget && (delay += Time.deltaTime) >= 5)
            {
                isActive = false;
            }

            else if (isActive == true)
            {
                Roam.Roaming(this.gameObject);
            }
        }

        //ELSE have G-Protein roam
        else
        {
            Roam.Roaming(this.gameObject);
        }
    }
Example #18
0
    // Update is called once per frame
    // Each outer if block is to setup a state to tell the object which state
    // To perform actions for
    void FixedUpdate()
    {
        // Set active congratulations to inactive. Unity does not support activating inactive objects


        // Check if the time if the interaction did not complete reset back to before
        // The interaction was setup to occur
        if (timeoutForInteraction > timeoutMaxInterval)
        {
            // If the interaction is in the state of looking for a Kinase
            if (tag == "T_Reg_Prep_A" || tag == "T_Reg_Prep_B")
            {
                tag = "T_Reg";              // Reset the tag to when no interaction was setup to occur
                reset();                    // Reset Components of both objects
            }
            else if (tag == "ATP_tracking") // If ATP is Tracking this Transcription Regulator
            // Reset Components of the Transcription Regulator
            {
                this.gameObject.GetComponent <CircleCollider2D> ().enabled = true;
                this.gameObject.GetComponent <BoxCollider2D>().enabled     = true;

                // Reset the Timeout for Interaction
                timeoutForInteraction = 0.0f;

                // Set the T_Reg back to is Active
                isActive = true;
                this.tag = "ATP_tracking";
            }
        }


        // Default State when nothing is happening, T_Reg will just roam
        if (tag == "T_Reg")
        {
            Roam.Roaming(this.gameObject);
        }
        // Else enter the state of approaching a Kinase
        else if (tag == "T_Reg_Prep_A")
        {
            if ((delay += Time.deltaTime) >= 5.0f)  // If Time delay, is less than 5 seconds keep Roaming
            {
                if (!midpointSet)                   // If midpoint not set, setup the midpoint between
                // the paired Kinase and this T_Reg
                {
                    midpoint = Roam.CalcMidPoint(active_Kinase_P2, this.gameObject);

                    // Say the has now been set
                    midpointSet = true;
                }
                // Else Approach the midpoint, if this point has been achieved setup the next phase T_Reg_Prep_B
                else if (Roam.ApproachMidpoint(active_Kinase_P2, this.gameObject, midpointAchieved, midpoint, new Vector3(0.0f, 1.75f, 0.0f), 2.5f))
                {
                    delay = 0;

                    // Disable Collider Components
                    active_Kinase_P2.GetComponent <PolygonCollider2D> ().enabled = false;
                    this.GetComponent <BoxCollider2D> ().enabled = false;

                    // Set MidpointAchieved back to false
                    midpointAchieved [0] = midpointAchieved [1] = false;
                    tag = "T_Reg_Prep_B";                     // Enter the next state by changing the tag to T_Reg_Prep_B
                }
            }
            else
            {
                // Continue Roaming for 5 seconds after entering this state
                Roam.Roaming(this.gameObject);
            }
            // Increment the timeout variable by delta time
            timeoutForInteraction += Time.deltaTime;
        }
        // Else if tag is T_Reg_Prep_B, enter the state next phase of approaching the Kinase
        else if (tag == "T_Reg_Prep_B")
        {
            // If Midpoint has not been achieved, approach the midpoint
            if (!midpointAchieved [0] || !midpointAchieved [1])
            {
                // Proceed to the Kinase
                midpointAchieved [0] = Roam.ProceedToVector(active_Kinase_P2, midpoint + new Vector3(0.0f, 0.52f, 0.0f));
                midpointAchieved [1] = Roam.ProceedToVector(this.gameObject, midpoint + new Vector3(0.0f, -0.52f, 0.0f));
            }
            // Check if the midpoint has been achieved
            if (midpointAchieved [0] && midpointAchieved [1])
            {
                // Check if the kinase has a parent
                if (active_Kinase_P2.gameObject.transform.parent == null)
                {
                    // Set the kinase's parent to be this T_Reg
                    active_Kinase_P2.transform.parent = this.gameObject.transform;

                    // Switch kinase to move with the its parent
                    active_Kinase_P2.GetComponent <Rigidbody2D> ().isKinematic   = true;
                    active_Kinase_P2.GetComponent <PolygonCollider2D> ().enabled = false;

                    // Enable the Box Collider for this T_Reg
                    this.gameObject.GetComponent <BoxCollider2D> ().enabled = true;
                    // Enable the Circle Collider for the ATP to approach and "Dock"
                    this.gameObject.GetComponent <CircleCollider2D> ().enabled = true;

                    // Setup state for an ATP to come and dock with T_Regulator
                    timeoutForInteraction = 0;
                    delay = 0;
                    tag   = "ATP_tracking";
                }
            }
            //Increment the timeout variable by delta time
            timeoutForInteraction += Time.deltaTime;
        }
        // Else if tag is ATP_Tracking, wait for an ATP to Collide with the CircleCollider
        else if (tag == "ATP_tracking")
        {
            // Check if the T_Reg is active
            if (isActive == true)
            {
                // Find the Closest ATP
                GameObject ATP = Roam.FindClosest(transform, "ATP");

                // Check if the Closest ATP is not null, therefore one exists
                if (ATP != null)
                {
                    // Set the z position for the T_Regulator to be off the 0.0f
                    transform.position = new Vector3(transform.position.x, transform.position.y, 2.0f);

                    // Setup a Vector in 2D because we only care about distance in the x and y
                    Vector2[] pos = new Vector2[2];

                    // Collect the x and y values for this T_Reg and the ATP in separate Vector2 variables
                    pos [0] = new Vector2(transform.position.x, transform.position.y);
                    pos [1] = new Vector2(ATP.transform.position.x, ATP.transform.position.y);

                    // Check if the Distance between the the ATP and the T_Reg is less than 6.0f
                    if (Vector2.Distance(pos [0], pos [1]) < 6.0f)
                    {
                        // Set the T_Reg to be inactive because an ATP is close enough to dock
                        isActive = false;
                        // Disable the box Collider on this T_Reg
                        this.GetComponent <BoxCollider2D> ().enabled = false;
                    }
                }
                // Roam while the T_Reg is still active
                Roam.Roaming(this.gameObject);
            }

            //Increment the timeout variable by delta time
            timeoutForInteraction += Time.deltaTime;
        }
        // Else if tag is T_Reg_With_Phosphate, Enter this block
        else if (tag == "T_Reg_With_Phosphate")
        {
            // Check if T_Reg is active
            if (isActive == true)
            {
                // Check if Kinase is still active
                if (active_Kinase_P2 != null)
                {
                    //Enter the state of looking for the nearest NPC
                    this.tag = "T_Reg_To_NPC";

                    // Disable the Circle Collider the ATP was using
                    this.gameObject.GetComponent <CircleCollider2D> ().enabled = false;

                    // Reset the Kinase back to Kinase_Phase_2, when it was looking for a T_Reg
                    active_Kinase_P2.GetComponent <Rigidbody2D> ().isKinematic = false;
                    active_Kinase_P2.transform.parent = null;
                    active_Kinase_P2.GetComponent <KinaseCmdCtrl> ().reset();
                    active_Kinase_P2.tag = "Kinase_Phase_2";
                    active_Kinase_P2     = null;
                }

                // Roam while T_Reg is Active but not looking for a NPC
                Roam.Roaming(this.gameObject);
            }
            // Wait 3.5 Seconds after entering the stage where we have a phosphate
            else if ((delay += Time.deltaTime) > 3.5f && isActive == false)
            {
                // Time to release the Kinase and start looking for an NPC
                isActive = true;
                this.GetComponent <BoxCollider2D> ().enabled = true;
            }
        }
        // If tag is T_Reg_To_NPC, then start moving toward the nearest NPC;
        else if (tag == "T_Reg_To_NPC")
        {
            GameObject NPC          = Roam.FindClosest(this.transform, "NPC");
            Transform  nucTransform = Nucleus.transform;
            if (NPC != null)
            {             // calculate the distance and the approach vector
                float diffX    = NPC.transform.position.x - nucTransform.position.x;
                float diffY    = NPC.transform.position.y - nucTransform.position.y;
                float distance = (float)Math.Sqrt((diffX * diffX) + (diffY * diffY));
                float rads     = (float)Math.Atan2(diffY, diffX);

                Vector3 tempPosition = NPC.transform.position;
                tempPosition.x    = (distance + distanceOffset) * (float)Math.Cos(rads) + nucTransform.position.x;
                tempPosition.y    = (distance + distanceOffset) * (float)Math.Sin(rads) + nucTransform.position.y;
                tempPosition.z    = 2;
                ingressDistance   = tempPosition;
                ingressDistance.x = (distance - distanceOffset) * (float)Math.Cos(rads) + nucTransform.position.x;
                ingressDistance.y = (distance - distanceOffset) * (float)Math.Sin(rads) + nucTransform.position.y;
                // Check and move to the tempPosition, if we have then change state to T_Reg_To_Nucleus
                if (Roam.ApproachVector(this.gameObject, tempPosition, new Vector3(0, 0, 2), 0))
                {
                    this.tag = "T_Reg_To_Nucleus";
                }
            }
            else
            {
                Roam.Roaming(this.gameObject);
            }
        }
        // Check if Tag is T_Reg_To_Nucleus, proceed to the Nucleus
        else if (tag == "T_Reg_To_Nucleus")
        {
            // Turn off the Collider on the T_Reg so it can pass through the nucleus
            Physics2D.IgnoreCollision(Nucleus.GetComponent <Collider2D>(), GetComponent <Collider2D>(), true);

            // Approach the Nucleus's midpoint
            if (Roam.ProceedToVector(this.gameObject, ingressDistance))
            {             // T_Reg is in the Nucleus, Game is won
                Physics2D.IgnoreCollision(Nucleus.GetComponent <Collider2D>(), GetComponent <Collider2D>(), false);
                this.tag = "T_Reg_Complete";
            }
        }
        // Check if Tag is T_Reg_Complete,
        else if (tag == "T_Reg_Complete")
        {
            // Congratulations, the game is won
            {
                gameWon = true;                 // FOR CONGRATULATIONS SCREEN
                Roam.Roaming(this.gameObject);
            }
        }
    }
Example #19
0
 // Update is called once per frame
 void FixedUpdate()
 {
     Roam.Roaming(this.gameObject);
 }