void Update()
    {
        UpdateCamera();

        if (!gameControllerScript.isPaused)
        {
            /// PC Movement ///
            if (Time.timeScale > 0 && Health >= 25)
            {
                if (PlayerNumber == playerNumber.PlayerOne && useKeyboardControls == true && Health >= 25)
                {
                    float moveHorizontal;
                    float moveVertical;

                    // Keyboard input
                    if (Input.GetAxis ("Horizontal") != 0 || Input.GetAxis ("Vertical") != 0)
                    {
                        moveHorizontal = Input.GetAxis ("Horizontal");
                        moveVertical = Input.GetAxis ("Vertical");
                    }
                    else
                    {
                        // Mouse input
                        moveHorizontal = Input.GetAxis ("Mouse X");
                        moveVertical = Input.GetAxis ("Mouse Y");
                    }

                    Vector3 movement = new Vector3 (moveHorizontal, moveVertical, 0.0f);
                    rb.velocity = movement * speed;
                }
            }

            if (SpecialAbilityImage.fillAmount >= 1
                && Input.GetMouseButtonDown (1))
            {
                // When the player presses altfire while bar is greater than 0
                if (SpecialAbility == ability.Emp)
                {
                    AbilityActive = abilityActive.yes;
                    PlayerCollider.enabled = false;
                    SpecialAbilityActivateAudio.Play ();
                }
            }

            if (SpecialAbilityImage.fillAmount <= 0)
            {
                DeactivateSpecialAbilities ();
                SpecialAbilityImage.fillAmount += 0.1f * Time.deltaTime;

                if (SpecialAbility == ability.Emp)
                {
                    AbilityActive = abilityActive.no;
                    Shield.GetComponent<Animator> ().Play ("ShieldExit");
                    PlayerCollider.enabled = true;
                }
            }

            if (PlayerNumber == playerNumber.PlayerOne && useKeyboardControls == false && Health >= 25)
            {
                float moveHorizontalA = Input.GetAxis ("Horizontal P1");
                float moveVerticalA = Input.GetAxis ("Vertical P1");
                Vector3 movementA = new Vector3 (moveHorizontalA, moveVerticalA, 0.0f);
                rb.velocity = movementA * speed;
            }

            if (PlayerNumber == playerNumber.PlayerTwo)
            {
                float moveHorizontalB = Input.GetAxis ("Horizontal P2");
                float moveVerticalB = Input.GetAxis ("Vertical P2");
                Vector3 movementB = new Vector3 (moveHorizontalB, moveVerticalB, 0.0f);
                rb.velocity = movementB * speed;
            }

            rb.position = new Vector3 (rb.position.x, rb.position.y, 0);

            // Player boundaries
            GetComponent<Transform> ().position = new Vector3 (
                Mathf.Clamp (GetComponent<Transform> ().position.x, xBoundLower, xBoundUpper),
                Mathf.Clamp (GetComponent<Transform> ().position.y, yBoundLower, yBoundUpper),
                zBound
            );

            /// Shooting functionality ///

            // PC Controller Input.
            if ((Input.GetKey ("space") && Time.unscaledTime > nextFire && gameControllerScript.CurrentScore > -1 && Health > minHealth) ||
                (Input.GetKey (KeyCode.LeftControl) && Time.unscaledTime > nextFire && gameControllerScript.CurrentScore > -1 && Health > minHealth))
            {
                nextFire = Time.unscaledTime + fireRate * (1/Time.timeScale);
                Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
            }

            if ((Input.GetKeyUp ("space") && gameControllerScript.CurrentScore > -1 && Health > minHealth) ||
                (Input.GetKeyUp (KeyCode.LeftControl) && gameControllerScript.CurrentScore > -1 && Health > minHealth))
            {
            }

            // Controller Input.
            if (PlayerNumber == playerNumber.PlayerOne && Health >= 25)
            {
                if (Time.timeScale > 0) {
                    if (((Input.GetAxisRaw ("Fire P1") > 0.1f || Input.GetMouseButton (0)) && Time.unscaledTime > nextFire && gameControllerScript.CurrentScore > -1 && Health > minHealth)) {
                        nextFire = Time.unscaledTime + fireRate * (1 / Time.timeScale);
                        Instantiate (shot, shotSpawn.position, shotSpawn.rotation);
                    }

                    if (((Input.GetAxisRaw ("Alt Fire P1") > 0.3f || Input.GetMouseButton (1)) && gameControllerScript.CurrentScore > -1 && Health > minHealth && isClone == false) ||
                       (Input.GetKeyDown ("joystick 1 button 2") && gameControllerScript.CurrentScore > 0 && Health > minHealth && isClone == false)) {
                        // When the player presses altfire while bar is greater than 0
                        if (SpecialAbilityImage.fillAmount > 0.25f)
                        {
                            if (SpecialAbility == ability.Emp)
                            {
                                Shield.SetActive (true);
                                Shield.GetComponent<Animator> ().Play ("ShieldEntry");
                                AbilityActive = abilityActive.yes;
                                PlayerCollider.enabled = false;
                                SpecialAbilityActivateAudio.Play ();
                            }
                        }
                    }

                    if (Input.GetAxisRaw ("Alt Fire P1") <= 0.3f) {
                    }

                    if (((Input.GetAxisRaw ("Alt Fire P1") <= 0 || Input.GetMouseButtonUp (1)) && gameControllerScript.CurrentScore > 0 && Health > minHealth && isClone == false) ||
                       (Input.GetKeyDown ("joystick 1 button 2") && gameControllerScript.CurrentScore > 0 && Health > minHealth && isClone == false)) {
                    }
                }
            }

            CheckPowerupTime ();

            if (AbilityActive == abilityActive.no && SpecialAbilityImage.fillAmount > 0 && SpecialAbilityImage.fillAmount < 1)
            {
                SpecialAbilityImage.fillAmount += 0.1f * Time.unscaledDeltaTime;
            }

            if (AbilityActive == abilityActive.yes && SpecialAbilityImage.fillAmount <= 1)
            {
                SpecialAbilityImage.fillAmount -= 0.2f * Time.unscaledDeltaTime;
                PlayerCollider.enabled = false;
            }

            if (AbilityActive == abilityActive.yes && SpecialAbilityImage.fillAmount <= 0)
            {
                AbilityActive = abilityActive.no;
                Shield.GetComponent<Animator> ().Play ("ShieldExit");
                SpecialAbilityDeactivateAudio.Play ();
                PlayerCollider.enabled = true;
            }

            ComboN = Mathf.RoundToInt (ComboTime);

            if (ComboTime > 11)
            {
                ComboTime = 11;
            }

            if (ComboTime < 0)
            {
                ComboTime = 0;
            }

            if (ComboN > 10)
            {
                ComboN = 10;
            }

            if (collisionCooldown > 0)
            {
                collisionCooldown -= Time.unscaledDeltaTime;
                PlayerCollider.enabled = false;
            }

            if (collisionCooldown <= 0 && AbilityActive == abilityActive.no)
            {
                collisionCooldown = 0;
                PlayerCollider.enabled = true;
            }

            if (isClone == false && Health >= 25)
            {
            }

            if (Health < 25)
            {
                //Camera.main.transform.position = new Vector3 (PlayerMesh.transform.position.x, PlayerMesh.transform.position.y, -100);
            }

            CheckIfClone ();
        }
    }
