Beispiel #1
0
    private Arrow getRandomArrowType(GameObject arrowThing)
    {
        Arrow     arrowComponent = null;
        ArrowType type           = ArrowType.Arrow;
        bool      validResult    = false;
        int       numberOfTries  = 0;

        do
        {
            int value = Random.Range(0, 100);
            if (value > 85)
            {
                type = ArrowType.FireArrow;
            }
            else if (value > 65)
            {
                type = ArrowType.SplitArrow;
            }
            else if (value > 50)
            {
                type = ArrowType.IceArrow;
            }
            else if (value > 35)
            {
                type = ArrowType.ForceArrow;
            }
            else if (value > 20)
            {
                type = ArrowType.PiercingArrow;
            }
            else
            {
                type = ArrowType.TreeArrow;
            }

            if (quiver.pullArrow(type))
            {
                switch (type)
                {
                case ArrowType.FireArrow:
                    arrowComponent = arrowThing.AddComponent <FireArrow> ();
                    break;

                case ArrowType.IceArrow:
                    arrowComponent = arrowThing.AddComponent <IceArrow> ();
                    break;

                case ArrowType.ForceArrow:
                    arrowComponent = arrowThing.AddComponent <ForceArrow> ();
                    break;

                case ArrowType.SplitArrow:
                    arrowComponent = arrowThing.AddComponent <SplitArrow> ();
                    break;

                case ArrowType.PiercingArrow:
                    arrowComponent = arrowThing.AddComponent <PiercingArrow> ();
                    break;

                case ArrowType.TreeArrow:
                    arrowComponent = arrowThing.AddComponent <TreeArrow> ();
                    break;

                default:
                    arrowComponent = arrowThing.AddComponent <Arrow>();
                    break;
                }
                validResult = true;
            }
            numberOfTries++;
        } while (!validResult && numberOfTries < 3);

        if (!arrowComponent)
        {
            arrowComponent = arrowThing.AddComponent <Arrow>();
        }
        return(arrowComponent);
    }
