Пример #1
0
        void Update()
        {
            if (!doingGroundPound)
            {
                if (!IsLeftJoystickInput())
                {
                    animationController.ChangeAnimation(Constants.ANIMATION_IDLE);
                    particleController.StopFeetDust();
                }
                else
                {
                    float angle = (Mathf.Atan2(-Input.GetAxis(XboxController.leftJoystickX), -Input.GetAxis(XboxController.leftJoystickY)) * Mathf.Rad2Deg) + 45f;
                    transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(new Vector3(0f, -angle, 0)), rotationSpeed * Time.deltaTime);

                    if (!shooting)
                    {
                        animationController.ChangeAnimation(Constants.ANIMATION_RUN);
                    }

                    if (!particleController.feetDust.isPlaying && collisionController.onGround)
                    {
                        particleController.PlayFeetDust();
                    }
                }

                transform.position += isometricForward * Time.deltaTime * movementSpeed * -Input.GetAxis(XboxController.leftJoystickY);
                transform.position += isometricRight * Time.deltaTime * movementSpeed * Input.GetAxis(XboxController.leftJoystickX);

                //transform.position += isometricForward * Time.deltaTime * movementSpeed * Input.GetAxis("Vertical");
                //transform.position += isometricRight * Time.deltaTime * movementSpeed * Input.GetAxis("Horizontal");
            }

            if (Input.GetButtonDown(XboxController.xboxAButton))
            {
                Jump();
            }
            if (Input.GetButtonDown(XboxController.xboxXButton) && canGroundPound)
            {
                StartCoroutine(GroundPound());
            }
            if (Input.GetButtonDown(XboxController.xboxBButton))
            {
                uiController.SetDynamiteIcon(false);
                weaponsController.DropDynamite();
            }

            if (Input.GetAxis(XboxController.rightTrigger) >= 1f)
            {
                shooting = true;
                weaponsController.Shoot();
                movementSpeed = 0f;
                animationController.ChangeAnimation(Constants.ANIMATION_IDLE);
            }
            else
            {
                shooting      = false;
                movementSpeed = originalMovementSpeed;
            }
        }
        private void OnCollisionEnter(Collision other)
        {
            print("Player has collided with: " + other.gameObject.tag);

            // If we are in the air when we collide with something
            if (!onGround)
            {
                switch (other.gameObject.tag)
                {
                case Tags.MINION:
                    if (playerController.doingGroundPound)
                    {
                        other.gameObject.GetComponent <HealthController>().Die();
                    }
                    else
                    {
                        other.gameObject.GetComponent <HealthController>().RemoveHealth(1);
                        playerController.Bounce();
                    }
                    break;

                case Tags.BARRELL:
                    if (!playerController.doingGroundPound)
                    {
                        playerController.Bounce();
                    }
                    break;

                case Tags.CRATE:
                    if (!playerController.doingGroundPound)
                    {
                        playerController.Bounce();
                    }
                    break;
                }
            }

            switch (other.gameObject.tag)
            {
            case Tags.GROUND:
                // If we hit the ground as we are doing a ground pound
                if (playerController.doingGroundPound)
                {
                    // Shake the camera and play the dust
                    particleController.PlayGroundPound();
                    CameraController.instance.ShakeCamera(.4f, .5f);

                    GetComponent <PlayerUIController>().RechargeGroundPound();

                    // Inflict damage upon enemies in range
                    //Collider[] objectsInRange = Physics.OverlapBox(feetPosition.position, new Vector3(playerController.groundPoundRadius, .5f, 5f));
                    Collider[] objectsInRange = Physics.OverlapCapsule(feetPosition.position, feetPosition.position + Vector3.up / 10, playerController.groundPoundRadius);
                    for (int i = 0; i < objectsInRange.Length; i++)
                    {
                        GameObject obj = objectsInRange[i].gameObject;

                        switch (obj.tag)
                        {
                        case Tags.MINION:
                            Vector3 direction = obj.transform.position - transform.position;
                            direction = -direction.normalized;
                            obj.gameObject.GetComponent <HealthController>().RemoveHealth(1);
                            obj.gameObject.GetComponent <Minion>().KnockBack(direction);
                            break;

                        case Tags.BARRELL:
                            obj.GetComponent <DestroyableObject>().Destroy();
                            break;

                        case Tags.CRATE:
                            obj.GetComponent <DestroyableObject>().Destroy();
                            break;
                        }
                    }
                }
                else
                {
                    if (!onGround)
                    {
                        particleController.PlayJumpDust();
                    }
                }
                onGround = true;
                particleController.PlayFeetDust();
                break;

            case Tags.MINION:
                if (onGround)
                {
                    GetComponent <HealthController>().RemoveHealth(1);
                }
                break;

            case Tags.BULLET:
                GetComponent <HealthController>().RemoveHealth(1);
                break;

            case Tags.PICKUP_BLASTER:
                GetComponent <PlayerWeaponsController>().ChangeWeapon("Blaster");
                Destroy(other.gameObject);
                break;

            case Tags.PICKUP_CANNON:
                GetComponent <PlayerWeaponsController>().ChangeWeapon("Cannon");
                Destroy(other.gameObject);
                break;

            case Tags.PICKUP_DYNAMITE:
                GetComponent <PlayerWeaponsController>().hasDynamite = true;
                GetComponent <PlayerUIController>().SetDynamiteIcon(true);
                Destroy(other.gameObject);
                break;

            case Tags.CHECKPOINT:
                Checkpoint c = other.gameObject.GetComponent <Checkpoint>();
                GetComponent <PlayerCheckpointController>().UpdateCheckpoint(c);
                c.Animate();
                break;
            }
        }