示例#1
0
    void ThrowBoulder(float percent)
    {
        if (heldBoulder != null)
        {
            BoulderObject obj         = heldBoulder.GetComponent <BoulderObject>();
            Rigidbody2D   visualsBody = obj.visuals.GetComponent <Rigidbody2D>();
            visualsBody.isKinematic        = false;
            visualsBody.fixedAngle         = true;
            visualsBody.transform.rotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);

            int directionMultiplier = 0;
            if (facingRight == false)
            {
                directionMultiplier = -1;
            }
            else
            {
                directionMultiplier = 1;
            }
            float force = percent * boulderThrowForce;
            visualsBody.GetComponent <Rigidbody2D>().AddForce(new Vector2(directionMultiplier * force, 0.5f * force));            // to the side & a bit up

            heldBoulder = null;

            PlayThrowSound();
        }

        chargeBar.maxCharge = boulderPickupAmount;
    }
示例#2
0
    void CheckForBoulderDamage(GameObject boulderObject)
    {
        if (detectedCollisionBoulder == null)
        {
            BoulderObject body          = boulderObject.GetComponent <BoulderObject>();
            GameObject    visuals       = body.visuals;
            BoulderScript boulderScript = boulderObject.GetComponentInParent <BoulderScript>();

            Rigidbody2D rigidBody        = visuals.GetComponent <Rigidbody2D>();
            float       boulderMagnitude = rigidBody.velocity.sqrMagnitude;
            if (boulderMagnitude > 9.0f)
            {
                detectedCollisionBoulder = boulderObject;
                //print("Boulder velocity squared magnitude " + boulderMagnitude);

                // check held boulder shield
                float healthReduction = boulderScript.baseDamage + boulderScript.DamageBonus();
                if (heldBoulder != null)
                {
                    BoulderScript heldBoulderScript = heldBoulder.GetComponentInParent <BoulderScript>();
                    float         percentReduction  = heldBoulderScript.ShieldBonus() / 100.0f;
                    if (percentReduction > 0.0f)
                    {
                        healthReduction -= healthReduction * percentReduction;
                    }
                }

                // take damage
                health          -= healthReduction;
                healthBar.charge = health;

                PlayHitSound();

                // Death
                if (health <= 0.0f)
                {
                    ShowEndGameText();

                    // hide UI bars
                    healthBar.gameObject.SetActive(false);
                    chargeBar.gameObject.SetActive(false);

                    // dying
                    this.gameObject.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
                    //this.gameObject.SetActive(false);
                }
            }
        }
    }
示例#3
0
    public void UpdateChargeProgress(float percent)
    {
        if (heldBoulder != null && percent > 0.0f)
        {
            int directionMultiplier = 1;
            if (facingRight == false)
            {
                directionMultiplier = -1;
            }

            // rotate boulder
            float angle = directionMultiplier * percent * 45.0f;

            BoulderObject obj         = heldBoulder.GetComponent <BoulderObject>();
            Rigidbody2D   visualsBody = obj.visuals.GetComponent <Rigidbody2D>();
            visualsBody.transform.rotation = Quaternion.Euler(0.0f, 0.0f, angle);
        }
    }
示例#4
0
    public void FinishedChargingAction()
    {
        if (heldBoulder == null && potentialBoulder != null)
        {
            heldBoulder         = potentialBoulder;
            chargeBar.maxCharge = boulderChargeAmount;
            potentialBoulder    = null;

            PlayPickupSound();

            BoulderObject obj         = heldBoulder.GetComponent <BoulderObject>();
            Rigidbody2D   visualsBody = obj.visuals.GetComponent <Rigidbody2D>();
            visualsBody.isKinematic = true;
            visualsBody.fixedAngle  = false;
        }
        else if (heldBoulder != null)
        {
            ThrowBoulder(1.0f);
        }
    }
示例#5
0
    void PerformMovement(Direction direction)
    {
        // add movement
        int directionMultiplier = 0;

        if (direction == Direction.DirectionLeft)
        {
            directionMultiplier = -1;
        }
        else if (direction == Direction.DirectionRight)
        {
            directionMultiplier = 1;
        }

        if (hitWall == false)
        {
            if (directionMultiplier != 0)
            {
                animator.SetInteger("PlayerAnimationState", (int)AnimationState.AnimationStateToWalk);
            }
            else
            {
                animator.SetInteger("PlayerAnimationState", (int)AnimationState.AnimationStateToIdle);
            }

            // block movement while picking up a boulder
            if (potentialBoulder != null && heldBoulder == null && chargeBar.isCharging == true)
            {
                GetComponent <Rigidbody2D>().velocity = new Vector2(0.0f, 0.0f);
                return;
            }

            float speed = maxSpeed;
            if (heldBoulder != null)
            {
                BoulderScript heldBoulderScript = heldBoulder.GetComponentInParent <BoulderScript>();
                float         percentBonus      = heldBoulderScript.SpeedBonus() / 100.0f;
                if (percentBonus > 0.0f)
                {
                    speed += speed * percentBonus;
                }
            }

            GetComponent <Rigidbody2D>().velocity = new Vector2(directionMultiplier * speed, GetComponent <Rigidbody2D>().velocity.y);

            // dashing
            if (dashing == true)
            {
                if (currentDashDuration > 0.0f)
                {
                    currentDashDuration -= Time.deltaTime;

                    int dir = 1;
                    if (facingRight == false)
                    {
                        dir = -1;
                    }

                    GetComponent <Rigidbody2D>().AddForce(new Vector2(dir * dashForce, 0.0f));
                }
                else
                {
                    timeSinceLastDash   = 0.0f;
                    dashing             = false;
                    currentDashDuration = dashDuration;
                }
            }

            // play step sound
            if (directionMultiplier != 0 && grounded == true && HasEnoughTimePassedSinceLastStep() == true)
            {
                PlayWalkingSound();
            }
        }

        // update held boulder position
        if (heldBoulder != null)
        {
            BoulderObject obj = heldBoulder.GetComponent <BoulderObject>();

            Vector3 boulderPosition = this.transform.position;
            boulderPosition.y += 1.0f;
            obj.visuals.transform.position = boulderPosition;
        }

        // update UI bar positions
        // anochor to parent game object
        healthBar.UpdateWithParentPosition(this.transform.position);
        chargeBar.UpdateWithParentPosition(this.transform.position);
    }