Example #1
0
        private void Sprint()
        {
            if (currentStamina == maxStamina)
            {
                isSpriniting = true;
            }

            if (isSpriniting && SprintBtn() == true && z != 0)
            {
                currentStamina -= amount;
                staminaBar.SetStamina(currentStamina);
                Move(sprintSpeed);

                if (regen != null)
                {
                    StopCoroutine(regen);
                }

                regen = StartCoroutine(RechargeStamina(1.1f));
            }

            if (currentStamina <= 0)
            {
                currentStamina = 0;
                isSpriniting   = false;
            }
        }
    private void Update()
    {
        if (Input.GetKey(KeyCode.LeftShift) && (m_Stamina >= 0) && (m_CurrentCooldown >= m_Cooldown))
        {
            Dash();
        }
        else
        {
            IsShaking = false;
            if (m_Stamina < 3)
            {
                m_Stamina += 0.1f * Time.deltaTime;
            }
        }
        staminaBar.SetStamina(m_Stamina);

        if (IsShaking)
        {
            Shake(0.4f);
            Time.timeScale = 5;
        }
        else
        {
            Time.timeScale = 1;
        }
        if (m_Stamina <= 0)
        {
            m_CurrentCooldown = 0;
        }
        if (m_CurrentCooldown < m_Cooldown)
        {
            m_CurrentCooldown += 1f * Time.deltaTime;
        }
    }
Example #3
0
 void GainStamina(float gain)
 {
     if (currentStamina <= 100f)
     {
         currentStamina += gain;
         sb.SetStamina(currentStamina);
     }
 }
Example #4
0
 void StaminaRegen()
 {
     if (Time.time >= nextStaminaRegenTime)
     {
         if (currentStamina < maxHealth)
         {
             currentStamina += staminaRegen;
             staminaBar.SetStamina(currentStamina);
             nextStaminaRegenTime = Time.time + 1f / staminaRegenRate;
         }
     }
 }
Example #5
0
    // Update is called once per frame
    void Update()
    {
        Punching();

        staminaBar.SetStamina(Stamina);

        //Plays the sound effect when punching
        if (Input.GetButtonDown("Attack"))
        {
            punchSound.Play();
        }

        if (isAttacking && Stamina > 0)
        {
            Stamina -= Time.deltaTime * 2.5f;
        }
        else
        {
            if (Stamina < maxStamina)
            {
                Stamina += Time.deltaTime * 2.5f;
            }
        }

        if (Stamina > 0f)
        {
            canAttack = true;
        }
        else
        {
            canAttack = false;
        }
    }
Example #6
0
    void Update()
    {
        // stamina stuff
        MaxStamina     = CurrentHealth;
        CurrentStamina = Math.Min(MaxStamina, CurrentStamina);  // restrict stamina to health

        // UI
        HealthBar.SetHealth(CurrentHealth);
        StaminaBar.SetStamina(CurrentStamina);

        CurrentAmmoText.text = CurrentAmmo.ToString();
        ReserveAmmoText.text = "∞";
    }
    // Update is called once per frame
    void Update()
    {
        spriteRenderer.sprite = currentWeapon.sprite;

        if (!Mathf.Approximately(joystick.Vertical, 0f) || !Mathf.Approximately(joystick.Horizontal, 0f))
        {
            player.lookDirection.Set(joystick.Horizontal, joystick.Vertical);

            if (waitTime <= 0)
            {
                animator.SetTrigger("Attack");

                currentWeapon.Attack(attackPoint, enemyLayers);

                waitTime = currentWeapon.delay;
                if (player.playerSpeed < 15)
                {
                    waitTime = currentWeapon.delay - ((Mathf.Pow(-0.05f * player.playerSpeed, 2f) + (player.playerSpeed) / 10) / 2);
                    if (waitTime <= 0)
                    {
                        waitTime = 0.1f;
                    }
                    staminaBar.SetMaxStamina(waitTime);
                }
                else
                {
                    waitTime = currentWeapon.delay - ((Mathf.Pow(-0.05f * 15, 2f) + (15) / 10) / 2);
                    staminaBar.SetMaxStamina(waitTime);
                }
                staminaBar.SetStamina(waitTime);
            }
        }

        waitTime -= Time.deltaTime;
        staminaBar.SetStamina(waitTime);
    }
