예제 #1
0
    private void Fire()
    {
        if (_playerCtrl.playerStats.Ammo > 0)
        {
            _playerCtrl.playerStats.Ammo--;
            UpdateAmmoText();

            // ... set the animator Shoot trigger parameter and play the audioclip.
            _anim.SetTrigger("Shoot2");
            //GetComponent<AudioSource>().Play();

            Vector3 mouseLoc = Input.mousePosition;
            mouseLoc.z = 10.0f;
            mouseLoc   = Camera.main.ScreenToWorldPoint(mouseLoc);

            Vector2 dir = DirectionCalc.GetPlayerShotDirection(Vector2.ClampMagnitude(mouseLoc - transform.position, 1.0f));

            // ... instantiate the rocket facing right and set it's velocity to the right.
            GameObject projectileObject = Instantiate(Ammo);
            Projectile p = projectileObject.GetComponent <Projectile>();

            p.SetLocation(transform.GetChild(0).gameObject.transform.position);
            p.SetDirection(dir);
            p.SetAttack(_playerCtrl.playerStats.BaseAttack + +_playerCtrl.playerStats.WeaponAttack);
        }
        else
        {
            Reload();
        }
    }
예제 #2
0
    void Update()
    {
        /*if (!_playerCtrl.facingRight)
         *      transform.localScale = new Vector3 (-1f, 1f, 1f);
         * else
         *      transform.localScale = Vector3.one;*/

        // If the fire button is pressed...
        if (Input.GetButtonDown(GlobalControl.Instance.KeyboardSettings.Fire1))
        {
            Vector3 mouseLoc = Input.mousePosition;
            mouseLoc.z = 10.0f;
            mouseLoc   = Camera.main.ScreenToWorldPoint(mouseLoc);

            // ... set the animator Shoot trigger parameter and play the audioclip.
            //_anim.SetTrigger("Shoot");
            //GetComponent<AudioSource>().Play();

            // To decide.  Should I fixed directions (Hero Siege) or any direction (Nuclear Throne)
            // Right now, clamp direction to 90 degree angles
            Vector2 dir = DirectionCalc.GetPlayerShotDirection(Vector2.ClampMagnitude(mouseLoc - transform.position, 1.0f));

            GameObject projectileObject = Instantiate(Ammo);
            Projectile p = projectileObject.GetComponent <Projectile>();

            p.SetLocation(transform.GetChild(0).gameObject.transform.position);
            p.SetDirection(new Vector2(dir.x, dir.y));
            p.SetAttack(_playerCtrl.playerStats.BaseAttack + _playerCtrl.playerStats.WeaponAttack);

            //_camera.ShakeCamera();
        }
    }
        public void CalculateDirection_OldCoord44_NewCoord42_returns0()
        {
            //arrange
            var uut = new DirectionCalc();

            var oldCoord = Substitute.For <ICoordinate>();

            oldCoord.x = 4;
            oldCoord.y = 4;

            var newCoord = Substitute.For <ICoordinate>();

            newCoord.x = 4;
            newCoord.y = 2;

            //act
            var result = uut.CalculateDirection(oldCoord, newCoord);

            //assert
            Assert.That(result, Is.EqualTo(180)); //180 = S
        }
예제 #4
0
    void IsShotIncoming()
    {
        Vector2[]    areaVectors = DirectionCalc.GetEnemyCollisionVectors(Vector2.ClampMagnitude(playerPos - enemyPos, 1.0f));
        Collider2D[] Shots       = Physics2D.OverlapAreaAll(transform.position - (Vector3)areaVectors[0], transform.position - (Vector3)areaVectors[1]);

        foreach (Collider2D shot in Shots)
        {
            if (shot.tag == "Bullet")
            {
                Projectile s = shot.gameObject.GetComponent <Projectile>();
                if (s != null && !s.GetIsEnemy())
                {
                    _lastDodgeTime = Time.time;
                    if (UnityEngine.Random.Range(0, 3) == 0)
                    {
                        _dodging        = true;
                        _dodgeDirection = DirectionCalc.GetEnemyDodgeDirection(Vector2.ClampMagnitude((Vector2)shot.transform.position - (Vector2)transform.position, 1.0f));

                        StartCoroutine("Dodge");
                    }
                }
            }
        }
    }