Ejemplo n.º 1
0
    //negate damage from health, check if player is dead
    public void TakeDamage(int damage)
    {
        Debug.Log("Damage received: " + damage);

        //check player is not blocking
        if (!isBlocking)
        {
            currentHealth -= damage;
            healthBar.SetHealth(currentHealth);
            if (currentHealth > 0)
            {
                m_animator.SetTrigger("Hurt");
            }
            //player has no health left; DEAD
            else
            {
                Debug.Log("Dead");
                m_animator.SetTrigger("Death");
                //tell levelCanvas to pull up GameOver screen
                levelCanvas.SendMessage("InvokeMenuAfterDeath");
            }
        }
        else //player blocked attack
        {
            ManagingAudio.PlaySound("ESkill");
        }
    }
Ejemplo n.º 2
0
    public void TakeDamage(int damage)
    {
        // If damage take away from current health
        currentHealth -= damage;

        // Play hurt animation
        animator.SetTrigger("Hurt");
        ManagingAudio.PlaySound("Hurt");

        if (currentHealth <= 0)
        {
            ManagingAudio.PlaySound("Death");
            Die();
        }
    }
Ejemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        //user hits esc key to bring up pause menu
        if (Input.GetKeyDown("escape"))
        {
            //pause/freeze any animated things
            Time.timeScale = 0f;
            //activate pause menu
            pauseMenu.SetActive(true);
            //hide pause button as already paused
            pauseButton.SetActive(false);
        }

        // Increase timer that controls attack combo
        m_timeSinceAttack += Time.deltaTime;

        //Check if character just landed on the ground
        if (!m_grounded && m_groundSensor.State())
        {
            m_grounded = true;
            m_animator.SetBool("Grounded", m_grounded);
            ManagingAudio.PlaySound("Landing");
        }

        //Check if character just started falling
        if (m_grounded && !m_groundSensor.State())
        {
            m_grounded = false;
            m_animator.SetBool("Grounded", m_grounded);
        }

        // -- Handle input and movement --
        float inputX = Input.GetAxis("Horizontal");

        // Swap direction of sprite depending on walk direction
        if (inputX > 0) //moving right
        {
            GetComponent <SpriteRenderer>().flipX = false;
            m_facingDirection = 1;
        }
        else if (inputX < 0)    //moving left
        {
            GetComponent <SpriteRenderer>().flipX = true;
            m_facingDirection = -1;
        }

        // Move
        if (!m_rolling)
        {
            //translate rigidbody
            m_body2d.velocity = new Vector2(inputX * m_speed, m_body2d.velocity.y);

            //rigidbody is moving
            if (m_body2d.velocity.x != 0)
            {
                isMoving = true;
            }
            //not moving
            else
            {
                isMoving = false;
            }

            //only play moving sound when on ground, moving and game isnt paused
            if (isMoving && m_grounded && Time.timeScale == 1)
            {
                //check sound already playing
                if (!movementSrc.isPlaying)
                {
                    movementSrc.PlayScheduled(2.0f);
                }
            }
            else //stop sound
            {
                movementSrc.Stop();
            }
        }

        //facing right
        if (m_facingDirection == 1)
        {
            AttackPtL.SetActive(false);
            AttackPtR.SetActive(true);

            FirePointL.SetActive(false);
            FirePointR.SetActive(true);
        }
        else //moving left
        {
            AttackPtL.SetActive(true);
            AttackPtR.SetActive(false);

            FirePointL.SetActive(true);
            FirePointR.SetActive(false);
        }

        //Set AirSpeed in animator
        m_animator.SetFloat("AirSpeedY", m_body2d.velocity.y);

        //Attack
        //*****was 1f to slow attacks
        if (Input.GetKeyDown("w") && m_timeSinceAttack > 0.25f)
        {
            ManagingAudio.PlaySound("Melee");
            m_currentAttack++;

            // Loop back to one after third attack
            if (m_currentAttack > 3)
            {
                m_currentAttack = 1;
            }

            // Reset Attack combo if time since last attack is too large
            if (m_timeSinceAttack > 1.0f)
            {
                m_currentAttack = 1;
            }

            // Call one of three attack animations "Attack1", "Attack2", "Attack3"
            m_animator.SetTrigger("Attack" + m_currentAttack);

            // Reset timer
            m_timeSinceAttack = 0.0f;

            //attack enemy
            Attack();
        }

        if (Input.GetButtonDown("Fire1"))
        {
            if (projectile == null)
            {
                Debug.Log("projectile null");
            }

            if (m_facingDirection == 1)
            {
                projectile.SendMessage("FacingRight", true);
                Debug.Log("Trying to send msg");
            }
            else
            {
                projectile.SendMessage("FacingRight", false);
            }
        }

        // Block
        else if (Input.GetKeyDown("e"))
        {
            isBlocking = true;
            m_animator.SetTrigger("Block");
            m_animator.SetBool("IdleBlock", true);
        }
        //stop blocking
        else if (Input.GetKeyUp("e"))
        {
            isBlocking = false;
            m_animator.SetBool("IdleBlock", false);
        }

        //Jump
        else if ((Input.GetKeyDown("space") && m_grounded) || (Input.GetKeyDown("up") && m_grounded))
        {
            ManagingAudio.PlaySound("Jump");
            m_animator.SetTrigger("Jump");
            m_grounded = false;
            m_animator.SetBool("Grounded", m_grounded);
            m_body2d.velocity = new Vector2(m_body2d.velocity.x, m_jumpForce);
            m_groundSensor.Disable(0.2f);
        }
        //Run
        else if (Mathf.Abs(inputX) > Mathf.Epsilon)
        {
            // Reset timer
            m_delayToIdle = 0.05f;
            m_animator.SetInteger("AnimState", 1);
        }
        //Idle
        else
        {
            // Prevents flickering transitions to idle
            if (currentHealth > 0)
            {
                m_delayToIdle -= Time.deltaTime;
                if (m_delayToIdle < 0)
                {
                    m_animator.SetInteger("AnimState", 0);
                }
            }
        }

        // Called in slide animation.
        void AE_SlideDust()
        {
            Vector3 spawnPosition;

            if (m_facingDirection == 1)
            {
                spawnPosition = m_wallSensorR2.transform.position;
            }
            else
            {
                spawnPosition = m_wallSensorL2.transform.position;
            }

            if (m_slideDust != null)
            {
                // Set correct arrow spawn position
                GameObject dust = Instantiate(m_slideDust, spawnPosition, gameObject.transform.localRotation) as GameObject;
                // Turn arrow in correct direction
                dust.transform.localScale = new Vector3(m_facingDirection, 1, 1);
            }
        }
    }