// Grípa í fánastöng
    void GrabFlagpole(float flagpolePosX)
    {
        // Stilla animator rétt
        animator.SetBool("Jump", false);
        animator.SetBool("On Flagpole", true);

        // Færa leikmann á réttan stað
        MovePlayerXTo(flagpolePosX);
        SetFrozen(true);  // Leikmaður má ekki hreyfa sig
        // Spila hljóð
        audioManager.PlayAudio("Grab Flagpole");
    }
    private void Update()
    {
        if (Math.Abs(personageRB.velocity.y) >= 0.1f)
        {
            onAir = true;
        }
        else
        {
            onAir = false;
        }

        if (vidas.currentLives > 0)
        {
            if (Input.GetKeyDown(KeyCode.Space) && !onAir)
            {
                personageRB.AddForce(new Vector2(0, velocidadSalto), ForceMode.Impulse);
                personageRB.velocity = new Vector2(personageRB.velocity.x / 2, personageRB.velocity.y);
                playerAudio.PlayAudio(0);
                aController.ActivateJump();
            }

            float impulsoActual = impulsoHorizontal;

            if (onAir)
            {
                impulsoActual /= 10;
            }

            if (Input.GetKey(KeyCode.RightArrow))
            {
                transform.eulerAngles = new Vector3(0, 90, 0);

                if (personageRB.velocity.x < velocidadHorizontal)
                {
                    personageRB.AddForce(new Vector2(impulsoActual * StaticComponent.GetCurrentSpeed(), 0), ForceMode.Force);
                }
            }
            else if (Input.GetKey(KeyCode.LeftArrow))
            {
                transform.eulerAngles = new Vector3(0, -90, 0);

                if (personageRB.velocity.x > -velocidadHorizontal)
                {
                    personageRB.AddForce(new Vector2(-impulsoActual * StaticComponent.GetCurrentSpeed(), 0), ForceMode.Force);
                }
            }
            else
            {
                personageRB.AddForce(new Vector2(-4 * personageRB.velocity.x, 0), ForceMode.Force);
            }
        }
        else
        {
            personageRB.AddForce(new Vector2(-4 * personageRB.velocity.x, 0), ForceMode.Force);
        }
    }
示例#3
0
    private void PerderVidas()
    {
        if (currentLives > 0)
        {
            currentLives   -= 1;
            timerInvencible = 0;
            invencible      = true;
            aController.animator.SetBool("Invencible", invencible);

            gameManager.ActualizarVidas(currentLives);

            if (currentLives <= 0)
            {
                Kill();
            }
            else
            {
                playerAudio.PlayAudio(1);
            }
        }
    }
 public void Die()
 {
     // Ef leikmaður er ekki þegar að deyja, stoppa tónlist, spila dauðahljóð og endurræsa senu
     if (!isDying)
     {
         playerController.SetFrozen(true);
         isDying = true;
         backgroundAudio.Stop();
         audioManager.PlayAudio("Death");
         StartCoroutine("WaitThenRestartScene");
     }
 }
示例#5
0
    public void FlipGravity()
    {
        _gravityModifier  *= -1;
        Physics2D.gravity *= -1;
        _gravitySwitchesLeft--;

        if (_gravityModifier == -1)
        {
            transform.eulerAngles = new Vector2(180, transform.eulerAngles.y);
            playerAudio.PlayAudio("Gravity_Changed");
        }
        else
        {
            transform.eulerAngles = new Vector2(0, transform.eulerAngles.y + 180);
            playerAudio.StopAudio();
        }

        if (_gravitySwitchesLeft <= 0)
        {
            Die();
        }
    }
 public void PlayClick()
 {
     gameAudio.PlayAudio(0);
 }
 private void Run()
 {
     isFalling = false;
     playerAudio.PlayAudio(running, true);
 }
示例#8
0
    private void GetInput()
    {
        _moveDir = Input.GetAxisRaw("Horizontal");

        if (_isGrounded)
        {
            animator.SetFloat("Speed", Mathf.Abs(_moveDir));
        }
        else
        {
            animator.SetFloat("Speed", 0);
        }


        if (Input.GetButtonDown("Jump") && _isGrounded && _gravityModifier != -1)
        {
            _rb.AddForce(new Vector2(0, myProperties.jumpForce * _gravityModifier), ForceMode2D.Impulse);

            switch (activePlayer)
            {
            case ActivePlayer.Explosion:
                _playerAudio.PlayAudio("Flamey_Jump");
                break;

            case ActivePlayer.Gravity:
                _playerAudio.PlayAudio("Gravity_Jump");
                break;

            case ActivePlayer.Slime:
                _playerAudio.PlayAudio("Slime_Jump");
                break;

            default:
                break;
            }
        }

        if (Input.GetButtonDown("Fire1"))
        {
            switch (activePlayer)
            {
            case ActivePlayer.Explosion:
                Instantiate(explosionPrefab, transform.position, transform.rotation);
                Die();
                break;

            case ActivePlayer.Gravity:
                if (_gravitySwitchesLeft > 1)
                {
                    animator.SetTrigger("AbilityGravity");
                }
                break;

            case ActivePlayer.Teleport:
                if (_isGrounded)
                {
                    SpawnPortal();
                }
                break;

            case ActivePlayer.Slime:
                if (_isGrounded)
                {
                    animator.SetTrigger("AbilitySlime");
                }
                break;

            default:
                break;
            }
        }
    }
示例#9
0
 public void KillPlayer()
 {
     gameOver.StopGameScene();
     playerAudio.PlayAudio(hurt, false);
 }