Beispiel #1
0
    IEnumerator Charge()
    {
        isCharging = true;
        animator.SetTrigger("Charge");

        currentArrow = Instantiate(flechaPrefab, hand).GetComponent <Flecha>();
        yield return(new WaitUntil(WaitUntilCharge));

        AnimatorStateInfo animatorStateInfo = animator.GetCurrentAnimatorStateInfo(5);

        while (animatorStateInfo.IsName("Charge") && animatorStateInfo.normalizedTime < 1f)
        {
            animatorStateInfo = animator.GetCurrentAnimatorStateInfo(5);
            Debug.Log("IsCharging");
            if (!Input.GetMouseButton(0))
            {
                Debug.Log("CancelCharge");
                animator.SetTrigger("CancelCharge");
                isCharging = false;
                Destroy(currentArrow.gameObject);
                yield return(new WaitForEndOfFrame());

                break;
            }
            yield return(new WaitForEndOfFrame());
        }

        if (isCharging)
        {
            isCharging = false;
            StartCoroutine(Shoot());
        }
    }
Beispiel #2
0
    public void RechargeBow(GameObject arrowPrefab)
    {
        currentArrow = Instantiate(arrowPrefab, arrowPosition).GetComponent <Flecha>();

        if (currentArrow)
        {
            currentArrow.transform.parent = lineTransform;
            hasArrow = true;
        }
    }
Beispiel #3
0
 public void Shoot()
 {
     if (hasArrow && bowIsReady)
     {
         bowIsReady = false;
         hasArrow   = false;
         currentArrow.transform.parent = null;
         Vector3 shootFinalForce = (lineTransform.TransformDirection(Vector3.forward) * shootForce) * 25f;
         currentArrow.rb.AddForce(-shootFinalForce, ForceMode.Impulse);
         //currentArrow.StartInAirBehaviour();
         currentArrow = null;
         StartCoroutine(RetriveBowLine());
     }
 }
    public void SpawnarFlecha(int disFlePlay)
    {
        Vector3 position = player_ref.transform.position;

        position.x += disFlePlay;
        position.y += disFlePlay;
        position.z  = -1;

        if (FlechasList.Any())
        {
            int    index = FlechasList.FindLastIndex(x => x.GetType() == typeof(Flecha));
            Flecha F     = (Flecha)FlechasList[index];
            FlechasList.RemoveAt(index);
            F.transform.position = position;
            F.gameObject.SetActive(true);
        }
        else
        {
            GameObject ru = Instantiate(municaoFlechasPrefab, position, Quaternion.identity);

            FlechasList.Add(ru);
        }
    }
Beispiel #5
0
    public void SearchWeapon()
    {
        if (lastSeenArrow && teste.Length > 0)
        {
            bool isSeenArrow = false;
            for (int i = 0; i < teste.Length; i++)
            {
                if (teste[i] == lastSeenArrow)
                {
                    isSeenArrow = true;
                    Debug.DrawLine(transform.position, lastSeenArrow.transform.position, Color.red);
                }

                if (i == (teste.Length - 1) && !isSeenArrow)
                {
                    lastSeenArrow = null;
                }
            }
        }

        Collider[] seenWeapons = Physics.OverlapCapsule(transform.position, (transform.position + (Vector3.up * 100)), pickUpRadius, weaponLayer); //Sphere(transform.position, pickUpRadius, weaponLayer);
        teste = seenWeapons;
        if (seenWeapons.Length != 0)
        {
            for (int i = 0; i < seenWeapons.Length; i++)
            {
                Weapon weapon = seenWeapons[i].GetComponent <Weapon>();
                Flecha arrow  = seenWeapons[i].GetComponent <Flecha>();

                if (weapon)
                {
                    if (weapon == actualWeapon)
                    {
                        seenWeapons[i] = null;
                    }
                    else if (lastSeenWeapon)
                    {
                        if (lastSeenWeapon != actualWeapon && lastSeenWeapon != weapon)
                        {
                            lastSeenWeaponDist = Vector3.Distance(transform.position, lastSeenWeapon.transform.position);
                            float weaponDist = Vector3.Distance(transform.position, weapon.transform.position);
                            if (weaponDist < lastSeenWeaponDist)
                            {
                                lastSeenWeapon = weapon;
                            }
                        }
                    }
                    else
                    {
                        lastSeenWeapon = weapon;
                    }
                }
                else if (arrow && !RangedAttack.isAiming && !RangedAttack.isCharging)
                {
                    if (lastSeenArrow)
                    {
                        if (lastSeenArrow != arrow)
                        {
                            lastSeenArrowDist = Vector3.Distance(transform.position, lastSeenArrow.transform.position);
                            float arrowDist = Vector3.Distance(transform.position, arrow.transform.position);
                            if (arrowDist < lastSeenArrowDist)
                            {
                                lastSeenArrow = arrow;
                            }
                        }
                    }
                    else
                    {
                        lastSeenArrow = arrow;
                    }
                }
            }
        }

        if (lastSeenWeapon)
        {
            Debug.DrawLine(transform.position, lastSeenWeapon.transform.position, Color.green); if (Vector3.Distance(transform.position, lastSeenWeapon.transform.position) > 2f)
            {
                lastSeenWeapon = null;
            }
        }
    }
