public void SmartJump(Vector2 newPositionDifference)
 {
     positionDifference = newPositionDifference;
     isJumping = true;
     CalculateSmartJump();
     rigidbody2D.velocity = jumpVelocityStage1;
     yBeforeJump = transform.position.y;
     jumpStage = JumpStage.SmartJumpVertical;
 }
    public void DumbJump(Vector2 newPositionDifference)
    {
        oldPosition = transform.position;

        positionDifference = newPositionDifference;
        isJumping = true;
        CalculateDumbJump();
        rigidbody2D.velocity = jumpVelocityDumb;
        yBeforeJump = transform.position.y;
        jumpStage = JumpStage.DumbJumpRise;
    }
 private void turnControl()
 {
     lookVector.x = Mathf.Sin(Mathf.Deg2Rad * trans.rotation.eulerAngles.z);
     lookVector.y = Mathf.Cos(Mathf.Deg2Rad * trans.rotation.eulerAngles.z);
     angle        = Vector2.Angle(lookVector.normalized, direction);
     if (angle > 10)
     {
         onLeftSide = Vector3.Cross(lookVector, direction).z < 0;
         turnLeft   = onLeftSide;
         turnRight  = !onLeftSide;
     }
     else if (angle < 5)
     {
         turnLeft = turnRight = false;
         addMessage("Разогрев ускорителей", false);
         accelerate = true;
         stage      = JumpStage.WARMING_ENGINES;
     }
 }
 public void startJumpSequence(StarSystemType destination, Vector3 direction)
 {
     stage                       = JumpStage.SETTING_COURSE;
     this.destination            = destination;
     this.direction              = direction;
     this.direction.x           *= -1;
     UserInterface.showInterface = false;
     inControl                   = true;
     onCourse                    = false;
     playerController.inControl  = false;
     inJump                      = false;
     loadSystem                  = false;
     warmEngineCounter           = 100;
     jumpColor.a                 = 0;
     jumpBG.color                = jumpColor;
     jumpBG.gameObject.SetActive(true);
     ship.prepareWeaponsToJump();
     accelerate = decelerate = turnLeft = turnRight = false;
     addMessage("Выход на курс прыжка", false);
     setRotationForJump(true);
 }
    void Update()
    {
        if(Input.GetKey (KeyCode.Space) && !isJumping && debugMode)
        {
            SmartJump(positionDifference);
        }
        if(isJumping && jumpStage == JumpStage.DumbJumpRise && transform.position.y - yBeforeJump >= positionDifference.y - 0.1f)
        {
            jumpStage = JumpStage.DumbJumpFall;
        }

        if(isJumping && jumpStage == JumpStage.SmartJumpVertical && transform.position.y - yBeforeJump >= positionDifference.y)
        {
            jumpVelocityStage2 = new Vector2(jumpVelocityStage2.x, rigidbody2D.velocity.y);
            rigidbody2D.velocity = jumpVelocityStage2;
            jumpStage = JumpStage.SmartJumpHorizontal;
        }
        if(isJumping && (jumpStage == JumpStage.SmartJumpHorizontal || jumpStage == JumpStage.DumbJumpFall) && sensory.isGrounded)
        {
            rigidbody2D.velocity = Vector2.zero;
            jumpStage = JumpStage.NotJumping;
            isJumping = false;
        }

        if(isJumping && (jumpStage == JumpStage.DumbJumpFall || jumpStage == JumpStage.DumbJumpRise))
        {
            Debug.DrawLine(oldPosition, oldPosition + positionDifference, Color.magenta);
        }
    }
    override protected void Update()
    {
        if (inControl)
        {
            switch (stage)
            {
            case JumpStage.SETTING_COURSE: turnControl(); break;

            case JumpStage.WARMING_ENGINES:
                warmEngineCounter--;
                if (warmEngineCounter <= 0)
                {
                    setMainEngineForJump(true);
                    addMessage("Прыжок в систему " + destination.name(), false);
                    inJump = true;
                    stage  = JumpStage.FILL_WHITE;
                }
                break;

            case JumpStage.FILL_WHITE:
                jumpColor.a += 2;
                if (jumpColor.a >= 250)
                {
                    jumpColor.a  = 255;
                    stage        = JumpStage.lOAD_SYSTEM;
                    systemLoaded = false;
                    StarSystem.setGamePause(true);
                    Vars.starSystemType = destination;
                    starSystem.loadStarSystem();
                }
                jumpBG.color     = jumpColor;
                bgPos.x          = cameraTrans.position.x;
                bgPos.y          = cameraTrans.position.y;
                bgTrans.position = bgPos;
                break;

            case JumpStage.lOAD_SYSTEM:
                if (systemLoaded)
                {
                    addMessage("Прибытие в систему " + Vars.starSystemType.name(), true);
                    stage = JumpStage.ARRIVE_TO_SYSTEM;
                    ship.transform.position = Vector3.zero;
                    StarSystem.setGamePause(false);
                    setRotationForJump(false);
                    setMainEngineForJump(false);
                    UserInterface.showInterface = true;
                }
                break;

            case JumpStage.ARRIVE_TO_SYSTEM:
                jumpColor.a -= 2;
                if (jumpColor.a <= 10)
                {
                    inControl = false;
                    playerController.inControl = true;
                    jumpColor.a = 0;
                    stage       = JumpStage.DONE;
                    jumpBG.gameObject.SetActive(false);
                    cameraController.setDirectlyToShip();
                    accelerate = false;
                    inJump     = false;
                    ship.activateWeapons();
                }
                jumpBG.color     = jumpColor;
                bgPos.x          = cameraTrans.position.x;
                bgPos.y          = cameraTrans.position.y;
                bgTrans.position = bgPos;
                break;

            default: Debug.Log("Unknown stage: " + stage); break;
            }
            base.Update();
            if (Input.anyKeyDown && !inJump)
            {
                addMessage("Прыжок прерван командиром", true);
                setRotationForJump(false);
                setMainEngineForJump(false);
                inControl = false;
                UserInterface.showInterface = true;
                playerController.inControl  = true;
                ship.activateWeapons();
                playerController.checkInput();
            }
        }
    }