Beispiel #2
0
    public override void Update()
    {
        base.Update();

        if ((canShoot || canSpecialShot) && !quiverReady)
        {
            tutorialQuiver();
        }

        Quaternion direction = Quaternion.LookRotation(getMouseDirection());
        Vector3    extraZ    = direction * (new Vector3(0, 0, 1.3f));

        if (!isDead)
        {
            if (((Input.GetMouseButton(0) && canShoot) || (Input.GetMouseButton(1) && canSpecialShot && currentAmmo != ArrowType.Arrow)) && shotTimer >= bow.getReloadDelay())
            {
                if (!(Input.GetMouseButton(0) && Input.GetMouseButton(1)))
                {
                    if (!isCharging)
                    {
                        if (Input.GetMouseButton(1) && quiver.arrowInQuiver(currentAmmo))
                        {
                            bow.initializeRangeIndicator(direction, currentAmmo, true);
                        }
                        else
                        {
                            bow.initializeRangeIndicator(direction, ArrowType.Arrow, true);
                        }
                    }

                    bow.updateIndicator(direction);
                    bow.Charge();
                    isCharging = true;
                    if (currentMovementSpeed > chargingMovementSpeed)
                    {
                        currentMovementSpeed -= Time.deltaTime;
                    }
                }
                else
                {
                    bow.resetCharge();
                    isCharging           = false;
                    currentMovementSpeed = movementSpeed;
                    shotTimer            = 0.90f;
                }
            }
            else if (Input.GetMouseButtonUp(0) && shotTimer >= bow.getReloadDelay() && isCharging && canShoot)
            {
                this.rigidbody.velocity = new Vector3(0, 0, 0);
                GameObject arrowThing = (GameObject)Instantiate(Resources.Load("ArrowPrefab"), this.transform.position + extraZ, direction);

                Arrow arrowComponent = arrowThing.AddComponent <Arrow> ();

                arrowComponent.owner = this.gameObject;
                bow.Release(direction, arrowThing);
                isCharging = false;
                shotTimer  = 0;
                moveTimer  = 0;
                if (!isSlowed)
                {
                    currentMovementSpeed = movementSpeed;
                }
            }
            else if (Input.GetMouseButtonUp(1) && shotTimer >= bow.getReloadDelay() && isCharging && canSpecialShot)
            {
                this.rigidbody.velocity = new Vector3(0, 0, 0);
                GameObject arrowThing = (GameObject)Instantiate(Resources.Load("ArrowPrefab"), this.transform.position + extraZ, direction);

                Arrow arrowComponent = null;
                if (quiver.pullArrow(currentAmmo))
                {
                    switch (currentAmmo)
                    {
                    case ArrowType.FireArrow:
                        arrowComponent = arrowThing.AddComponent <FireArrow> ();
                        break;

                    case ArrowType.IceArrow:
                        arrowComponent = arrowThing.AddComponent <IceArrow> ();
                        break;

                    case ArrowType.ForceArrow:
                        arrowComponent = arrowThing.AddComponent <ForceArrow> ();
                        break;

                    case ArrowType.SplitArrow:
                        arrowComponent = arrowThing.AddComponent <SplitArrow> ();
                        break;

                    case ArrowType.PiercingArrow:
                        arrowComponent = arrowThing.AddComponent <PiercingArrow> ();
                        break;

                    case ArrowType.TreeArrow:
                        arrowComponent = arrowThing.AddComponent <TreeArrow> ();
                        break;

                    default:
                        arrowComponent = arrowThing.AddComponent <Arrow>();
                        break;
                    }
                }
                else
                {
                    arrowComponent = arrowThing.AddComponent <Arrow> ();
                }

                arrowComponent.owner = this.gameObject;

                bow.Release(direction, arrowThing);
                isCharging = false;
                shotTimer  = 0;
                moveTimer  = 0;
                if (!isSlowed)
                {
                    currentMovementSpeed = movementSpeed;
                }
            }
        }
        else
        {
            bow.resetCharge();
            isCharging = false;
        }

        if (Input.GetKeyDown(KeyCode.Space) & !abilityExecuted & !abilityOnCooldown & !isDead && !movementLocked && canDash)
        {
            if (Vector3.Magnitude(this.gameObject.rigidbody.velocity) != 0)
            {
                this.gameObject.AddComponent <Accelerate>().Initialize(
                    50.0f * Vector3.Normalize(this.gameObject.rigidbody.velocity),
                    0.4f, 4.0f, true);
                abilityExecuted = true;
                AudioSource source = AudioHelper.PlayClipAt(dashSound, this.gameObject.transform.position);
                source.rolloffMode = AudioRolloffMode.Linear;
                source.maxDistance = 50.0f;

                dashSystem = (GameObject)Instantiate(Resources.Load("Particles/Air Dash Effect"), this.transform.position - (Vector3.Normalize(this.gameObject.rigidbody.velocity)),
                                                     Quaternion.LookRotation(Vector3.Normalize(-this.gameObject.rigidbody.velocity)));
                dashSystem.transform.parent = gameObject.transform;
                Destroy(dashSystem, 0.4f);
            }
        }
        else if (moveDelay <= 0.0f && !abilityExecuted && !isDead && !movementLocked && canMove)
        {
            this.gameObject.rigidbody.velocity = new Vector3();

            if (Input.GetKey(KeyCode.W))
            {
                currentMovement -= new Vector3(0.0f, 0.0f, currentMovementSpeed);
            }

            if (Input.GetKey(KeyCode.S))
            {
                currentMovement += new Vector3(0.0f, 0.0f, currentMovementSpeed);
            }

            if (Input.GetKey(KeyCode.A))
            {
                currentMovement += new Vector3(currentMovementSpeed, 0.0f, 0.0f);
            }

            if (Input.GetKey(KeyCode.D))
            {
                currentMovement -= new Vector3(currentMovementSpeed, 0.0f, 0.0f);
            }

            this.gameObject.rigidbody.velocity = currentMovement;
            if (Vector3.Magnitude(this.gameObject.rigidbody.velocity) > 0)
            {
                this.gameObject.transform.rotation = Quaternion.LookRotation(Vector3.Normalize(this.gameObject.rigidbody.velocity));
                anim.SetFloat("Speed", 5);
            }
            else
            {
                anim.SetFloat("Speed", 0);
            }
            currentMovement = new Vector3();
        }
        else if (moveDelay > 0.0f)
        {
            moveDelay -= Time.deltaTime;
        }
        if (canSpecialShot)
        {
            if (Input.GetKey(KeyCode.Alpha1) && Application.loadedLevelName == "FireArrow")
            {
                currentAmmo = quiver.arrows[1].type;
            }
            if (Input.GetKey(KeyCode.Alpha2) && Application.loadedLevelName == "IceArrow")
            {
                currentAmmo = quiver.arrows[2].type;
            }
            if (Input.GetKey(KeyCode.Alpha3) && Application.loadedLevelName == "ForceArrow")
            {
                currentAmmo = quiver.arrows[3].type;
            }
            if (Input.GetKey(KeyCode.Alpha4) && Application.loadedLevelName == "TreeArrow")
            {
                currentAmmo = quiver.arrows[4].type;
            }
            if (Input.GetKey(KeyCode.Alpha5) && Application.loadedLevelName == "PiercingArrow")
            {
                currentAmmo = quiver.arrows[5].type;
            }
            if (Input.GetKey(KeyCode.Alpha6) && Application.loadedLevelName == "SplitArrow")
            {
                currentAmmo = quiver.arrows[6].type;
            }
        }
        if (Application.loadedLevelName == "tutorial")
        {
            float scrollWheel = Input.GetAxis(("Mouse ScrollWheel"));

            if (Input.GetKeyDown(KeyCode.Q) || scrollWheel < 0.0f)
            {
                if (((int)currentAmmo - 1) <= 0)
                {
                    currentAmmo = quiver.arrows[6].type;
                }
                else
                {
                    currentAmmo = quiver.arrows[(int)currentAmmo - 1].type;
                }
            }

            if (Input.GetKeyDown(KeyCode.E) || scrollWheel > 0.0f)
            {
                if (((int)currentAmmo + 1) == 7)
                {
                    currentAmmo = quiver.arrows[1].type;
                }
                else
                {
                    currentAmmo = quiver.arrows[(int)currentAmmo + 1].type;
                }
            }
        }


        if (abilityCooldown > 0.0f)
        {
            abilityCooldown -= Time.deltaTime;

            if (abilityCooldown <= 0.0f)
            {
                abilityOnCooldown = false;
            }
        }

        shotTimer += Time.deltaTime;
        moveTimer += Time.deltaTime;
        spawnTimer();

        Camera.main.transform.position = new Vector3(this.gameObject.transform.position.x,
                                                     36.0f, this.gameObject.transform.position.z + 10);
    }