예제 #1
0
 void OnTriggerStay2D(Collider2D other)
 {
     if (!audio.isPlaying)
     {
         audio.Play();
     }
     if (other.gameObject.tag == "Player")
     {
         Vector3 vec3 = transform.parent.parent.FindChild(mapEngine.ActiveRoom()).FindChild("PitSpawn").position;
         other.transform.position = new Vector3(vec3.x, vec3.y, -1.0f);
     }
     else if (other.gameObject.name == "Clone")
     {
         Vector3 vec3 = transform.parent.parent.FindChild(mapEngine.ActiveRoom()).FindChild("PitSpawnClone").position;
         other.transform.position = new Vector3(vec3.x, vec3.y, -1.0f);
     }
     else if (other.gameObject.name.StartsWith("move"))
     {
         BoxCollider2D[] cols = other.gameObject.GetComponents <BoxCollider2D> ();
         for (int i = 0; i < cols.Length; i++)
         {
             cols[i].enabled = false;
         }
         this.gameObject.GetComponent <BoxCollider2D> ().enabled = false;
     }
 }
예제 #2
0
 void FixedUpdate()
 {
     //move only when player is in the room
     if (mapEngine.ActiveRoom() == transform.parent.gameObject.name)
     {
         if (Input.GetButtonUp("Action"))                //toggle can move by action button
         {
             if (canMove)
             {
                 canMove = false;
             }
             else
             {
                 canMove = true;
                 clone   = transform.parent.Find("Clone").gameObject;
             }
         }
     }
     else
     {
         canMove = false;
         clone.GetComponent <ShadowPlayer>().SetAnimation(new Vector3(0, 0, 0));
     }
     if (canMove)
     {
         Vector2 temp = clone.transform.position;
         float   x    = Input.GetAxis("Horizontal");
         float   y    = Input.GetAxis("Vertical");
         temp.x += x * speed * (Time.deltaTime * 4);
         temp.y += y * speed * (Time.deltaTime * 4);
         clone.transform.position = temp;
         clone.GetComponent <ShadowPlayer>().SetAnimation(new Vector3(x, y, 0));
     }
 }
예제 #3
0
    void FixedUpdate()
    {
        clone = GameObject.Find("Clone");
        if (clone != null)
        {
            if (!seenPlayer)
            {
                if (mapEngine.ActiveRoom() == transform.parent.gameObject.name)                   //if player in the room
                //reward player + time
                {
                    if (temple.SecondsLeft() < temple.InitialTime)
                    {
                        temple.Buff(Time.deltaTime * 2f);
                    }
                }

                //wander behaviour
                if (counter == maxCount)
                {
                    counter = 0;
                    clone.transform.GetComponent <Rigidbody2D>().velocity = Vector2.zero;
                    Vector2 init = Vector2.zero;

                    // get point on first big circle
                    float c1x = Random.Range(radius1 * (-1), radius1);
                    int   g   = Random.Range(-1, 2);
                    float c1y = g * Mathf.Sqrt(radius1 * radius1 - c1x * c1x);
                    init.x += c1x;
                    if (float.IsNaN(c1y))
                    {
                        c1y = 0;
                    }
                    init.y += c1y;

                    //get point on second small circle
                    float c2x = Random.Range(radius1 * (-1), radius1);
                    g = Random.Range(-1, 2);
                    float c2y = g * Mathf.Sqrt(radius2 * radius2 - c2x * c2x);
                    init.x += c2x;
                    if (float.IsNaN(c2y))
                    {
                        c2y = 0;
                    }
                    init.y += c2y;

                    init.Normalize();

                    clone.GetComponent <ShadowPlayer>().SetVelocity(new Vector3(init.x, init.y, transform.position.z));
                }
                else
                {
                    counter++;
                }
            }
            else
            {
                //penalise player
                temple.Penalise(0.6f);

                //chase player behaviour
                seek();

                // Add steering component to the current velocity and desired speed
                currentVelocity = currentVelocity + steering / this.mass;
                currentVelocity.Normalize();
                currentVelocity *= speed;

                // Set the velocity to the rigidbody ’s velocity .
                clone.GetComponent <ShadowPlayer>().SetVelocity(currentVelocity);
            }

            //raycast to check for players
            RaycastHit2D hit1 = Physics2D.Raycast(clone.transform.position, Vector2.down);
            RaycastHit2D hit2 = Physics2D.Raycast(clone.transform.position, Vector2.up);
            RaycastHit2D hit3 = Physics2D.Raycast(clone.transform.position, Vector2.left);
            RaycastHit2D hit4 = Physics2D.Raycast(clone.transform.position, Vector2.right);

            if (hit1.collider != null && hit1.transform.name == "Player" ||
                hit2.collider != null && hit2.transform.name == "Player" ||
                hit3.collider != null && hit3.transform.name == "Player" ||
                hit4.collider != null && hit4.transform.name == "Player")
            {
                seenPlayer = true;
            }
            else
            {
                seenPlayer = false;
            }
        }
    }