Пример #1
0
    void StartWalking()
    {
        if (_playerStates.SetState(PlayerStates.States.WalkingOnPlanet))
        {
            transform.position = playerShip.transform.position;

            GetComponent <SpriteRenderer>().enabled = true;

            currentPlanet = _playerStates.GetPlanet();
            if (currentPlanet.GetComponent <ResourcePlanet>() != null)
            {
                ResetAllAnimationBool();
                SetAnimationType(currentPlanet.GetComponent <ResourcePlanet>().producingResourceType.resourceName);
            }
            else
            {
                SetAnimationType("Wood");
            }

            currentAngle = Vector3.SignedAngle(Vector3.up, transform.position - currentPlanet.transform.position,
                                               Vector3.forward);

            _rigidbody.rotation = currentAngle;
            _planetRadius       = currentPlanet.GetComponent <CircleCollider2D>().radius *currentPlanet.transform.localScale.x;

            transform.position = currentPlanet.transform.position + (spriteOffset + _planetRadius) * (Quaternion.AngleAxis(currentAngle, Vector3.forward) * Vector3.up);
        }
    }
Пример #2
0
    // Update is called once per frame
    void LateUpdate()
    {
        if (_states.GetState() == PlayerStates.States.WalkingOnPlanet)
        {
            Vector3 newPos = _states.GetPlanet().transform.position;
            newPos.z = transform.position.z;

            transform.position = Vector3.MoveTowards(transform.position, newPos, 0.6f);
        }
        else
        {
            Vector3 newPos = playerShip.transform.position;
            newPos.z = transform.position.z;

            //transform.position = Vector3.MoveTowards(transform.position, newPos, 2);
            transform.position = newPos;
        }
    }
Пример #3
0
    // Update is called once per frame
    void Update()
    {
        UpdateSoundVolume();

        if (_fuelController.IsEmpty())
        {
            _animator.SetBool("Accelerating", false);
            StopSound();
            return;
        }

        if (_playerStates.GetState() == PlayerStates.States.InLandedShip)
        {
            if (ControlIndicator.currentCommand != "TO  LEAVE  SHIP" || !ControlIndicator.isActive)
            {
                CommandShower.GetComponent <ControlIndicator>().ShowCommand("TO  LEAVE  SHIP");
            }
            if (Input.GetButtonDown("Vertical"))
            {
                if (Input.GetAxis("Vertical") > 0)
                {
                    PlayerShipCollision.Player.transform.parent = null;
                    PlayerStates.canLand = false;
                    _animator.SetBool("Accelerating", true);


                    if (_playerStates.SetState(PlayerStates.States.InFlyingShip))
                    {
                        if (ControlIndicator.currentCommand == "TO  LEAVE  SHIP" && ControlIndicator.isActive)
                        {
                            CommandShower.GetComponent <ControlIndicator>().HideCommand();
                        }

                        canCrash = false;
                        StartCoroutine(shipLeavingPlanetDelay());

                        mainMusicController.GetComponent <DrumChanger>().AddDrum();
                        PlaySound();

                        PlayerShipCollision.Player.transform.parent = null;

                        _rigidbody.AddForce(force * 100 * transform.up * Time.deltaTime);
                        _fuelController.ConsumeFuel(fuelConsuptionPerSecond * Time.deltaTime * 125);


                        _playerStates.GetPlanet().GetComponent <Planet>().LeavePlanet();
                    }
                }
            }
            else
            {
                _animator.SetBool("Accelerating", false);
                StopSound();
            }
        }

        if (_playerStates.GetState() == PlayerStates.States.InFlyingShip)
        {
            if (Input.GetButton("Vertical"))
            {
                PlaySound();

                _fuelController.ConsumeFuel(fuelConsuptionPerSecond * Time.deltaTime);

                if (Input.GetAxis("Vertical") > 0)
                {
                    _animator.SetBool("Accelerating", true);
                    _animator.SetBool("Back", false);

                    _rigidbody.AddForce(force * transform.up * Time.deltaTime);
                }
                else
                {
                    _animator.SetBool("Accelerating", false);
                    _animator.SetBool("Back", true);
                    _rigidbody.AddForce(-force * transform.up * Time.deltaTime);
                }
            }

            if (Input.GetButton("Horizontal"))
            {
                PlaySound();
                _fuelController.ConsumeFuel(fueldConsuptionPerSecondOnTurn * Time.deltaTime);

                if (Input.GetAxis("Horizontal") > 0)
                {
                    _rigidbody.AddTorque(-torque * Time.deltaTime);
                }
                else
                {
                    _rigidbody.AddTorque(torque * Time.deltaTime);
                }
            }

            if (_rigidbody.velocity.magnitude >= maxSpeed)
            {
                _rigidbody.velocity = _rigidbody.velocity.normalized * maxSpeed;
            }

            if (!Input.GetButton("Horizontal") && !Input.GetButton("Vertical"))
            {
                StopSound();
                _animator.SetBool("Accelerating", false);
                _animator.SetBool("Back", false);
            }
        }
        else
        {
            StopSound();
        }

        VerifyIfPlayersIsInbound();
    }