Exemple #1
0
 void EnterShip()
 {
     if (_state.SetState(PlayerStates.States.InLandedShip))
     {
         GetComponent <SpriteRenderer>().enabled = false;
     }
 }
    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);
        }
    }
Exemple #3
0
    void Land(GameObject planet)
    {
        if (PlayerStates.canLand)
        {
            mainMusicController.GetComponent <DrumChanger>().RemoveDrum();
            _playerRigidbody.velocity        = Vector3.zero;
            _playerRigidbody.angularVelocity = 0;
            float angle = Vector3.SignedAngle(Vector3.up, playerShip.transform.position - planet.transform.position, Vector3.forward);



            _playerRigidbody.SetRotation(angle);
            _state.SetState(PlayerStates.States.InLandedShip);
            _state.SetPlanet(planet);

            planet.GetComponent <Planet>().LandOnPlanet(transform.parent.parent.gameObject);

            Player.transform.parent = planet.transform;
        }
    }
Exemple #4
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();
    }