Ejemplo n.º 2
0
    void Update()
    {
        UpdateCamera();

        if (!gameControllerScript.isPaused)
        {
            /// PC Movement ///
            if (Time.timeScale > 0 && Health >= 25)
            {
                if (PlayerNumber == playerNumber.PlayerOne && useKeyboardControls == true && Health >= 25)
                {
                    float moveHorizontal;
                    float moveVertical;

                    // Keyboard input
                    if (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0)
                    {
                        moveHorizontal = Input.GetAxis("Horizontal");
                        moveVertical   = Input.GetAxis("Vertical");
                    }
                    else
                    {
                        // Mouse input
                        moveHorizontal = Input.GetAxis("Mouse X");
                        moveVertical   = Input.GetAxis("Mouse Y");
                    }

                    Vector3 movement = new Vector3(moveHorizontal, moveVertical, 0.0f);
                    rb.velocity = movement * speed;
                }
            }

            if (SpecialAbilityImage.fillAmount >= 1 &&
                Input.GetMouseButtonDown(1))
            {
                // When the player presses altfire while bar is greater than 0
                if (SpecialAbility == ability.Emp)
                {
                    AbilityActive          = abilityActive.yes;
                    PlayerCollider.enabled = false;
                    SpecialAbilityActivateAudio.Play();
                }
            }

            if (SpecialAbilityImage.fillAmount <= 0)
            {
                DeactivateSpecialAbilities();
                SpecialAbilityImage.fillAmount += 0.1f * Time.deltaTime;

                if (SpecialAbility == ability.Emp)
                {
                    AbilityActive = abilityActive.no;
                    Shield.GetComponent <Animator> ().Play("ShieldExit");
                    PlayerCollider.enabled = true;
                }
            }

            if (PlayerNumber == playerNumber.PlayerOne && useKeyboardControls == false && Health >= 25)
            {
                float   moveHorizontalA = Input.GetAxis("Horizontal P1");
                float   moveVerticalA   = Input.GetAxis("Vertical P1");
                Vector3 movementA       = new Vector3(moveHorizontalA, moveVerticalA, 0.0f);
                rb.velocity = movementA * speed;
            }

            if (PlayerNumber == playerNumber.PlayerTwo)
            {
                float   moveHorizontalB = Input.GetAxis("Horizontal P2");
                float   moveVerticalB   = Input.GetAxis("Vertical P2");
                Vector3 movementB       = new Vector3(moveHorizontalB, moveVerticalB, 0.0f);
                rb.velocity = movementB * speed;
            }

            rb.position = new Vector3(rb.position.x, rb.position.y, 0);

            // Player boundaries
            GetComponent <Transform> ().position = new Vector3(
                Mathf.Clamp(GetComponent <Transform> ().position.x, xBoundLower, xBoundUpper),
                Mathf.Clamp(GetComponent <Transform> ().position.y, yBoundLower, yBoundUpper),
                zBound
                );

            /// Shooting functionality ///

            // PC Controller Input.
            if ((Input.GetKey("space") && Time.unscaledTime > nextFire && gameControllerScript.CurrentScore > -1 && Health > minHealth) ||
                (Input.GetKey(KeyCode.LeftControl) && Time.unscaledTime > nextFire && gameControllerScript.CurrentScore > -1 && Health > minHealth))
            {
                nextFire = Time.unscaledTime + fireRate * (1 / Time.timeScale);
                Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
            }

            if ((Input.GetKeyUp("space") && gameControllerScript.CurrentScore > -1 && Health > minHealth) ||
                (Input.GetKeyUp(KeyCode.LeftControl) && gameControllerScript.CurrentScore > -1 && Health > minHealth))
            {
            }

            // Controller Input.
            if (PlayerNumber == playerNumber.PlayerOne && Health >= 25)
            {
                if (Time.timeScale > 0)
                {
                    if (((Input.GetAxisRaw("Fire P1") > 0.1f || Input.GetMouseButton(0)) && Time.unscaledTime > nextFire && gameControllerScript.CurrentScore > -1 && Health > minHealth))
                    {
                        nextFire = Time.unscaledTime + fireRate * (1 / Time.timeScale);
                        Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
                    }

                    if (((Input.GetAxisRaw("Alt Fire P1") > 0.3f || Input.GetMouseButton(1)) && gameControllerScript.CurrentScore > -1 && Health > minHealth && isClone == false) ||
                        (Input.GetKeyDown("joystick 1 button 2") && gameControllerScript.CurrentScore > 0 && Health > minHealth && isClone == false))
                    {
                        // When the player presses altfire while bar is greater than 0
                        if (SpecialAbilityImage.fillAmount > 0.25f)
                        {
                            if (SpecialAbility == ability.Emp)
                            {
                                Shield.SetActive(true);
                                Shield.GetComponent <Animator> ().Play("ShieldEntry");
                                AbilityActive          = abilityActive.yes;
                                PlayerCollider.enabled = false;
                                SpecialAbilityActivateAudio.Play();
                            }
                        }
                    }

                    if (Input.GetAxisRaw("Alt Fire P1") <= 0.3f)
                    {
                    }

                    if (((Input.GetAxisRaw("Alt Fire P1") <= 0 || Input.GetMouseButtonUp(1)) && gameControllerScript.CurrentScore > 0 && Health > minHealth && isClone == false) ||
                        (Input.GetKeyDown("joystick 1 button 2") && gameControllerScript.CurrentScore > 0 && Health > minHealth && isClone == false))
                    {
                    }
                }
            }

            CheckPowerupTime();

            if (AbilityActive == abilityActive.no && SpecialAbilityImage.fillAmount > 0 && SpecialAbilityImage.fillAmount < 1)
            {
                SpecialAbilityImage.fillAmount += 0.1f * Time.unscaledDeltaTime;
            }

            if (AbilityActive == abilityActive.yes && SpecialAbilityImage.fillAmount <= 1)
            {
                SpecialAbilityImage.fillAmount -= 0.2f * Time.unscaledDeltaTime;
                PlayerCollider.enabled          = false;
            }

            if (AbilityActive == abilityActive.yes && SpecialAbilityImage.fillAmount <= 0)
            {
                AbilityActive = abilityActive.no;
                Shield.GetComponent <Animator> ().Play("ShieldExit");
                SpecialAbilityDeactivateAudio.Play();
                PlayerCollider.enabled = true;
            }

            ComboN = Mathf.RoundToInt(ComboTime);

            if (ComboTime > 11)
            {
                ComboTime = 11;
            }

            if (ComboTime < 0)
            {
                ComboTime = 0;
            }

            if (ComboN > 10)
            {
                ComboN = 10;
            }

            if (collisionCooldown > 0)
            {
                collisionCooldown     -= Time.unscaledDeltaTime;
                PlayerCollider.enabled = false;
            }

            if (collisionCooldown <= 0 && AbilityActive == abilityActive.no)
            {
                collisionCooldown      = 0;
                PlayerCollider.enabled = true;
            }

            if (isClone == false && Health >= 25)
            {
            }

            if (Health < 25)
            {
                //Camera.main.transform.position = new Vector3 (PlayerMesh.transform.position.x, PlayerMesh.transform.position.y, -100);
            }

            CheckIfClone();
        }
    }
 void DeactivateSpecialAbilities()
 {
     AbilityActive = abilityActive.no;
     SpecialAbilityDeactivateAudio.Play ();
 }
Ejemplo n.º 4
0
 void DeactivateSpecialAbilities()
 {
     AbilityActive = abilityActive.no;
     SpecialAbilityDeactivateAudio.Play();
 }