public void DisableObjects()
    {
        Rigidbody2D[] rb      = Rigidbody2D.FindObjectsOfType(typeof(Rigidbody2D)) as Rigidbody2D[];
        GameObject[]  cannons = GameObject.FindGameObjectsWithTag("Cannon");
        GameObject[]  portals = GameObject.FindGameObjectsWithTag("Portal");

        foreach (Rigidbody2D obj in rb)
        {
            obj.constraints = RigidbodyConstraints2D.FreezeAll;
        }
        if (!m_wreckingBallReset)
        {
            ResetWreckingBalls();
        }

        foreach (GameObject cannon in cannons)
        {
            cannon.GetComponent <FireObject>().fireOnContact = false;
        }

        foreach (GameObject portal in portals)
        {
            if (portal.transform.GetChild(0).name == "2D Collider")
            {
                portal.transform.GetChild(0).gameObject.SetActive(false);
            }
        }
    }
    public void EnableObjects()
    {
        Rigidbody2D[] rb      = Rigidbody2D.FindObjectsOfType(typeof(Rigidbody2D)) as Rigidbody2D[];
        GameObject[]  cannons = GameObject.FindGameObjectsWithTag("Cannon");
        GameObject[]  portals = GameObject.FindGameObjectsWithTag("Portal");

        foreach (Rigidbody2D obj in rb)
        {
            obj.constraints = RigidbodyConstraints2D.None;
        }
        GameObject[] wreckingBalls = GameObject.FindGameObjectsWithTag("WreckingBall");
        foreach (var ball in wreckingBalls)
        {
            ball.transform.Find("AnchorPoint").GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezePosition;
        }
        m_wreckingBallReset = false;

        foreach (GameObject cannon in cannons)
        {
            cannon.GetComponent <FireObject>().fireOnContact = true;
        }

        foreach (GameObject portal in portals)
        {
            if (portal.transform.GetChild(0).name == "2D Collider")
            {
                portal.transform.GetChild(0).gameObject.SetActive(true);
            }
        }
    }
Example #3
0
    // Use this for initialization
    void Start()
    {
        introTimer = introDuration;
        Camera.main.GetComponent <VortexEffect>().angle = twirlEffectAngleInit;
        currentAction      = 0;
        actionsWithRepeats = new ArrayList();
        for (int i = 0; i < actions.Length; i++)
        {
            string s = (string)actions[i];
            for (int i2 = 0; i2 < timesToRepeatAction[i]; i2++)
            {
                actionsWithRepeats.Add(s);
            }
        }
        if (GameObject.Find("Player2") != null)
        {
            GameObject.Find("Player").transform.position   = GameObject.Find("Player2").transform.position;
            GameObject.Find("Player").transform.localScale = Vector3.one;
            facingRight = true;
            GameObject.Find("Player").GetComponent <Rigidbody2D>().velocity = Vector2.zero;
            Destroy(GameObject.Find("Player2"));
        }
        displayTime = 0;
        if (Application.loadedLevelName.Contains("1-"))
        {
            transform.Find("Camera").GetComponent <Skybox>().material  = skyboxs[0];
            Camera.main.GetComponent <FastBloom>().enabled             = true;
            Camera.main.GetComponent <ContrastStretchEffect>().enabled = false;
            Camera.main.GetComponent <ContrastEnhance>().enabled       = false;
        }
        else if (Application.loadedLevelName.Contains("2-"))
        {
            transform.Find("Camera").GetComponent <Skybox>().material  = skyboxs[1];
            Camera.main.GetComponent <FastBloom>().enabled             = false;
            Camera.main.GetComponent <ContrastStretchEffect>().enabled = true;
            Camera.main.GetComponent <ContrastEnhance>().enabled       = true;
        }
        else if (Application.loadedLevelName.Contains("3-"))
        {
            transform.Find("Camera").GetComponent <Skybox>().material  = skyboxs[2];
            Camera.main.GetComponent <FastBloom>().enabled             = false;
            Camera.main.GetComponent <ContrastStretchEffect>().enabled = false;
            Camera.main.GetComponent <ContrastEnhance>().enabled       = false;
        }
        starCollected = false;

        rigidbodyVelocities.Clear();
        rigidbodyPositions.Clear();
        rigidbodies.Clear();
        foreach (Rigidbody2D r in Rigidbody2D.FindObjectsOfType <Rigidbody2D>())
        {
            rigidbodyVelocities.Add(r.velocity);
            rigidbodyPositions.Add(r.position);
            rigidbodies.Add(r);
        }
        //jumpAxis = 1;
    }