Beispiel #6
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            tecladoPasado = tecladoActual;
            tecladoActual = Keyboard.GetState();

            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // TODO: Add your update logic here
            MouseState raton = Mouse.GetState();

            if(tecladoActual.IsKeyDown(Keys.W))
                cameraPosition.Y+=5;
            if (tecladoActual.IsKeyDown(Keys.S))
                cameraPosition.Y-=5;
            if (tecladoActual.IsKeyDown(Keys.A))
                cameraPosition.X-=5;
            if (tecladoActual.IsKeyDown(Keys.D))
                cameraPosition.X+=5;
            cameraPosition.Z = raton.ScrollWheelValue / 4;

            if (tecladoPasado.IsKeyUp(Keys.Up) && (tecladoActual.IsKeyDown(Keys.Up)))
            {
                inclinacionZ++;
                flecha.updateValores(inclinacionZ,-inclinacionY);
            }
            if (tecladoPasado.IsKeyUp(Keys.Down) && (tecladoActual.IsKeyDown(Keys.Down)))
            {
                inclinacionZ--;
                flecha.updateValores(inclinacionZ,-inclinacionY);
            }
            if (tecladoPasado.IsKeyUp(Keys.Right) && (tecladoActual.IsKeyDown(Keys.Right)))
            {
                inclinacionY--;
                flecha.updateValores(inclinacionZ,-inclinacionY);
            }
            if (tecladoPasado.IsKeyUp(Keys.Left) && (tecladoActual.IsKeyDown(Keys.Left)))
            {
                inclinacionY++;
                flecha.updateValores(inclinacionZ,-inclinacionY);
            }
            if (tecladoPasado.IsKeyUp(Keys.Enter) && (tecladoActual.IsKeyDown(Keys.Enter)))
            {
                flecha= new Flecha();
                int signo = 1;
                if (aleatorio.NextDouble() > .5)
                    signo = -1;
                posicionBlanco = new Vector3((float)(aleatorio.NextDouble() * 15000)+200, 455f, (float)(aleatorio.NextDouble() * 1000) * signo);
            }

            worldFlecha = Matrix.CreateRotationY((float)((inclinacionY) * Math.PI / 180)) * Matrix.CreateRotationZ((float)((-inclinacionZ) * Math.PI / 180)) * Matrix.CreateRotationY((float)Math.PI);
                //worldFlecha = Matrix.CreateFromAxisAngle(new Vector3(0f, 1f, 1f),(float) (inclinacionY*inclinacionZ / Math.PI));
                posicionFlecha=flecha.getPosicion()*50;
                worldFlecha.Translation=posicionFlecha;
                worldBlanco.Translation = posicionBlanco;
                flecha.Update(gameTime);
                if (flecha.lanzamiento)
                {
                    //cameraPosition.X = cameraPosition.X + (posicionFlecha.X / 100);
                    cameraPosition.X = posicionFlecha.X - 1250;
                    //lookAt = posicionFlecha;
                    //worldArco = Matrix.Identity;
                }
                else
                {
                    worldArco = worldFlecha;
                }
                lookAt = posicionFlecha;
                cameraPosition.X = posicionFlecha.X - 1250;
                if (flecha.term)
                    worldArco = Matrix.Identity;
                //cameraPosition.Y = cameraPosition.Y + posicionFlecha.Y;
                //cameraPosition.Z = cameraPosition.Z + posicionFlecha.Z;
            base.Update(gameTime);
        }
Beispiel #7
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            device= graphics.GraphicsDevice;
            device.Clear(Color.CornflowerBlue);
            //worldFlecha = Matrix.Identity;
            worldFlecha = Matrix.CreateRotationY((float)(Math.PI / 2));
            worldBlanco = Matrix.CreateRotationZ((float)(Math.PI / 2));
            worldArco = worldFlecha;
            inclinacionY = 0;
            inclinacionZ = 0;
            flecha = new Flecha();
            blanco = new Blanco();
            puntos = 0;
            int signo = 1;
            if (aleatorio.NextDouble() > .5)
                signo = -1;
            posicionBlanco = new Vector3(11133f, 455f, (float)(aleatorio.NextDouble() * 1000)*signo);

            base.Initialize();
        }