Example #1
0
        //PlayerController의 DirectionNotifyer 의 Listener.
        public void RotateWeapon(CurrentInput _currentinput)
        {
            if (_currentinput == null)
            {
                return;
            }
            if (_currentinput.fixMove == KeyState.Down)
            {
                if (isFixed)
                {
                    Vector3 m_eulerA = transform.rotation.eulerAngles;
                    if (Mathf.Round(m_eulerA.y) != Mathf.Round(GetComponentInParent <CharacterPhysics>().transform.rotation.eulerAngles.y))
                    {
                        transform.rotation = Mathf.Round(m_eulerA.y) == 0 ? Quaternion.Euler(m_eulerA.x, 180f, m_eulerA.z) : Quaternion.Euler(m_eulerA.x, 0f, m_eulerA.z);
                    }
                }
                else
                {
                    preRotate = transform.rotation;
                }
                isFixed = !isFixed;
            }
            if (isFixed)
            {
                transform.rotation = preRotate;
                return;
            }

            Vector2    _toVector = _currentinput.ToVector();
            Quaternion dir       = new Quaternion();

            if (GetComponentInParent <CharacterPhysics>().onWall)// || GetComponentInParent<CharacterPhysics>().isCrouching)
            {
                dir = Quaternion.Euler(0f, transform.rotation.eulerAngles.y, 0f);
            }
            else
            {
                dir = Quaternion.Euler(0f, transform.rotation.eulerAngles.y, _toVector.x == 0 ? _toVector.y * 90 : _toVector.y * 45);
            }
            transform.rotation = dir;
        }
Example #2
0
        void FireMessage(CurrentInput _currentInput)
        {
            if (isMeleeAttacking)
            {
                return;
            }

            Collider2D[] overlaps = Physics2D.OverlapCircleAll(transform.position + playerCollider.transform.right * 0.5f, meleeAttackRange);

            foreach (Collider2D _c in overlaps)
            {
                if (_c.tag == "Monster")
                {
                    m_Animator.SetTrigger("MeleeAttack");
                    isMeleeAttacking = true;
                    StartCoroutine("MeleeAttacking");
                    List <GameObject> meleeAttackObjects = new List <GameObject>();
                    foreach (Collider2D __c in overlaps)
                    {
                        if (__c.tag == "Monster" && !meleeAttackObjects.Contains(__c.gameObject))
                        {
                            meleeAttackObjects.Add(__c.gameObject);
                            StatusManagement _status = __c.GetComponent <StatusManagement>();
                            if (_status != null)
                            {
                                _status.GetDamage(meleeAttackDamage, gameObject);
                            }
                        }
                    }
                    break;
                }
            }
            // physics2D 로 주변 콜라이더 다 탐색. 그리고 그 안에 몬스터가있으면 근접공격 하기.
            if (!isMeleeAttacking)
            {
                gameObject.SendMessage("Fire", _currentInput, SendMessageOptions.DontRequireReceiver);
            }
        }
Example #3
0
        void CurrentInputCheck(CurrentInput _currentInput)
        {
            if (!gameStart)
            {
                return;
            }
            // Right
            if (Input.GetKeyDown(inputlist.right))
            {
                _currentInput.right = KeyState.Down;
            }
            else if (Input.GetKey(inputlist.right))
            {
                _currentInput.right = KeyState.Held;
            }
            else if (Input.GetKeyUp(inputlist.right))
            {
                _currentInput.right = KeyState.Up;
            }
            else
            {
                _currentInput.right = KeyState.None;
            }

            // Down
            if (Input.GetKeyDown(inputlist.down))
            {
                _currentInput.down = KeyState.Down;
            }
            else if (Input.GetKey(inputlist.down))
            {
                _currentInput.down = KeyState.Held;
            }
            else if (Input.GetKeyUp(inputlist.down))
            {
                _currentInput.down = KeyState.Up;
            }
            else
            {
                _currentInput.down = KeyState.None;
            }


            // Left
            if (Input.GetKeyDown(inputlist.left))
            {
                _currentInput.left = KeyState.Down;
            }
            else if (Input.GetKey(inputlist.left))
            {
                _currentInput.left = KeyState.Held;
            }
            else if (Input.GetKeyUp(inputlist.left))
            {
                _currentInput.left = KeyState.Up;
            }
            else
            {
                _currentInput.left = KeyState.None;
            }


            // Up
            if (Input.GetKeyDown(inputlist.up))
            {
                _currentInput.up = KeyState.Down;
            }
            else if (Input.GetKey(inputlist.up))
            {
                _currentInput.up = KeyState.Held;
            }
            else if (Input.GetKeyUp(inputlist.up))
            {
                _currentInput.up = KeyState.Up;
            }
            else
            {
                _currentInput.up = KeyState.None;
            }


            // Jump
            if (Input.GetKeyDown(inputlist.jump) || Input.GetKeyDown(KeyCode.Space))
            {
                _currentInput.jump = KeyState.Down;
            }
            else if (Input.GetKey(inputlist.jump) || Input.GetKey(KeyCode.Space))
            {
                _currentInput.jump = KeyState.Held;
            }
            else if (Input.GetKeyUp(inputlist.jump) || Input.GetKeyUp(KeyCode.Space))
            {
                _currentInput.jump = KeyState.Up;
            }
            else
            {
                _currentInput.jump = KeyState.None;
            }


            // Shoot
            if (Input.GetKeyDown(inputlist.shoot))
            {
                _currentInput.shoot = KeyState.Down;
            }
            else if (Input.GetKey(inputlist.shoot))
            {
                _currentInput.shoot = KeyState.Held;
            }
            else if (Input.GetKeyUp(inputlist.shoot))
            {
                _currentInput.shoot = KeyState.Up;
            }
            else
            {
                _currentInput.shoot = KeyState.None;
            }

            // FixMove
            if (Input.GetKeyDown(inputlist.fixMove))
            {
                _currentInput.fixMove = KeyState.Down;
            }
            else if (Input.GetKey(inputlist.fixMove))
            {
                _currentInput.fixMove = KeyState.Held;
            }
            else if (Input.GetKeyUp(inputlist.fixMove))
            {
                _currentInput.fixMove = KeyState.Up;
            }
            else
            {
                _currentInput.fixMove = KeyState.None;
            }

            // Reload
            if (Input.GetKeyDown(inputlist.reload))
            {
                _currentInput.reload = KeyState.Down;
            }
            else if (Input.GetKey(inputlist.reload))
            {
                _currentInput.reload = KeyState.Held;
            }
            else if (Input.GetKeyUp(inputlist.reload))
            {
                _currentInput.reload = KeyState.Up;
            }
            else
            {
                _currentInput.reload = KeyState.None;
            }

            // Dash
            if (Input.GetKeyDown(inputlist.dash) || Input.GetKeyDown(KeyCode.LeftShift))
            {
                _currentInput.dash = KeyState.Down;
            }
            else if (Input.GetKey(inputlist.dash) || Input.GetKey(KeyCode.LeftShift))
            {
                _currentInput.dash = KeyState.Held;
            }
            else if (Input.GetKeyUp(inputlist.dash) || Input.GetKeyUp(KeyCode.LeftShift))
            {
                _currentInput.dash = KeyState.Up;
            }
            else
            {
                _currentInput.dash = KeyState.None;
            }

            //Interaction
            if (Input.GetKeyDown(inputlist.interaction))
            {
                _currentInput.interaction = KeyState.Down;
            }
            else if (Input.GetKey(inputlist.interaction))
            {
                _currentInput.interaction = KeyState.Held;
            }
            else if (Input.GetKeyUp(inputlist.interaction))
            {
                _currentInput.interaction = KeyState.Up;
            }
            else
            {
                _currentInput.interaction = KeyState.None;
            }

            //AnyKey
            _currentInput.anyKey     = Input.anyKey;
            _currentInput.anyKeyDown = Input.anyKeyDown;
        }