Example #8
0
    // Update is called once per frame
    void Update()
    {
        //movement.x = Input.GetAxisRaw("Horizontal");

        //movement.y = Input.GetAxisRaw("Vertical");

        //Check Dash
        if (Input.GetKeyDown("left shift") && stamina >= 10)
        {
            if (stamina > 0)
            {
                stamina -= 33;
                staminaBar.SetStamina(stamina);
                delay     = 300; //Delay before extra speed runs out
                moveSpeed = 10f;
            }
        }

        if (delay > 0)
        {
            //Decrement delay
            delay--;
        }
        else
        {
            moveSpeed = 6f;
        }

        /*
         * else if (stamina < 100 && staminaTimeDelay == 0) //Check if Stamina has been used and needs recharging
         * {
         *  stamina++;
         *  staminaBar.SetStamina(stamina);
         *  staminaTimeDelay = 10;
         * }
         *
         * if (staminaTimeDelay > 0)
         * {
         *  staminaTimeDelay--;
         * }*/

        switch (movement.x)
        {
        case 1:
            animator.SetTrigger("Right");
            isMoving = true;
            break;

        case -1:
            animator.SetTrigger("Left");
            isMoving = true;
            break;

        default:
            switch (movement.y)
            {
            case 1:
                animator.SetTrigger("Up");
                isMoving = true;
                break;

            case -1:
                animator.SetTrigger("Down");
                isMoving = true;
                break;

            default:
                animator.SetTrigger("Idle");
                isMoving = false;
                break;
            }
            break;
        }
    }
 public void SetStaminaBar()
 {
     staminaBar.SetStamina(PlayerStats.instance.stamina);
     staminaBar.SetMaxStamina(PlayerStats.instance.maxStamina);
 }
Example #10
0
    void TakeStaminaDamage(int StaminaDecrease)
    {
        currentShield -= StaminaDecrease;

        staminaBar.SetStamina(currentStamina);
    }
Example #11
0
    void Update()
    {
        //Runniing
        if (Input.GetKey(KeyCode.LeftShift))
        {
            speed = RunSpeed;
        }
        //Sneaking
        else if (Input.GetKey(KeyCode.C))
        {
            speed = 1f;
        }
        else
        {
            speed = NewSpeed;
        }
        isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
        //For Landing animation to resume
        if (timertoLand > -1)
        {
            timertoLand -= Time.deltaTime;
        }
        if (jumped == true)
        {
            if (isGrounded == true)
            {
                if (timertoLand <= 0f)
                {
                    anim.SetTrigger("IsGrounded");
                    jumped = false;
                }
            }
        }
        //velocity resets at grounded
        if (isGrounded && velocity.y < 0)
        {
            velocity.y = -2f;
        }

        //Movement
        x = Input.GetAxis("Horizontal");
        z = Input.GetAxis("Vertical");
        if (player.transform.position.y < -10)
        {
            Player.GameOver();
        }


        //Player Attack
        if (Input.GetMouseButtonDown(0))
        {
            if (Stamina > 10)
            {
                //transform.hasChanged = false;

                anim.SetTrigger("Attack");
                anim.SetInteger("condition", 0);
                //Collision Check
                Stamina = Stamina - 10;
                StaminaBar.SetStamina(Stamina);
                Collider[] hitEnemies = Physics.OverlapSphere(attackPoint.position, attackRange, enemyLayers);
                foreach (Collider enemy in hitEnemies)
                {
                    enemy.GetComponent <EnemyScript>().TakeDamage(Strength);
                    enemy.GetComponent <EnemyScript>().CheckDeath();
                    Sword.Play();
                }
            }
        }
        //Configures correct animations based on direction of run in relation to the face of the mouse
        if (transform.hasChanged)
        {
            Stamina = Stamina - (StaminaDec * Time.deltaTime);
            StaminaBar.SetStamina(Stamina);
            if (Input.GetKey(KeyCode.LeftShift))
            {
                if (x < 0)
                {
                    anim.SetInteger("condition", 14);   //LEFT
                    transform.hasChanged = false;
                    StaminaDec           = 10f;
                }
                else if (x > 0)
                {
                    anim.SetInteger("condition", 15);   //Right
                    transform.hasChanged = false;
                    StaminaDec           = 10f;
                }
                else if ((x == 0) && (z > 0))
                {
                    anim.SetInteger("condition", 2);   //walk
                    transform.hasChanged = false;
                    StaminaDec           = 10f;
                }
                else if ((x == 0) && (z < 0))
                {
                    anim.SetInteger("condition", 13);   //Backwards
                    transform.hasChanged = false;
                    StaminaDec           = 10f;
                }
                else
                {
                    anim.SetInteger("condition", 0);
                    transform.hasChanged = false;
                }
            }
            else if (Input.GetKey(KeyCode.C))
            {
                anim.SetInteger("condition", 4);
                transform.hasChanged = false;
                if (Stamina < MaxStamina)
                {
                    StaminaDec = -30f;
                }
                else
                {
                    StaminaDec = 0f;
                }
            }
            else
            {
                if (x < 0)
                {
                    anim.SetInteger("condition", 10);   //LEFT
                    transform.hasChanged = false;
                    StaminaDec           = .05f;
                }
                else if (x > 0)
                {
                    anim.SetInteger("condition", 11);   //Right
                    transform.hasChanged = false;
                    StaminaDec           = .05f;
                }
                else if ((x == 0) && (z > 0))
                {
                    anim.SetInteger("condition", 1);   //walk
                    transform.hasChanged = false;
                    StaminaDec           = .05f;
                }
                else if ((x == 0) && (z < 0))
                {
                    anim.SetInteger("condition", 12);   //Backwards
                    transform.hasChanged = false;
                    StaminaDec           = .05f;
                }
                else
                {
                    anim.SetInteger("condition", 0);
                    transform.hasChanged = false;
                }
            }
        }
        else
        {
            if (Stamina < MaxStamina)
            {
                Stamina = Stamina + (75f * Time.deltaTime);
                StaminaBar.SetStamina(Stamina);
            }
            if (Input.GetKeyDown(KeyCode.Y))
            {
                anim.SetInteger("condition", 3);
            }
            else
            {
                anim.SetInteger("condition", 0);
            }
        }
        //Move transform when greater than 0 stamina
        Vector3 move = transform.right * x + transform.forward * z;

        if (Stamina > 0f)
        {
            controller.Move(move * speed * Time.deltaTime);
        }
        //Jump when grounded
        if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
        {
            anim.SetTrigger("Jump");
            jumped = true;
            Jump.Play();
            velocity.y   = Mathf.Sqrt(jumpHeight * -2f * gravity);
            timertoLand  = .2f;
            timertoLand -= Time.deltaTime;
        }
        //falling
        velocity.y += 3 * gravity * Time.deltaTime;
        controller.Move(velocity * Time.deltaTime);
    }
