Ejemplo n.º 1
0
        public void SetHeadDirection(HeadDirection direction)
        {
            switch (direction)
            {
            case HeadDirection.Up:
                _spriteRenderer.sprite = _headBack;
                break;

            case HeadDirection.Down:
                _spriteRenderer.sprite = _headFront;
                break;

            case HeadDirection.Left:
                _spriteRenderer.sprite = _headSideways;
                if ((transform.parent.transform.localScale.x < 0 && transform.localScale.x > 0) ||
                    transform.parent.transform.localScale.x > 0 && transform.localScale.x < 0)
                {
                    TransformHelpers.FlipX(gameObject);
                }
                break;

            case HeadDirection.Right:
                _spriteRenderer.sprite = _headSideways;
                if ((transform.parent.transform.localScale.x < 0 && transform.localScale.x < 0) ||
                    transform.parent.transform.localScale.x > 0 && transform.localScale.x > 0)
                {
                    TransformHelpers.FlipX(gameObject);
                }
                break;
            }
        }
Ejemplo n.º 2
0
        private void SetAnimationDirection(Vector3 movement, Vector3 target, Vector3 currentPosition)
        {
            int animationDirection = Animator.GetInteger("Direction");
            int newDirection       = -1;

            if (movement.x != 0.0f && movement.y != 0.0f)
            {
                newDirection = target.y > currentPosition.y ? 0 : 2;
            }
            else if (movement.x != 0.0f && movement.y == 0.0f)
            {
                newDirection = target.x > currentPosition.x ? 1 : 3;
            }
            else if (movement.x == 0.0f && movement.y != 0.0f)
            {
                newDirection = target.y > currentPosition.y ? 0 : 2;
            }

            if (animationDirection != newDirection)
            {
                Animator.SetInteger("Direction", newDirection);
                if (MirrorAnimation)
                {
                    if ((transform.localScale.x < 0 && newDirection == 3) ||
                        (transform.localScale.x > 0 && newDirection == 1) ||
                        (transform.localScale.y < 0 && newDirection == 0) ||
                        (transform.localScale.y > 0 && newDirection == 2))
                    {
                        TransformHelpers.FlipX(gameObject);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        IEnumerator Shoot()
        {
            if (!_shooting)
            {
                _shooting = true;
                var bullet = (Rigidbody2D)Instantiate(BulletPrefab);
                bullet.GetComponent <BulletScript>().Shooter = transform.gameObject;
                bullet.transform.position = transform.position;

                if (_shootDirection.y > 0)
                {
                    bullet.transform.Rotate(0, 0, -90);
                }
                else if (_shootDirection.y < 0)
                {
                    bullet.transform.Rotate(0, 0, 90);
                }
                else if (_shootDirection.x > 0)
                {
                    TransformHelpers.FlipX(bullet.gameObject);
                }
                bullet.AddForce(_shootDirection);

                if (ShootClips.Any())
                {
                    int bossHax = 0;

                    if (_boss)
                    {
                        bossHax = 4;
                    }

                    var clipToPlay = ShootClips[Random.Range(bossHax, ShootClips.Count)];
                    clipToPlay.pitch = Random.Range(MinShootPitch, MaxShootPitch);
                    clipToPlay.Play();
                }

                //enemies with shoot speed that varies
                if (_shootSpeedVaries)
                {
                    if (_shootSpeed == 0)
                    {
                        yield return(new WaitForSeconds(0));

                        _shootSpeed = 0.3f;
                    }
                    else
                    {
                        yield return(new WaitForSeconds(_shootSpeed * 3));

                        _shootSpeed = 0;
                    }
                }
                else
                {
                    yield return(new WaitForSeconds(_shootSpeed * 3));
                }
                _shooting = false;
            }
        }
Ejemplo n.º 4
0
        IEnumerator Shoot()
        {
            IsShooting = true;
            while (Input.GetKey(_shootKey) && !_player.IsDead)
            {
                // Instantiate the bullet prefab and set the shooter as the player
                var bullet = (Rigidbody2D)Instantiate(BulletPrefab, new Vector3(transform.position.x, transform.position.y - 0.25f, 0f), new Quaternion());
                bullet.GetComponent <BulletScript>().Shooter = transform.gameObject;

                // Rotation of the bullet sprite
                if (_shootDirection.y > 0)
                {
                    bullet.transform.Rotate(0, 0, -90);
                }
                else if (_shootDirection.y < 0)
                {
                    bullet.transform.Rotate(0, 0, 90);
                }
                else if (_shootDirection.x > 0)
                {
                    TransformHelpers.FlipX(bullet.gameObject);
                }
                bullet.AddForce(_shootDirection);
                bullet.AddForce(_player.GetComponent <Rigidbody2D>().GetPointVelocity(_player.transform.position) * 0.02f);

                if (ShootClips.Any())
                {
                    var clipToPlay = ShootClips[Random.Range(0, ShootClips.Count)];
                    clipToPlay.pitch = Random.Range(MinShootPitch, MaxShootPitch);
                    clipToPlay.Play();
                }

                yield return(new WaitForSeconds(_shootSpeed));
            }
            IsShooting = false;
            _headObject.SetHeadDirection(PlayerHeadController.HeadDirection.Down);

            //Reset head flipping
            if (_headObject.transform.localScale.x < 0)
            {
                TransformHelpers.FlipX(_headObject.gameObject);
            }
        }
Ejemplo n.º 5
0
        IEnumerator Shoot()
        {
            IsShooting = true;
            while (Input.GetKey(_shootKey))
            {
                var bullet = (Rigidbody2D)Instantiate(BulletPrefab);
                bullet.GetComponent <BulletScript>().Shooter = transform.gameObject;
                bullet.transform.position = transform.position;
                if (_shootDirection.y > 0)
                {
                    bullet.transform.Rotate(0, 0, -90);
                }
                else if (_shootDirection.y < 0)
                {
                    bullet.transform.Rotate(0, 0, 90);
                }
                else if (_shootDirection.x > 0)
                {
                    TransformHelpers.FlipX(bullet.gameObject);
                }
                bullet.AddForce(_shootDirection);
                bullet.AddForce(_player.rigidbody2D.GetPointVelocity(_player.transform.position) * 0.02f);

                if (ShootClips.Any())
                {
                    var clipToPlay = ShootClips[Random.Range(0, ShootClips.Count)];
                    clipToPlay.pitch = Random.Range(MinShootPitch, MaxShootPitch);
                    clipToPlay.Play();
                }

                yield return(new WaitForSeconds(ShootingSpeed));
            }
            IsShooting = false;

            //Reset head flipping
            if (_headObject.transform.localScale.x < 0)
            {
                TransformHelpers.FlipX(_headObject.gameObject);
            }
        }