Example #4
0
    // Start is called before the first frame update
    void Start()
    {
        Rigidbody2D[] allRB2D = Rigidbody2D.FindObjectsOfType(typeof(Rigidbody2D)) as Rigidbody2D[];
        for (int i = 0; i < allRB2D.Length; i++)
        {
            if (rb2dOne == null)
            {
                rb2dOne = allRB2D[i];
            }
            else if (rb2dTwo == null)
            {
                rb2dTwo = allRB2D[i];
            }
            else if (rb2dTtree == null)
            {
                rb2dTtree = allRB2D[i];
            }
        }


        inputAxis    = Vector3.zero;
        velocityAxis = Vector3.zero;
    }
Example #5
0
 void HandleSelection()
 {
     GUI.FocusControl(menuOptions[selectedIndex]);
     for (int i = 0; i < menuOptions.Length; i++)
     {
         if (selectedIndex == i)
         {
             if (i == 0)
             {
                 if (timeScale2 == 0)
                 {
                     foreach (Rigidbody2D r in Rigidbody2D.FindObjectsOfType <Rigidbody2D>())
                     {
                         r.velocity = (Vector2)rigidbodyVelocities[rigidbodies.IndexOf(r)];
                     }
                     foreach (GameObject go in starPics)
                     {
                         go.GetComponent <GUITexture>().enabled = false;
                     }
                 }
                 else
                 {
                     rigidbodyVelocities.Clear();
                     rigidbodyPositions.Clear();
                     rigidbodies.Clear();
                     foreach (Rigidbody2D r in Rigidbody2D.FindObjectsOfType <Rigidbody2D>())
                     {
                         rigidbodyVelocities.Add(r.velocity);
                         rigidbodyPositions.Add(r.position);
                         rigidbodies.Add(r);
                     }
                 }
                 if (!Input.GetKey(KeyCode.Space))
                 {
                     timeScale2 = 1 - timeScale2;
                 }
             }
             else if (i == menuOptions.Length - 4)
             {
                 if (PlayerPrefs.GetInt("Perk Points", 0) >= PlayerPrefs.GetInt("Sprint Speed Cost", perkCosts[0]) && PlayerPrefs.GetInt("Sprint Speed Cost", perkCosts[0]) <= perkMaxCosts[0])
                 {
                     PlayerPrefs.SetInt("Perk Points", PlayerPrefs.GetInt("Perk Points", 0) - PlayerPrefs.GetInt("Sprint Speed Cost", perkCosts[0]));
                     PlayerPrefs.SetInt("Sprint Speed Cost", PlayerPrefs.GetInt("Sprint Speed Cost", perkCosts[0]) + 1);
                     PlayerPrefs.SetFloat("Sprint Speed", PlayerPrefs.GetFloat("Sprint Speed", 0) + 10f);
                 }
             }
             else if (i == menuOptions.Length - 3)
             {
                 if (PlayerPrefs.GetInt("Perk Points", 0) >= PlayerPrefs.GetInt("Decrease Gravity Cost", perkCosts[1]) && PlayerPrefs.GetInt("Decrease Gravity Cost") <= perkMaxCosts[1])
                 {
                     PlayerPrefs.SetInt("Perk Points", PlayerPrefs.GetInt("Perk Points", 0) - PlayerPrefs.GetInt("Decrease Gravity Cost", perkCosts[1]));
                     PlayerPrefs.SetInt("Decrease Gravity Cost", PlayerPrefs.GetInt("Decrease Gravity Cost", perkCosts[1]) + 1);
                     PlayerPrefs.SetFloat("Decrease Gravity", PlayerPrefs.GetFloat("Decrease Gravity", 0) + .25f);
                 }
             }
             else if (i == menuOptions.Length - 2)
             {
                 AudioListener.volume = 1 - AudioListener.volume;
                 AudioListener.pause  = !AudioListener.pause;
             }
             else if (i == menuOptions.Length - 1)
             {
                 PlayerPrefs.DeleteAll();
                 PlayerPrefs.SetInt("Last Level Unlocked", lastLevelUnlockedInit);
                 foreach (GameObject g in GameObject.FindObjectsOfType <GameObject>())
                 {
                     Destroy(g);
                 }
                 Application.LoadLevel(0);
             }
             else
             {
                 Debug.Log(i);
                 Application.LoadLevel(selectedIndex);
             }
         }
     }
 }