Example #12
0
    // Update is called once per frame
    void Update()
    {
        if (Stuck)
        {
            StrugglingPrompt.enabled = true;
            LastStrugglingTime      += Time.deltaTime;
            speed = 0;
            if (LastStrugglingTime > StrugglingSpeed)
            {
                StrugglingCounter  = 0;
                LastStrugglingTime = 0;
            }
            if (Input.GetKeyDown(KeyCode.E))
            {
                LastStrugglingTime = 0;
                StrugglingCounter++;
                if (StrugglingCounter > MaxStruggingCounter)
                {
                    StrugglingCounter = 0;
                    Stuck             = false;
                    // Disable slime for a while
                    if (LastSlime)
                    {
                        LastSlime.Release();
                    }
                    reviveSpeed = true;
                }
            }
        }
        else
        {
            StrugglingPrompt.enabled = false;
            if (reviveSpeed)
            {
                speed       = OriginalSpeed;
                reviveSpeed = false;
            }
            //speed = OriginalSpeed;

            float x = Input.GetAxis("Horizontal");
            float z = Input.GetAxis("Vertical");
            staminaBar.SetStamina(stamina);

            Vector3 move = transform.right * x + transform.forward * z;

            controller.Move(move * speed * Time.deltaTime);
            if (Input.GetKeyDown(KeyCode.LeftShift) && (stamina > 0))
            {
                isRunning = true;
            }
            if (Input.GetKeyUp(KeyCode.LeftShift))
            {
                isRunning = false;
            }
            if (isRunning)
            {
                speed    = 20f;
                stamina -= Time.deltaTime;
                if (stamina <= 0)
                {
                    stamina   = 0;
                    isRunning = false;
                }
            }
            if (!isRunning)
            {
                speed = OriginalSpeed;
                if (stamina < maxStamina)
                {
                    stamina += Time.deltaTime;
                }
                else if (stamina >= maxStamina)
                {
                    stamina = 5f;
                }
            }
            if (Input.GetKeyDown(KeyCode.Space) && ifRocket)
            {
                GameObject rocketObject = Instantiate(rocketPrefab);
                rocketObject.transform.position = transform.position;
                rocketObject.transform.forward  = transform.forward;
                ifRocket = false;
            }

            //Debug.Log(stamina+" "+speed);
        }
    }