Example #4
0
        public void Fire(CurrentInput _currentinput)
        {
            if (!isPicked || reloading || _currentinput.shoot != KeyState.Down)
            {
                return;
            }

            if (ammo <= 0)
            {
                Reload();
                return;
            }

            if (1 / weaponInfo.fireRate > Time.time - preFireTime)
            {
                return;
            }
            preFireTime = Time.time;

            m_Animator.SetTrigger("Shoot");

            ammo -= 1;

            Vector2    _toVector = transform.right;
            Quaternion dir       = Quaternion.Euler(0, transform.rotation.eulerAngles.y, Mathf.Round(_toVector.x) == 0f ? _toVector.y * 90 : _toVector.y * 45);


            for (int i = 0; i < 6; i++)
            {
                var bullet   = Instantiate(weaponInfo.bulletPrefab, bulletPosition.position, dir);
                var hitCheck = bullet.gameObject.GetComponent <HitCheck>();
                hitCheck.shooter = playerCollider.gameObject;
                hitCheck.damage  = weaponInfo.damage;
                hitCheck.targetTag.Add("Monster");
                hitCheck.targetTag.Add("Platform");

                Vector2 _bulletVelocity = (_toVector + new Vector2(Random.Range(-0.25f, 0.25f), _toVector.y == 0f ? Random.Range(-0.05f, 0.25f) : Random.Range(-0.25f, 0.25f))).normalized * weaponInfo.bulletSpeed;

                /*
                 * if ((currentInput.right == KeyState.Held || currentInput.right == KeyState.Down) && !playerCollider.GetComponent<CharacterPhysics>().onWall)
                 * {
                 *  _bulletVelocity += new Vector2(playerCollider.GetComponent<CharacterPhysics>().moveSpeed, 0f);
                 * }
                 * else if ((currentInput.left == KeyState.Held || currentInput.left == KeyState.Down) && !playerCollider.GetComponent<CharacterPhysics>().onWall)
                 * {
                 *  _bulletVelocity += new Vector2(-playerCollider.GetComponent<CharacterPhysics>().moveSpeed, 0f);
                 * }
                 * _bulletVelocity += new Vector2(0f, playerCollider.GetComponent<Rigidbody2D>().velocity.y);
                 */
                Vector2 playerSpeed          = playerCollider.GetComponent <Rigidbody2D>().velocity;
                float   playerRotationXEuler = Mathf.Round(transform.rotation.eulerAngles.x);
                if ((playerSpeed.x > 0 && playerRotationXEuler == 0) || (playerSpeed.x < 0 && playerRotationXEuler != 0))
                {
                    _bulletVelocity.x += playerSpeed.x;
                }
                if (!(Mathf.Round(_toVector.x) != 0) && ((_toVector.y > 0 && playerSpeed.y > 0) || (_toVector.y < 0 && playerSpeed.y < 0)))
                {
                    _bulletVelocity.y += playerSpeed.y;
                }

                hitCheck.velocity = _bulletVelocity;

                hitCheck.StartCoroutine("ShootingRadiusCheck", 6f / _bulletVelocity.magnitude);
                FireBulletListener.Invoke(bullet);
            }
            WeaponFireListener.Invoke(gameObject);

            cameraShake.Shake(0.12f, 1.3f);
        }