Example #6
0
 // Update is called once per frame
 void FixedUpdate()
 {
     if (timeScale2 == 0)
     {
         foreach (Rigidbody2D r in Rigidbody2D.FindObjectsOfType <Rigidbody2D>())
         {
             r.velocity = Vector2.zero;
             r.position = (Vector2)rigidbodyPositions[rigidbodies.IndexOf(r)];
         }
         return;
     }
     introTimer -= Time.fixedDeltaTime * timeScale2;
     if (introTimer >= 0)
     {
         Camera.main.GetComponent <VortexEffect>().angle = twirlEffectAngleInit / introDuration * introTimer;
     }
     else
     {
         Camera.main.GetComponent <VortexEffect>().angle = 0;
     }
     playWalkAudioTimer += Time.fixedDeltaTime * timeScale2;
     foreach (GameObject go in GameObject.FindGameObjectsWithTag("GroundCheck"))
     {
         if (go.transform.IsChildOf(transform))
         {
             grounded = Physics2D.OverlapCircle(go.transform.position, groundCheckRadius, whatIsGround);
             if (grounded)
             {
                 transform.position = new Vector2(transform.position.x, transform.position.y + groundHoverAmount);
                 if (Physics2D.OverlapCircle(go.transform.position, groundCheckRadius, whatIsGround).gameObject.name.Contains("Grass") && Mathf.Abs(move) > 0 && playWalkAudioTimer > walkAudioPlayRate / Mathf.Abs(move))
                 {
                     playWalkAudioTimer = 0;
                     audios[walkAudios[currentWalkAudio]].Play();
                     currentWalkAudio++;
                     if (currentWalkAudio >= walkAudios.Length)
                     {
                         currentWalkAudio = 0;
                     }
                 }
                 break;
             }
         }
     }
     if (Input.GetKey(KeyCode.Z))
     {
         GetComponent <Rigidbody2D>().gravityScale = 1 - PlayerPrefs.GetFloat("Decrease Gravity", 0);
     }
     else
     {
         GetComponent <Rigidbody2D>().gravityScale = 1;
     }
     if (Input.GetKey(KeyCode.LeftShift))
     {
         speed = maxSpeed + PlayerPrefs.GetFloat("Sprint Speed", 0);
     }
     else
     {
         speed = maxSpeed;
     }
     move = Input.GetAxis("Horizontal") * speed;
     if (Input.GetJoystickNames().Length == 0)
     {
         if (!onWall && ((move > 0 && !facingRight) || (move < 0 && facingRight)))
         {
             Flip();
         }
     }
     else
     {
         if (move != 0 && Input.GetAxisRaw("Horizontal") == -transform.localScale.x)
         {
             Flip();
         }
     }
     if (!canControl)
     {
         move = xAxis * speed;
     }
     if (move != 0 && Physics2D.OverlapCircle(wallCheck1.position, wallCheckRadius, whatIsGround) && !Physics2D.OverlapCircle(wallCheck2.position, wallCheckRadius, whatIsGround))
     {
         transform.position = new Vector2(transform.position.x, transform.position.y + Vector2.Distance(wallCheck1.position, wallCheck2.position));
     }
     foreach (GameObject go in GameObject.FindGameObjectsWithTag("WallCheck"))
     {
         if (go.transform.IsChildOf(transform) && Physics2D.OverlapCircle(go.transform.position, wallCheckRadius, whatIsGround) && !Physics2D.OverlapCircle(go.transform.position, wallCheckRadius, whatIsGround).gameObject.name.Contains("(Wall Jump)"))
         {
             extraXVel = 0;
             move      = 0;
             break;
         }
     }
     onWall = false;
     foreach (GameObject go in GameObject.FindGameObjectsWithTag("WallCheck"))
     {
         if (go.transform.IsChildOf(transform) && Physics2D.OverlapCircle(go.transform.position, wallCheckRadius, whatIsGround) && Physics2D.OverlapCircle(go.transform.position, wallCheckRadius, whatIsGround).gameObject.name.Contains("(Wall Jump)"))
         {
             onWall    = true;
             extraXVel = 0;
             int x = 0;
             if (transform.position.x > go.transform.position.x)
             {
                 x = 1;
             }
             else
             {
                 x = -1;
             }
             if ((move > 0 && x < 0) || (move < 0 && x > 0))
             {
                 move = 0;
             }
             if ((Input.GetAxisRaw("Horizontal") == x || xAxis == x || (Input.GetJoystickNames().Length > 0 && Mathf.Sign(Input.GetAxisRaw("Horizontal")) != Mathf.Sign(pXAxis) && Mathf.RoundToInt(pXAxis) == -x)) && (Input.GetAxisRaw("Jump") == 1 || jumpAxis == 1))
             {
                 GetComponent <Rigidbody2D>().velocity = new Vector2(GetComponent <Rigidbody2D>().velocity.x, 0);
                 GetComponent <Rigidbody2D>().AddForce(Vector2.up * jumpForce);
                 int r = Mathf.RoundToInt(Random.Range(0, jumpAudios.Length));
                 audios[jumpAudios[r]].Play();
                 extraXVel = x * pushOfWallForce;
                 grounded  = false;
                 onWall    = false;
                 break;
             }
         }
     }
     extraXVel *= GetComponent <Rigidbody2D>().drag;
     if (move != 0)
     {
         GetComponent <Rigidbody2D>().velocity = new Vector2(move + extraXVel, GetComponent <Rigidbody2D>().velocity.y);
     }
     anim.SetFloat("Speed", Mathf.Abs(move));
     anim.speed = anim.GetFloat("Speed");
     if (Input.GetKeyDown(KeyCode.R))
     {
         Application.LoadLevel(Application.loadedLevel);
     }
     jumpAxis = 0;
 }